-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Proposal: expose flags set by floating-point exceptions #2976
Comments
I'd really like the flags to be extendable, if possible, as MPFR also uses a range one (for impossible conversions, i.e. a NaN to int), and flags seem to be a good alternative to return the rounding of the last operation. I'm not sure though what's the best way to implement them, my first idea for MPFR was using a |
Also, I may be wrong (and I do hope so), but I think LLVM just ignores the floating point flags, so we would have to detect and trap them manually in |
This capability would seem to go well with the capability to set the floating-point rounding mode (to nearest, upward, downward, toward zero), which is very helpful for checking the stability of a numerical code (and is a key component of the IEEE 754 standard). A bonus is that it would distinguish Julia, for it is unavailable in most other high-level environments. |
@bkalpert yeah, that would be nice. I've added that as a todo item |
We will definitely do this – it's absolutely necessary for getting the Kahan stamp of approval (or even getting close). |
For setting the floating point environment, how feasible is it to ccall the various |
I think they wouldn't work on Windows and/or Visual C++, as fenv.h is POSIX/C99. |
Also, julia> ccall(:fegetround, Cint, ())
0
julia> ccall(:fesetround, Cint, (Cint, ), 1)
1
julia> ccall(:fegetround, Cint, ())
0 |
Ah, binary enum: julia> ccall((:fesetround, :libm), Cint, (Cint,), 1024)
0
julia> ccall((:fegetround, :libm), Cint, ())
1024 Seems good! |
Looks like excellent progress! |
Ability to change rounding mode for all floats (cf. #2976)
Bump. @jiahao, is the TODO list at the top still up to date? Anyone feel like tackling this? |
It is nearly finished in #6170, IIRC, just needs some final touches and a merge. |
There is currently no
Base
function that allows users to check for the flags set by floating-point operations.1 This does not allow the user to compute in a fully IEEE-compatible manner and could decrease code legibility should the user be forced to test implicitly for a raised flag by inspecting the consequences of the computation.This continues a discussion started in #2085, and extends the concept of overflow checking proposed for integers in #855.
Inf
-Inf
[ ] Honor the difference between quiet and signaling NaNscc: @andrioni @JeffBezanson
The text was updated successfully, but these errors were encountered: