Skip to content

Conversation

@stevengj
Copy link
Member

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.

@stevengj stevengj added the maths Mathematical functions label Jul 27, 2024
Copy link
Member

@giordano giordano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't make any difference with any of the built-in floating-point types

It may be marginally faster for BigFloat since it has a specialised iszero method not to run a ccall:

iszero(x::BigFloat) = x.exp == mpfr_special_exponent_zero

Bug regardless of the magnitude of the speedup for BigFloat, the change looks good to me.

Co-authored-by: Sukera <11753998+Seelengrab@users.noreply.github.com>
@jishnub jishnub merged commit 5da9468 into master Jul 29, 2024
@jishnub jishnub deleted the stevengj-patch-3 branch July 29, 2024 04:07
lazarusA pushed a commit to lazarusA/julia that referenced this pull request Aug 17, 2024
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 JuliaLang#14569 in Julia 0.5.

---------

Co-authored-by: Sukera <11753998+Seelengrab@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maths Mathematical functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants