diff --git a/.gitignore b/.gitignore index 942d35a..9bf08d5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ deps/installed_vers deps/libbid*.* deps/deps.jl deps/usr +deps/build.log diff --git a/src/DecFP.jl b/src/DecFP.jl index 78ca360..3db735d 100644 --- a/src/DecFP.jl +++ b/src/DecFP.jl @@ -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 @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index dfd6a60..712333e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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 @@ -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