Skip to content

Commit 1aac6c6

Browse files
jmkuhnstevengj
authored andcommitted
Use primitive type
1 parent a677c85 commit 1aac6c6

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/DecFP.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,8 @@ Base.Rounding.setrounding(::Type{T}, r::RoundingMode) where {T<:DecimalFloatingP
112112
for w in (32,64,128)
113113
BID = Symbol(string("Dec",w))
114114
Ti = Symbol(string("UInt",w))
115-
@eval struct $BID <: DecimalFloatingPoint
116-
x::$Ti
117-
$BID(x::Number) = convert($BID, x)
118-
Base.reinterpret(::Type{$BID}, x::$Ti) = new(x)
119-
end
115+
@eval primitive type $BID <: DecimalFloatingPoint $w end
116+
$BID(x::Number) = convert($BID, x)
120117

121118
@eval function $BID(x::Real, mode::RoundingMode)
122119
setrounding($BID, mode) do
@@ -494,7 +491,7 @@ for w in (32,64,128)
494491
Base.one(::Union{Type{$BID},$BID}) = $(_parse(T, "1"))
495492
Base.zero(::Union{Type{$BID},$BID}) = $(_parse(T, "0"))
496493

497-
Base.signbit(x::$BID) = $(zero(Ti)) != $(Ti(1) << (Ti(w - 1))) & x.x
494+
Base.signbit(x::$BID) = $(zero(Ti)) != $(Ti(1) << (Ti(w - 1))) & reinterpret($Ti, x)
498495
Base.sign(x::$BID) = ifelse(isnan(x) || iszero(x), x, ifelse(signbit(x), $(_parse(T, "-1")), $(_parse(T, "1"))))
499496

500497
Base.nextfloat(x::$BID) = nox(_nextfloat(x))
@@ -616,10 +613,9 @@ for w in (32,64,128)
616613
end
617614
end
618615

619-
@eval Base.bswap(x::$BID) = reinterpret($BID, bswap(x.x))
616+
@eval Base.bswap(x::$BID) = reinterpret($BID, bswap(reinterpret($Ti, x)))
620617
@eval Base.convert(::Type{Float16}, x::$BID) = convert(Float16, convert(Float32, x))
621618
@eval Base.Float16(x::$BID) = convert(Float16, x)
622-
@eval Base.reinterpret(::Type{$Ti}, x::$BID) = x.x
623619
end # widths w
624620

625621
Base.round(x::DecimalFloatingPoint, ::RoundingMode{:FromZero}) = signbit(x) ? floor(x) : ceil(x)

0 commit comments

Comments
 (0)