The mantissa can be all zeroes, and the biased exponent can push the implicit 1 far enough down to end up with the value according to my understanding of floats, as it's just a single bit with a lot of zeroes before it in fixed-point.
Are you writing the precise 0.00000000023283064365386962890625? Then that is "excessive" because it still parses to the same f32 value when truncated as far as 0.00000000023283064.
Oh, I always thought excessive precision was when you have extra digits that are going to be rounded away, not when you wrote the correctly rounded number, but could use fewer digits by relying on rounding.
actually applying what that lint suggests would make my code very confusing so I'll just #[allow] it.
Thanks for the help.
You could use const { 4_294_967_296_f32.recip() } if your usecase doesn't require a literal?
Since this is a power of 2, your other alternative is to construct the constant using from_bits:
const TWO_POWER_MINUS_32: f32 = {
// bias for f32 is 127
const EXPONENT_NEG_32: u32 = 127 - 32;
const EXPONENT_SHIFT: u32 = f32::MANTISSA_DIGITS - 1;
f32::from_bits(EXPONENT_NEG_32 << (EXPONENT_SHIFT))
};
Depending on the context and the reader, this is either much clearer, or the greatest obfuscation technique you've yet seen for a floating-point constant.
why not just write:
const { 1.0 / (1u64 << 32) as f32 }
IMO that's way more obvious than any of the other magic-number filled suggestions above.
though if you really want obfuscation, you can always use:
f32::from_le_bytes(*b"\x00\x00\x80/")