5 ms·
I was going to comment that floats have nextUp operation which allows iterating them without needing to go through u32/from_bits, but apparently that feature is
by zokier 2y ago
I was going to comment that floats have nextUp operation which allows iterating them without needing to go through u32/from_bits, but apparently that feature is still behind feature gate in Rust
https://github.com/rust-lang/rust/issues/91399 https://github.com/rust-lang/rust/issues/91399
That is despite the fact that it is a IEEE-754 required operation! C and friends have equivalent available as nextafter https://en.cppreference.com/w/c/numeric/math/nextafter https://en.cppreference.com/w/c/numeric/math/nextafter
- lifthrasiir 2y agoI was more surprised that the proposed method does not include nextafter itself, which comes with its own distinct edge cases.
- vlovich123 2y agoReasoning explained here: https://github.com/rust-lang/rfcs/blob/master/text/3173-float-next-up-down.md https://github.com/rust-lang/rfcs/blob/master/text/3173-floa... TLDR: no one really uses it, the spec is ambiguous and deprecated, and those that do use it seem to be using it with constants that are usually infinities which is better suited and clearer with next_up/next_down, and those that don’t use infinities tend to assume the range of the value and pick a constant outside the range which can be dangerous if the range changes
- jcranmer 2y agoIEEE 754-1985 had a nextAfter function (which C implemented them as nextafter and nexttoward), but that was removed in IEEE 754-2008 in favor of nextUp and nextDown, which C implemented as nextup and nextdown, but only as of C23, which still hasn't officially been published by ISO. There's also another wrinkle: next* functions go from -subnormal to -0 to subnormal, and don't give you an iteration for both -0 and +0, which can be useful for some iteration purposes.
- tialaramex 2y agoI think even with these operations, it's more intuitive to a programmer to just try all the bit patterns using f32::from_bits on integers especially if they aren't already deeply familiar with how the IEEE representation works, which seems like a pre-requisite for this experiment.
- deleted 2y ago[deleted]
- lostmsu 2y agoIf you use f16 or f8, you could even reasonably plot the result.
- tialaramex 2y agoRust doesn't provide an f8 type, and it only provides f16 in nightly builds for now. I don't see additional value in "plotting the result" for f16 over f32. 65536 values is too many to understand it other than as a pattern, and the patterns is present in f32. Can you elaborate ?