Skip to content

Commit 5da9468

Browse files
stevengjSeelengrab
andauthored
use iszero in isinteger(::AbstractFloat) (#55276)
This is a very slight tweak to the implementation of `isinteger(::AbstractFloat)` to use `iszero` rather than `== 0`. It shouldn't make any difference with any of the built-in floating-point types, but `iszero` might conceivably be faster for some user-defined types. I also added a comment to indicate why it's using `iszero(x - trunc(x))` rather than `x == trunc(x)` (due to non-finite values); this code dates back to #14569 in Julia 0.5. --------- Co-authored-by: Sukera <[email protected]>
1 parent 079b69e commit 5da9468

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

base/floatfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ it is the minimum of `maxintfloat(T)` and [`typemax(S)`](@ref).
4242
maxintfloat(::Type{S}, ::Type{T}) where {S<:AbstractFloat, T<:Integer} = min(maxintfloat(S), S(typemax(T)))
4343
maxintfloat() = maxintfloat(Float64)
4444

45-
isinteger(x::AbstractFloat) = (x - trunc(x) == 0)
45+
isinteger(x::AbstractFloat) = iszero(x - trunc(x)) # note: x == trunc(x) would be incorrect for x=Inf
4646

4747
# See rounding.jl for docstring.
4848

0 commit comments

Comments
 (0)