@@ -109,11 +109,18 @@ Base.Rounding.rounding(::Type{T}) where {T<:DecimalFloatingPoint} =
109
109
Base. Rounding. setrounding (:: Type{T} , r:: RoundingMode ) where {T<: DecimalFloatingPoint } =
110
110
Base. Rounding. setrounding_raw (T, convert (DecFPRoundingMode, r))
111
111
112
+ primitive type Dec32 <: DecimalFloatingPoint 32 end
113
+ primitive type Dec64 <: DecimalFloatingPoint 64 end
114
+ Dec32 (x:: Number ) = convert (Dec32, x)
115
+ Dec64 (x:: Number ) = convert (Dec64, x)
116
+ struct Dec128 <: DecimalFloatingPoint
117
+ x:: UInt128
118
+ Dec128 (x:: Number ) = convert (Dec128, x)
119
+ Base. reinterpret (:: Type{Dec128} , x:: UInt128 ) = new (x)
120
+ end
112
121
for w in (32 ,64 ,128 )
113
122
BID = Symbol (string (" Dec" ,w))
114
123
Ti = Symbol (string (" UInt" ,w))
115
- @eval primitive type $ BID <: DecimalFloatingPoint $ w end
116
- $ BID (x:: Number ) = convert ($ BID, x)
117
124
118
125
@eval function $BID (x:: Real , mode:: RoundingMode )
119
126
setrounding ($ BID, mode) do
@@ -613,11 +620,15 @@ for w in (32,64,128)
613
620
end
614
621
end
615
622
616
- @eval Base. bswap (x:: $BID ) = reinterpret ($ BID, bswap (reinterpret ($ Ti, x)))
617
623
@eval Base. convert (:: Type{Float16} , x:: $BID ) = convert (Float16, convert (Float32, x))
618
624
@eval Base. Float16 (x:: $BID ) = convert (Float16, x)
619
625
end # widths w
620
626
627
+ Base. reinterpret (:: Type{UInt128} , x:: Dec128 ) = x. x
628
+ Base. bswap (x:: Dec32 ) = reinterpret (Dec32, bswap (reinterpret (UInt32, x)))
629
+ Base. bswap (x:: Dec64 ) = reinterpret (Dec64, bswap (reinterpret (UInt64, x)))
630
+ Base. bswap (x:: Dec128 ) = reinterpret (Dec128, bswap (x. x))
631
+
621
632
Base. round (x:: DecimalFloatingPoint , :: RoundingMode{:FromZero} ) = signbit (x) ? floor (x) : ceil (x)
622
633
623
634
for (f) in (:trunc , :floor , :ceil )
0 commit comments