Skip to content

Commit f486d6a

Browse files
jmkuhnstevengj
authored andcommitted
maxintfloat() (#55)
* maxintfloat() * review updates
1 parent 65adaad commit f486d6a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/DecFP.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ for T in (Dec32,Dec64,Dec128)
319319
end
320320
end
321321

322+
Base.maxintfloat(::Type{Dec32}) = reinterpret(Dec32, 0x36000001) # Dec32("1e7")
323+
Base.maxintfloat(::Type{Dec64}) = reinterpret(Dec64, 0x33c0000000000001) # Dec64("1e16")
324+
Base.maxintfloat(::Type{Dec128}) = reinterpret(Dec128, 0x30840000000000000000000000000001) # Dec128("1e34")
325+
322326
Base.convert(T::Type{F}, x::Union{Int8,UInt8,Int16,UInt16}) where {F<:DecimalFloatingPoint} = F(Int32(x))
323327
Base.convert(T::Type{F}, x::Integer) where {F<:DecimalFloatingPoint} = F(Int64(x))
324328
Base.convert(T::Type{F}, x::Unsigned) where {F<:DecimalFloatingPoint} = F(UInt64(x))

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ for T in (Dec32, Dec64, Dec128)
102102
@test nextfloat(T(1.5e10)) == 1.5e10 + eps(T(1.5e10))
103103
@test prevfloat(T(1.5e10)) == 1.5e10 - eps(T(1.5e10))
104104

105+
@test eps(maxintfloat(T) - 1) == 1
106+
@test eps(maxintfloat(T)) == 10
107+
@test maxintfloat(T) == maxintfloat(T)+1 > maxintfloat(T)-1 > maxintfloat(T)-2
108+
105109
for f in (isnan,isinf,isfinite,issubnormal,abs)
106110
@test f(xd) == f(x)
107111
end

0 commit comments

Comments
 (0)