Skip to content

Commit e918e51

Browse files
committed
Clarify method name
1 parent 00ee103 commit e918e51

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/FixedPointDecimals.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,19 @@ end
125125
Base.widemul(x::Integer, y::FD) = widemul(y, x)
126126

127127
"""
128-
_round_to_even(quotient, remainder, divisor, ::RoundingMode{M})
128+
_round_to_nearest(quotient, remainder, divisor, ::RoundingMode{M})
129129
130-
Round `quotient + remainder / divisor` to the nearest even integer,
130+
Round `quotient + remainder / divisor` to the nearest integer,
131131
given that `0 ≤ remainder < divisor` or `0 ≥ remainder >
132132
divisor`. (This assumption is satisfied by the return value of
133133
`fldmod` in all cases, and the return value of `divrem` in cases where
134134
`divisor` is known to be positive.) The tie is decided depending on
135135
the `RoundingMode`.
136136
"""
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}
138141
halfdivisor = divisor >> 1
139142
if iseven(divisor) && remainder == halfdivisor
140143
# `: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}
154157
quotient
155158
end
156159
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)
158161

159162
# In many of our calls to fldmod, `y` is a constant (the coefficient, 10^f). However, since
160163
# `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)
168171
function Base.:*(x::FD{T, f}, y::FD{T, f}) where {T, f}
169172
powt = coefficient(FD{T, f})
170173
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))
172175
end
173176

174177
# 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)
179182
function Base.:/(x::FD{T, f}, y::FD{T, f}) where {T, f}
180183
powt = coefficient(FD{T, f})
181184
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)))
183186
end
184187

185188
# 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}
188191
powt = coefficient(FD{T, f})
189192
powtsq = widemul(powt, powt)
190193
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)))
192195
end
193196

194197
function Base.:/(x::FD{T, f}, y::Integer) where {T, f}
195198
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)))
197200
end
198201

199202
# integerification
@@ -211,7 +214,7 @@ function Base.round(x::FD{T, f},
211214
RoundingMode{:NearestTiesAway}}=RoundNearest) where {T, f}
212215
powt = coefficient(FD{T, f})
213216
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))
215218
end
216219
function Base.ceil(x::FD{T, f}) where {T, f}
217220
powt = coefficient(FD{T, f})

0 commit comments

Comments
 (0)