| ▲ | colechristensen 6 hours ago | |||||||
I think a key you may want is ε which scales with the actual local floating point increment. C++ implements this https://en.cppreference.com/cpp/numeric/math/nextafter Rust does not https://rust-lang.github.io/rfcs/3173-float-next-up-down.htm... but people have in various places. | ||||||||
| ▲ | tialaramex 5 hours ago | parent [-] | |||||||
Um, what? You've linked an RFC for Rust, but the CPP Reference article for C++ So yeah, the Rust RFC documents a proposed change, and the C++ reference documents an implemented feature, but you could equally link the C++ Proposal document and the Rust library docs to make the opposite point if you wanted. Rust's https://doc.rust-lang.org/std/primitive.f32.html#method.next... https://doc.rust-lang.org/std/primitive.f32.html#method.next... of course exist, they're even actually constant expressions (the C++ functions are constexpr since 2023 but of course you're not promised they actually work as constant expressions because C++ is a stupid language and "constexpr" means almost nothing) You can also rely on the fact (not promised in C++) that these are actually the IEEE floats and so they have all the resulting properties you can (entirely in safe Rust) just ask for the integers with the same bit pattern, compare integers and because of how IEEE is designed that tells you how far away in some proportional sense, the two values are. On an actual CPU manufactured this century that's almost free because the type system evaporates during compilation -- for example f32::to_bits is literally zero CPU instructions. | ||||||||
| ||||||||