Expand description
Fixed-precision mathematics.
Structs§
- Fixed
I32 - Fixed precision
i32
- upper 16 bits is value, lower 16 bits are the fractional portion of the value. Each fractional portion is 1/u16::MAX
~=1.5259e-5
or0.000_015_259
, or about15.3 micro
, and can accurately represent SI-prefixes:milli/1e-3
. The whole portion can representi16::MIN
(-32768
) ->i16::MAX
(32_727
) - Fixed
I64 - Fixed precision
i64
- upper 32 bits is value, lower 32 bits are the fractional portion of the value. Each fractional portion is 1/u32::MAX
~=2.328306e-10
or0.000_000_000_238_306
, or about238.3 pico
, and can accurately represent SI-prefixesmilli/1e-3
,micro/1e-6
, andnano/1e-9
. The whole portion can representi32::MIN
(-2_147_483_648
) ->i32::MAX
(2_147_483_647
) - Fixed
I128 - Fixed precision
u128
- upper 64 bits is value, lower 64 bits are the fractional portion of the value. Each fractional portion is 1/i64::MAX
~=5.4210e-20
or0.000_000_000_000_000_000_054_210
, or about54.2 zepto
, and can accurately represent SI-prefixesmilli/1e-3
,micro/1e-6
,nano/1e-9
,pico/1e-12
,femto/1e-15
, andatto/1e-18
. This is probably overkill for what you need. The whole portion can representi64::MIN
(-9_223_372_036_854_775_808
) ->i64::MAX
(9_223_372_036_854_775_807
) - Fixed
U32 - Fixed precision
u32
- upper 16 bits is value, lower 16 bits are the fractional portion of the value. Each fractional portion is 1/u16::MAX
~=1.5259e-5
or0.000_015_259
, or about15.3 micro
, and can accurately represent SI-prefixes:milli/1e-3
. The whole portion can represent0
->u16::MAX
(65_535
) - Fixed
U64 - Fixed precision
u64
- upper 32 bits is value, lower 32 bits are the fractional portion of the value. Each fractional portion is 1/u32::MAX
~=2.328306e-10
or0.000_000_000_238_306
, or about238.3 pico
, and can accurately represent SI-prefixesmilli/1e-3
,micro/1e-6
, andnano/1e-9
. The whole portion can represent0
->u32::MAX
(4_294_967_295
) - Fixed
U128 - Fixed precision
u128
- upper 64 bits is value, lower 64 bits are the fractional portion of the value. Each fractional portion is 1/u64::MAX
~=5.4210e-20
or0.000_000_000_000_000_000_054_210
, or about54.2 zepto
, and can accurately represent SI-prefixesmilli/1e-3
,micro/1e-6
,nano/1e-9
,pico/1e-12
,femto/1e-15
, andatto/1e-18
. This is probably overkill for what you need. The whole portion can represent0
->u64::MAX
(1.84467E+19
)