@@ -125,16 +125,19 @@ end
125
125
Base. widemul (x:: Integer , y:: FD ) = widemul (y, x)
126
126
127
127
"""
128
- _round_to_even (quotient, remainder, divisor, ::RoundingMode{M})
128
+ _round_to_nearest (quotient, remainder, divisor, ::RoundingMode{M})
129
129
130
- Round `quotient + remainder / divisor` to the nearest even integer,
130
+ Round `quotient + remainder / divisor` to the nearest integer,
131
131
given that `0 ≤ remainder < divisor` or `0 ≥ remainder >
132
132
divisor`. (This assumption is satisfied by the return value of
133
133
`fldmod` in all cases, and the return value of `divrem` in cases where
134
134
`divisor` is known to be positive.) The tie is decided depending on
135
135
the `RoundingMode`.
136
136
"""
137
- function _round_to_even (quotient:: T , remainder:: T , divisor:: T , :: RoundingMode{M} = RoundNearest) where {T <: Integer , M}
137
+ function _round_to_nearest (quotient:: T ,
138
+ remainder:: T ,
139
+ divisor:: T ,
140
+ :: RoundingMode{M} = RoundNearest) where {T <: Integer , M}
138
141
halfdivisor = divisor >> 1
139
142
if iseven (divisor) && remainder == halfdivisor
140
143
# `:NearestTiesAway` will tie away from zero, e.g. -8.5 ->
@@ -154,7 +157,7 @@ function _round_to_even(quotient::T, remainder::T, divisor::T, ::RoundingMode{M}
154
157
quotient
155
158
end
156
159
end
157
- _round_to_even (q, r, d, m= RoundNearest) = _round_to_even (promote (q, r, d)... , m)
160
+ _round_to_nearest (q, r, d, m= RoundNearest) = _round_to_nearest (promote (q, r, d)... , m)
158
161
159
162
# In many of our calls to fldmod, `y` is a constant (the coefficient, 10^f). However, since
160
163
# `fldmod` is sometimes not being inlined, that constant information is not available to the
@@ -168,7 +171,7 @@ _round_to_even(q, r, d, m=RoundNearest) = _round_to_even(promote(q, r, d)..., m)
168
171
function Base.:* (x:: FD{T, f} , y:: FD{T, f} ) where {T, f}
169
172
powt = coefficient (FD{T, f})
170
173
quotient, remainder = fldmodinline (widemul (x. i, y. i), powt)
171
- reinterpret (FD{T, f}, _round_to_even (quotient, remainder, powt))
174
+ reinterpret (FD{T, f}, _round_to_nearest (quotient, remainder, powt))
172
175
end
173
176
174
177
# these functions are needed to avoid InexactError when converting from the
@@ -179,7 +182,7 @@ Base.:*(x::FD{T, f}, y::Integer) where {T, f} = reinterpret(FD{T, f}, T(x.i * y)
179
182
function Base.:/ (x:: FD{T, f} , y:: FD{T, f} ) where {T, f}
180
183
powt = coefficient (FD{T, f})
181
184
quotient, remainder = fldmod (widemul (x. i, powt), y. i)
182
- reinterpret (FD{T, f}, T (_round_to_even (quotient, remainder, y. i)))
185
+ reinterpret (FD{T, f}, T (_round_to_nearest (quotient, remainder, y. i)))
183
186
end
184
187
185
188
# These functions allow us to perform division with integers outside of the range of the
@@ -188,12 +191,12 @@ function Base.:/(x::Integer, y::FD{T, f}) where {T, f}
188
191
powt = coefficient (FD{T, f})
189
192
powtsq = widemul (powt, powt)
190
193
quotient, remainder = fldmod (widemul (x, powtsq), y. i)
191
- reinterpret (FD{T, f}, T (_round_to_even (quotient, remainder, y. i)))
194
+ reinterpret (FD{T, f}, T (_round_to_nearest (quotient, remainder, y. i)))
192
195
end
193
196
194
197
function Base.:/ (x:: FD{T, f} , y:: Integer ) where {T, f}
195
198
quotient, remainder = fldmod (x. i, y)
196
- reinterpret (FD{T, f}, T (_round_to_even (quotient, remainder, y)))
199
+ reinterpret (FD{T, f}, T (_round_to_nearest (quotient, remainder, y)))
197
200
end
198
201
199
202
# integerification
@@ -211,7 +214,7 @@ function Base.round(x::FD{T, f},
211
214
RoundingMode{:NearestTiesAway }}= RoundNearest) where {T, f}
212
215
powt = coefficient (FD{T, f})
213
216
quotient, remainder = fldmodinline (x. i, powt)
214
- FD {T, f} (_round_to_even (quotient, remainder, powt, m))
217
+ FD {T, f} (_round_to_nearest (quotient, remainder, powt, m))
215
218
end
216
219
function Base. ceil (x:: FD{T, f} ) where {T, f}
217
220
powt = coefficient (FD{T, f})
0 commit comments