Skip to content

Commit

Permalink
Merge pull request #52 from stevengj/jq/0.7
Browse files Browse the repository at this point in the history
Compat for 0.7
  • Loading branch information
quinnj authored Jan 10, 2018
2 parents 2550bca + 167ee79 commit ea95d2d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/DecFP.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__precompile__(true)
module DecFP

using Compat
Expand Down Expand Up @@ -52,6 +53,7 @@ for w in (32,64,128)
$BID(x) = convert($BID, x)
Base.reinterpret(::Type{$BID}, x::$Ti) = new(x)
end
@eval $BID(x::Rational{T}) where {T} = convert($BID, x)
end

# quickly check whether s begins with "±nan"
Expand Down Expand Up @@ -118,7 +120,7 @@ for w in (32,64,128)
DIGITS[1] = UInt8('0')
return Int32(1), Int32(1), signbit(x)
end
ccall(($(bidsym(w,"to_string")), libbid), Void, (Ptr{UInt8}, $BID), _buffer, rounded)
ccall(($(bidsym(w,"to_string")), libbid), Cvoid, (Ptr{UInt8}, $BID), _buffer, rounded)
trailing_zeros = 0
i = 2
while _buffer[i] != UInt8('E')
Expand Down Expand Up @@ -164,7 +166,7 @@ for w in (32,64,128)
# rounded = round(x * exp10($BID(n - 1 - normalized_exponent)), RoundNearestTiesAway)
rounded = xchk(ccall(($(bidsym(w,"round_integral_nearest_away")), libbid), $BID, ($BID,), x * exp10($BID(n - 1 - normalized_exponent))), InexactError, :round, $BID, x, mask=INVALID | OVERFLOW)
rounded_exponent = nox(ccall(($(bidsym(w,"ilogb")), libbid), Cint, ($BID,), rounded))
ccall(($(bidsym(w,"to_string")), libbid), Void, (Ptr{UInt8}, $BID), _buffer, rounded)
ccall(($(bidsym(w,"to_string")), libbid), Cvoid, (Ptr{UInt8}, $BID), _buffer, rounded)
i = 2
while _buffer[i] != UInt8('E')
DIGITS[i - 1] = _buffer[i]
Expand Down Expand Up @@ -217,6 +219,7 @@ for w in (32,64,128)
bT = string("binary",sizeof(Tf)*8)
@eval begin
Base.convert(::Type{$Tf}, x::$BID) = nox(ccall(($(bidsym(w,"to_",bT)), libbid), $Tf, ($BID,), x))
Base.$(Symbol("$Tf"))(x::$BID) = convert($Tf, x)
Base.convert(::Type{$BID}, x::$Tf) = nox(ccall(($(string("__",bT,"_to_","bid",w)), libbid), $BID, ($Tf,), x))
end
end
Expand Down Expand Up @@ -264,12 +267,14 @@ for w in (32,64,128)
Base.round(::Type{$Ti′}, x::$BID) = xchk(ccall(($(bidsym(w,"to_",i′str,"_xrnint")), libbid), $Ti′, ($BID,), x), InexactError, :round, $BID, x, mask=INVALID | OVERFLOW)
Base.round(::Type{$Ti′}, x::$BID, ::RoundingMode{:NearestTiesAway}) = xchk(ccall(($(bidsym(w,"to_",i′str,"_xrninta")), libbid), $Ti′, ($BID,), x), InexactError, :round, $BID, x, mask=INVALID | OVERFLOW)
Base.convert(::Type{$Ti′}, x::$BID) = xchk(ccall(($(bidsym(w,"to_",i′str,"_xfloor")), libbid), $Ti′, ($BID,), x), InexactError, :convert, $BID, x)
Base.$(Symbol("$Ti′"))(x::$BID) = convert($Ti′, x)
end
end
end

@eval Base.bswap(x::$BID) = reinterpret($BID, bswap(x.x))
@eval Base.convert(::Type{Float16}, x::$BID) = convert(Float16, convert(Float32, x))
@eval Base.Float16(x::$BID) = convert(Float16, x)
@eval Base.reinterpret(::Type{$Ti}, x::$BID) = x.x
end # widths w

Expand Down

0 comments on commit ea95d2d

Please sign in to comment.