@@ -184,6 +184,8 @@ for w in (32,64,128)
184184 Base. trunc (:: Type{$Ti′} , x:: $BID ) = xchk (ccall (($ (bidsym (w," to_" ,lowercase (i′)," _xint" )), libbid), $ Ti′, ($ BID,), x), InexactError, INVALID | OVERFLOW)
185185 Base. floor (:: Type{$Ti′} , x:: $BID ) = xchk (ccall (($ (bidsym (w," to_" ,lowercase (i′)," _xfloor" )), libbid), $ Ti′, ($ BID,), x), InexactError, INVALID | OVERFLOW)
186186 Base. ceil (:: Type{$Ti′} , x:: $BID ) = xchk (ccall (($ (bidsym (w," to_" ,lowercase (i′)," _xceil" )), libbid), $ Ti′, ($ BID,), x), InexactError, INVALID | OVERFLOW)
187+ Base. round (:: Type{$Ti′} , x:: $BID ) = xchk (ccall (($ (bidsym (w," to_" ,lowercase (i′)," _xrnint" )), libbid), $ Ti′, ($ BID,), x), InexactError, INVALID | OVERFLOW)
188+ Base. round (:: Type{$Ti′} , x:: $BID , :: RoundingMode{:NearestTiesAway} ) = xchk (ccall (($ (bidsym (w," to_" ,lowercase (i′)," _xrninta" )), libbid), $ Ti′, ($ BID,), x), InexactError, INVALID | OVERFLOW)
187189 Base. convert (:: Type{$Ti′} , x:: $BID ) = xchk (ccall (($ (bidsym (w," to_" ,lowercase (i′)," _xfloor" )), libbid), $ Ti′, ($ BID,), x), InexactError)
188190 end
189191 end
@@ -197,8 +199,20 @@ end # widths w
197199Base. trunc (:: Type{Integer} , x:: DecimalFloatingPoint ) = trunc (Int, x)
198200Base. floor (:: Type{Integer} , x:: DecimalFloatingPoint ) = floor (Int, x)
199201Base. ceil (:: Type{Integer} , x:: DecimalFloatingPoint ) = ceil (Int, x)
202+ Base. round (:: Type{Integer} , x:: DecimalFloatingPoint ) = round (Int, x)
203+ Base. round (:: Type{Integer} , x:: DecimalFloatingPoint , :: RoundingMode{:NearestTiesAway} ) = round (Int, x, RoundNearestTiesAway)
200204Base. convert (:: Type{Integer} , x:: DecimalFloatingPoint ) = convert (Int, x)
201205
206+ Base. round {T<:Integer} (:: Type{T} , x:: DecimalFloatingPoint , :: RoundingMode{:Nearest} ) = round (T, x)
207+ function Base. round {T<:Integer} (:: Type{T} , x:: DecimalFloatingPoint , :: RoundingMode{:NearestTiesUp} )
208+ y = floor (T, x)
209+ ifelse (x== y, y, copysign (floor (T, 2 * x- y), x))
210+ end
211+ Base. round {T<:Integer} (:: Type{T} , x:: DecimalFloatingPoint , :: RoundingMode{:ToZero} ) = trunc (T, x)
212+ Base. round {T<:Integer} (:: Type{T} , x:: DecimalFloatingPoint , :: RoundingMode{:FromZero} ) = (x>= 0 ? ceil (T, x) : floor (T, x))
213+ Base. round {T<:Integer} (:: Type{T} , x:: DecimalFloatingPoint , :: RoundingMode{:Up} ) = ceil (T, x)
214+ Base. round {T<:Integer} (:: Type{T} , x:: DecimalFloatingPoint , :: RoundingMode{:Down} ) = floor (T, x)
215+
202216# the complex-sqrt function in base doesn't work for use, because it requires base-2 ldexp
203217function Base. sqrt {T<:DecimalFloatingPoint} (z:: Complex{T} )
204218 x, y = reim (z)
0 commit comments