Skip to content

Commit a03d754

Browse files
committed
Fix one other case of iseven allocating a BigInt
1 parent efee91b commit a03d754

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/FixedPointDecimals.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,16 @@ function _round_to_nearest(quotient::T,
191191
halfdivisor = divisor >> 1
192192
# PERF Note: Only need the last bit to check iseven, and default iseven(Int256)
193193
# allocates, so we truncate first.
194-
if iseven((divisor % Int8)) && remainder == halfdivisor
194+
_iseven(x) = (x & 0x1) == 0
195+
if _iseven(divisor) && remainder == halfdivisor
195196
# `:NearestTiesAway` will tie away from zero, e.g. -8.5 ->
196197
# -9. `:NearestTiesUp` will always ties towards positive
197198
# infinity. `:Nearest` will tie towards the nearest even
198199
# integer.
199200
if M == :NearestTiesAway
200201
ifelse(quotient < zero(quotient), quotient, quotient + one(quotient))
201202
elseif M == :Nearest
202-
ifelse(iseven(quotient), quotient, quotient + one(quotient))
203+
ifelse(_iseven(quotient), quotient, quotient + one(quotient))
203204
else
204205
quotient + one(quotient)
205206
end

0 commit comments

Comments
 (0)