The question is how to enable all this in Rust... Right now there's no simple way to just tell Rust to be fast & loose with floats.
I don't know if most Rust programmers would be happy with any fast and loose features making it into the official Rust compiler. Besides, algorithms that benefit from -ffast-math can be implemented in C and with Rust bindings automatically generated. This solution isn't exactly "simple", but it could help projects keep track of the expectations of correctness between different algorithm implementations.
Optimizations Enabled by -ffast-Math
51–60 of 117 posts
Re: Optimizations Enabled by -ffast-Math
#52Re: Optimizations Enabled by -ffast-Math
#53Earlier quoted context omitted.
> Generally if you're seeing a NaN/Inf something has gone wrong That’s a bold claim.
Can you think of a function where the input is valid, the output is NaN and nothing has gone wrong in the process? I can't think of any, haven't experienced any, not heard of any examples of it, so you're welcome to break my ignorance on the subject.
±Inf is a very natural output for many kinds of numerical codes.
Re: Optimizations Enabled by -ffast-Math
#54Earlier quoted context omitted.
Generally if you're seeing a NaN/Inf something has gone wrong, It's very difficult to gracefully recover from and if you tried I think you would lose both sanity and performance! Regarding performance, the cost of a real division is about 3-4 orders worse performance than an if statement that is very consistent, but the usual way is to have fast/safe versions of functions, where you need performance and can deduce if…
> Generally if you're seeing a NaN/Inf something has gone wrong That’s a bold claim.
Re: Optimizations Enabled by -ffast-Math
#55Re: Optimizations Enabled by -ffast-Math
#56I found the following note for -ffinite-math-only and -fno-signed-zeros quite worrying: The program may behave in strange ways (such as not evaluating either the true or false part of an if-statement) if calculations produce Inf, NaN, or -0.0 when these flags are used. I always thought that -ffast-math was telling the compiler. "I do not care about floating point standards compliance, and I do not rely on it. So opti…
> A promise that you will not produce Inf, NaN, or -0.0. Whilst especially Inf and NaN can be hard to exclude. Cumbersome but not that difficult: Range-check all input values.
Re: Optimizations Enabled by -ffast-Math
#57Earlier quoted context omitted.
> Generally if you're seeing a NaN/Inf something has gone wrong That’s a bold claim.
Can you think of a function where the input is valid, the output is NaN and nothing has gone wrong in the process? I can't think of any, haven't experienced any, not heard of any examples of it, so you're welcome to break my ignorance on the subject.
I'd suspect the same is true for NaN. These things were introduced for reasons. If you don't have a deep knowledge of why, don't assume everyone else is the same.
Edit: I found examples using a NaN and Inf intermediates to get a large speed increase [1,2].
Re: Optimizations Enabled by -ffast-Math
#58Earlier quoted context omitted.
Also maybe you woild like to have more granular control over which parts of your program has the priority on speed and which part favours accuracy. Maybe this could be done with a seperate type (e.g. ff64) or a decorator (which would be useful if you want to enable this for someone elses library).
Maybe... or maybe there would be just a flag to enable all this and be fine with consequences.
Re: Optimizations Enabled by -ffast-Math
#59Earlier quoted context omitted.
Can you think of a function where the input is valid, the output is NaN and nothing has gone wrong in the process? I can't think of any, haven't experienced any, not heard of any examples of it, so you're welcome to break my ignorance on the subject.
Do you count under/overflow resulting in Inf as 'something has gone wrong'? If so, why would gracefully recovering be hard?
I think NaN and inf can be really useful in specific cases, but they probably shouldn't be allowed to propagate through your program, and shouldn't occur unless you're specifically making use of them.