Skip to content

Commit

Permalink
Merge pull request #77 from JuliaMath/jq/1.0
Browse files Browse the repository at this point in the history
Fixes for 1.0
  • Loading branch information
quinnj authored Aug 7, 2018
2 parents f7d7921 + 7ea28e4 commit 988acd6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ deps/installed_vers
deps/libbid*.*
deps/deps.jl
deps/usr
deps/build.log
9 changes: 7 additions & 2 deletions src/DecFP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ for w in (32,64,128)
for c in (, :e, :ℯ, , :catalan, )
@eval begin
Base.convert(::Type{$BID}, ::Irrational{$(QuoteNode(c))}) = $(_parse(T, setprecision(256) do
string(BigFloat(isdefined(Base, :MathConstants) ? Core.eval(Base.MathConstants, c) : eval(c)))
string(BigFloat(getfield(Compat.MathConstants, c)))
end))
end
end
Expand Down Expand Up @@ -502,13 +502,18 @@ end
const pinf128 = _parse(Dec128, "+Inf")
const minf128 = _parse(Dec128, "-Inf")

for T in (Dec32,Dec64,Dec128)
for T in (Dec32, Dec64, Dec128)
@eval begin
Base.eps(::Type{$T}) = $(_sub(_nextfloat(one(T)), one(T)))
Base.typemax(::Type{$T}) = $(_parse(T, "+inf"))
Base.typemin(::Type{$T}) = $(_parse(T, "-inf"))
@static if isdefined(Base, :floatmax)
Base.floatmax(::Type{$T}) = $(_prevfloat(_parse(T, "+inf")))
Base.floatmin(::Type{$T}) = $(_nextfloat(zero(T)))
else
Base.realmax(::Type{$T}) = $(_prevfloat(_parse(T, "+inf")))
Base.realmin(::Type{$T}) = $(_nextfloat(zero(T)))
end
end
end

Expand Down
23 changes: 14 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ if VERSION >= v"0.7.0-alpha.69"
using SpecialFunctions
end

if !isdefined(Base, :floatmax)
floatmax(x) = realmax(x)
floatmin(x) = realmin(x)
end


@test unsafe_load(DecFP.flags[]) == 0

Expand All @@ -20,21 +25,21 @@ for T in (Dec32, Dec64, Dec128)
if T == Dec32
@test d32"3.2" * d32"4.5" == d32"14.4"
@test eps(Dec32) == parse(Dec32, "1e-6")
@test realmax(Dec32) == parse(Dec32, "+9999999E+90")
@test realmin(Dec32) == parse(Dec32, "+1E-101")
@test floatmax(Dec32) == parse(Dec32, "+9999999E+90")
@test floatmin(Dec32) == parse(Dec32, "+1E-101")
@test bswap(Dec32(1.5)) == reinterpret(Dec32, bswap(reinterpret(UInt32, Dec32(1.5))))
elseif T == Dec64
@test d"3.2" * d"4.5" == d"14.4"
@test d64"3.2" * d64"4.5" == d64"14.4"
@test eps(Dec64) == parse(Dec64, "1e-15")
@test realmax(Dec64) == parse(Dec64, "+9999999999999999E+369")
@test realmin(Dec64) == parse(Dec64, "+1E-398")
@test floatmax(Dec64) == parse(Dec64, "+9999999999999999E+369")
@test floatmin(Dec64) == parse(Dec64, "+1E-398")
@test bswap(Dec64(1.5)) == reinterpret(Dec64, bswap(reinterpret(UInt64, Dec64(1.5))))
else
@test d128"3.2" * d128"4.5" == d128"14.4"
@test eps(Dec128) == parse(Dec128, "1e-33")
@test realmax(Dec128) == parse(Dec128, "+9999999999999999999999999999999999E+6111")
@test realmin(Dec128) == parse(Dec128, "+1E-6176")
@test floatmax(Dec128) == parse(Dec128, "+9999999999999999999999999999999999E+6111")
@test floatmin(Dec128) == parse(Dec128, "+1E-6176")
@test bswap(Dec128(1.5)) == reinterpret(Dec128, bswap(reinterpret(UInt128, Dec128(1.5))))
end

Expand Down Expand Up @@ -172,9 +177,9 @@ for T in (Dec32, Dec64, Dec128)
@test round(Ti, T(2.5), RoundNearestTiesAway) === round(Ti, T(3.3), RoundNearestTiesAway) === Ti(3)
@test round(Ti, T(2.5), RoundNearestTiesUp) === round(Ti, T(3.3), RoundNearestTiesUp) === Ti(3)
@test_throws InexactError convert(Ti, xd)
@test_throws InexactError trunc(Ti, realmax(T))
@test_throws InexactError floor(Ti, realmax(T))
@test_throws InexactError ceil(Ti, realmax(T))
@test_throws InexactError trunc(Ti, floatmax(T))
@test_throws InexactError floor(Ti, floatmax(T))
@test_throws InexactError ceil(Ti, floatmax(T))
if Ti <: Signed
@test parse(T, "-17") == T(Ti(-17)) == Ti(-17) == Ti(T(-17))
end
Expand Down

0 comments on commit 988acd6

Please sign in to comment.