Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.math: allow comptime_floats in isInf and isNan #23357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rootbeer
Copy link
Contributor

Currently constants passed to std.math.isInf and std.math.isNan trigger an obtuse (to me): error: access of union field 'float' while field 'comptime_float' is active. The work-around is to cast the constant into a runtime float.

From #21205, I'm leveraging the idea that comptime_float won't (eventually) support NaN or infinity, so the isNan and isInf methods can unilaterally return false given any comptime_float parameters.

Perhaps short-circuiting at this layer is the wrong approach (or I'm mis-interpreting that proposal), and a more appropriate fix would be at a lower layer?

Also add tests for comptime floats passed to isNan, isInf*.

See #23258 for the motivation.

Fixes #22107

Currently constants passed to these functions trigger an obtuse:
`error: access of union field 'float' while field 'comptime_float' is active`
where the work-around is to cast the constant into a runtime float.

From ziglang#21205, I'm leveraging the fact
that `comptime_float` won't (eventually) support NaN or infinity, so the
`isNan` and `isInf` methods can unilaterally return false for
`comptime_float` parameters.

Add tests for comptime floats passed to isNan, isInf*.

See ziglang#23258 for the motivation.

Fixes ziglang#22107
@rootbeer rootbeer force-pushed the 22107-comptime-isinf branch from aa67b9f to f3f4848 Compare March 27, 2025 03:33
@rootbeer rootbeer marked this pull request as ready for review March 27, 2025 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std.math.isInf either should support ComptimeFloat or should have a clearer error message
1 participant