Construct a NormalizedInt from an integer representation.
Construct a NormalizedInt from a floating point representation. The value is clamped to the range [min.
Integral storage type.
Binary operators.
Binary operators.
Binary operators.
Binary operators.
Binary operators.
Binary operators.
Binary operators.
Binary operators.
Floating point cast operator.
Cast between NormalizedInt types.
Comparison operators.
Comparison operators.
Comparison operators.
Equality operators.
Integral equality operator.
If rh is outside of the integral range, rh will not be clamped and comparison will return false.
Floating point equality operator.
If rh is outside of the nominal range, rh will not be clamped and comparison will return false.
Binary assignment operators.
Unary operators.
Maximum floating point value.
Minimum floating point value.
Maximum integral value.
Minimum integral value.
The actual value
auto x = NormalizedInt!ubyte(200); auto y = NormalizedInt!ubyte(50); auto z = x + y; assert(z == 250); // add as expected z += y; assert(z == 255); // overflow saturates assert(cast(float)z == 1.0); // maximum value is floating point 1.0 z -= x; assert(z == 55); // subtract as expected z -= x; assert(z == 0); // underflow saturates z = y * 2; assert(z == 100); // multiply by integer z = x * 0.5; assert(z == 100); // multiply by float z *= 3; assert(z == 255); // multiply overflow saturates z *= y; assert(z == 50); // multiply is performed in normalized space z *= y; assert(z == 9); // multiplication rounds *down* z /= 2; assert(z == 4); // division works as expected, rounds down z /= y; assert(z == 20); // division is performed in normalized space z /= y * y; assert(z == 255); // division overflow saturates z = -z; assert(z == 0); // unsigned negation saturates at zero auto u = NormalizedInt!short(-1.0); auto v = NormalizedInt!short(0.5); auto w = cast(NormalizedInt!short)x; assert(w == 25700); // casting to higher precision extends bit-pattern to preserve uniformity w = -w; assert(w == -25700); // negation works as expected w *= 2; assert(w == -32767 && w == -1.0); // overflow saturates w *= -0.5; assert(w == 16384 && w > 0.5); // 0.5 is not exactly representable (odd number of positive integers) w = w^^0.0; assert(w == 1.0); // pow as expected // check floating poing comparisons static assert(NormalizedInt!ubyte(0xFF) == 1.0); static assert(NormalizedInt!ubyte(0x00) == 0.0); static assert(NormalizedInt!ubyte(0x80) > 0.5); static assert(NormalizedInt!ubyte(0x7F) < 0.5); static assert(NormalizedInt!byte(127) == 1.0); static assert(NormalizedInt!byte(-127) == -1.0); static assert(NormalizedInt!byte(-128) == -1.0); static assert(NormalizedInt!byte(0x00) == 0.0); static assert(NormalizedInt!byte(0x40) > 0.5); static assert(NormalizedInt!byte(0x3F) < 0.5);
Normalized integers express a fractional range of values within an integer data type.
Unsigned integers map the values [0 to the fractional values [0.0 in equal increments.
Signed integers represent the values [-I.max to fractional values [-1.0 in equal increments. I.min is outside the nominal integer range and is clamped to represent -1.0.