4 ms·
An alternative could be to create another zero-sized type for NaN and Infinity
by frazar0 6y ago
An alternative could be to create another zero-sized type for NaN and Infinity
- fanf2 6y agoYeah I have been thinking about something like that, but we don’t know at compile time when NaN will turn up. (I suppose if you take abstract interpretation as far as you can, you get to partial evaluation, but I am not in that game!) Another idea is to rely on Rust-specific optimizations: make the concrete type used by the result expressions into enum ZeroNum { Zero, Num(f64), } Operator overloading on this type works like it does on the separate Zero and Num types, but the cases are tested at run time instead of compile time. But this type is only used in a small context where the optimizer should be able to eliminate the checks in the same way I naively thought it would do for ops with 0.0.