Skip to content

Commit ea95d2d

Browse files
authored
Merge pull request #52 from stevengj/jq/0.7
Compat for 0.7
2 parents 2550bca + 167ee79 commit ea95d2d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/DecFP.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
__precompile__(true)
12
module DecFP
23

34
using Compat
@@ -52,6 +53,7 @@ for w in (32,64,128)
5253
$BID(x) = convert($BID, x)
5354
Base.reinterpret(::Type{$BID}, x::$Ti) = new(x)
5455
end
56+
@eval $BID(x::Rational{T}) where {T} = convert($BID, x)
5557
end
5658

5759
# quickly check whether s begins with "±nan"
@@ -118,7 +120,7 @@ for w in (32,64,128)
118120
DIGITS[1] = UInt8('0')
119121
return Int32(1), Int32(1), signbit(x)
120122
end
121-
ccall(($(bidsym(w,"to_string")), libbid), Void, (Ptr{UInt8}, $BID), _buffer, rounded)
123+
ccall(($(bidsym(w,"to_string")), libbid), Cvoid, (Ptr{UInt8}, $BID), _buffer, rounded)
122124
trailing_zeros = 0
123125
i = 2
124126
while _buffer[i] != UInt8('E')
@@ -164,7 +166,7 @@ for w in (32,64,128)
164166
# rounded = round(x * exp10($BID(n - 1 - normalized_exponent)), RoundNearestTiesAway)
165167
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)
166168
rounded_exponent = nox(ccall(($(bidsym(w,"ilogb")), libbid), Cint, ($BID,), rounded))
167-
ccall(($(bidsym(w,"to_string")), libbid), Void, (Ptr{UInt8}, $BID), _buffer, rounded)
169+
ccall(($(bidsym(w,"to_string")), libbid), Cvoid, (Ptr{UInt8}, $BID), _buffer, rounded)
168170
i = 2
169171
while _buffer[i] != UInt8('E')
170172
DIGITS[i - 1] = _buffer[i]
@@ -217,6 +219,7 @@ for w in (32,64,128)
217219
bT = string("binary",sizeof(Tf)*8)
218220
@eval begin
219221
Base.convert(::Type{$Tf}, x::$BID) = nox(ccall(($(bidsym(w,"to_",bT)), libbid), $Tf, ($BID,), x))
222+
Base.$(Symbol("$Tf"))(x::$BID) = convert($Tf, x)
220223
Base.convert(::Type{$BID}, x::$Tf) = nox(ccall(($(string("__",bT,"_to_","bid",w)), libbid), $BID, ($Tf,), x))
221224
end
222225
end
@@ -264,12 +267,14 @@ for w in (32,64,128)
264267
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)
265268
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)
266269
Base.convert(::Type{$Ti′}, x::$BID) = xchk(ccall(($(bidsym(w,"to_",i′str,"_xfloor")), libbid), $Ti′, ($BID,), x), InexactError, :convert, $BID, x)
270+
Base.$(Symbol("$Ti′"))(x::$BID) = convert($Ti′, x)
267271
end
268272
end
269273
end
270274

271275
@eval Base.bswap(x::$BID) = reinterpret($BID, bswap(x.x))
272276
@eval Base.convert(::Type{Float16}, x::$BID) = convert(Float16, convert(Float32, x))
277+
@eval Base.Float16(x::$BID) = convert(Float16, x)
273278
@eval Base.reinterpret(::Type{$Ti}, x::$BID) = x.x
274279
end # widths w
275280

0 commit comments

Comments
 (0)