lib-misc-utils · crate
num-traits
Kinogaki's own numeric traits, published under the crates.io name num-traits so the frozen naga and our half resolve to it through [patch.crates-io].
- Repository
- lib-misc-utils (kinogaki/lib-misc-utils)
- Folder
libs/lib-misc-utils/crates/num-traits- Source
- 9 files, 1,179 lines
- Tests
- 1 file, 86 lines
What it is
Kinogaki's own numeric traits, published under the crates.io name num-traits so the frozen naga and our half resolve to it through [patch.crates-io]. It is not upstream num-traits: it holds only the traits and methods those two crates call, implemented for the primitive types with std's float functions.
The conversions follow num-traits' documented rules, which naga's constant evaluator depends on:
- float to integer truncates toward zero and is
Nonewhen the truncated value does not fit (or the float is NaN or infinite); - integer to float rounds to nearest, ties to even (Rust's
as); - float to float is Rust's
as(finite values may overflow to infinity).
Depends on
None.
Third-party
None.
Used by
| Crate | Repository | As | What it is |
|---|---|---|---|
half | lib-misc-utils | normal | Kinogaki's own half, published under the crates.io name so the frozen naga resolves to it through [patch.crates-io]. |
Third-party crates using it
Modules
boundsThe smallest and largest finite values of a type.8 linescastChecked conversions between the primitive number types.206 linesfloatFloating-point traits:FloatCore(no transcendental functions),Float(everything std'sf32/f64methods offer),Real(aFloatwithout the special values) andFloatConst.695 linesidentitiesThe additive and multiplicative identities.34 linesintPrimitive integers.42 linesopsChecked and wrapping arithmetic as traits.62 linesops::checkedno module doc22 linesops::wrappingno module doc18 linesrealReal numbers: everyFloatis one.4 linessignSign queries for signed numbers.12 lines
Public types and traits
At the crate root
Traits AsPrimitiveBoundedCheckedAddCheckedDivCheckedMulCheckedNegCheckedSubFloatFloatConstFloatCoreFromPrimitiveNumNumCastOnePrimIntSignedToPrimitiveWrappingAddWrappingMulWrappingNegWrappingSubZero
By module: 22 public types and traits in 8 modules
bounds Bounded
cast AsPrimitiveFromPrimitiveNumCastToPrimitive
float FloatFloatConstFloatCoreReal
identities OneZero
int PrimInt
ops::checked CheckedAddCheckedDivCheckedMulCheckedNegCheckedSub
ops::wrapping WrappingAddWrappingMulWrappingNegWrappingSub
sign Signed
Besides these, 3 public functions at module level.
