News for hackers. Stuff that matters.
Re:FOSDEM 2025: The state of Rust trying to catch up with Ad... by edflsafoiewq on Monday February 10, 2025 @11:22AM (#43002020)
They're sort of used in graphics APIs. When a value in [-1.0, 1.0] is quantized to an i8, the result is a BalancedI8: -1.0 maps to -127, 1.0 to 127, and -128 is unused; if -128 is used in the dequantizer, it is treated the same as -127. This replaced the old scheme where -1.0 mapped to -128 in which 0.0 was unrepresentable.

The value of encoding this case in the type system seems minimal to me though.

Re:FOSDEM 2025: The state of Rust trying to catch up with Ad... by ziml77 on Monday February 10, 2025 @06:47PM (#43006836)
The reason to encode it in the type system is it allows for optimization. Option<NonZeroI8> uses a single byte because it knows 0 is available to represent the None state. Option<BalancedI8> could do the same thing with -128 representing None.