scalars 0.1.0

Minimal numeric traits: Zero, One, Inv, Sqrt, Exp, Trigonometry, Real, Integer
Documentation
  • Coverage
  • 0%
    0 out of 36 items documented0 out of 32 items with examples
  • Size
  • Source code size: 11.57 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.58 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 16s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • porky11

scalars

Minimal numeric traits for Rust. Zero dependencies.

Replacement for num-traits with single-purpose traits instead of monolithic kitchen-sink traits.

Traits

Identities & Operations

  • Zerofn zero(), fn is_zero()
  • Onefn one(), fn is_one()
  • Invfn inv() with associated Output type
  • Sqrtfn sqrt()

Exponential

  • Expfn exp(), fn exp2() with associated Output type (supports Bivector → Rotor)

Trigonometry

  • Trigonometryfn sin_cos() -> [Self; 2], fn sin(), fn cos(), fn tan()
  • InverseTrigonometryfn asin(), fn acos(), fn atan(), fn atan2()

Ordering

  • Clampfn min(), fn max(), fn clamp()

Parsing

  • FromStrRadixfn from_str_radix() with associated Error type

Supertraits

  • NumericCopy + PartialEq + Add + Sub + Mul + Zero + One
  • IntegerNumeric + Eq + Ord + Div + Rem
  • RealNumeric + PartialOrd + Div + Neg + Inv + Sqrt + Exp + Trigonometry + InverseTrigonometry + Clamp

All supertraits have blanket implementations.

Implementations

  • f32, f64 — all traits including Real
  • i8..i128, u8..u128, isize, usizeZero, One, Clamp, FromStrRadix, Integer

Example

use scalars::{Real, Zero};

fn normalize<T: Real>(values: &mut [T]) {
    let sum: T = values.iter().copied().fold(T::zero(), |accumulator, value| accumulator + value);
    if !sum.is_zero() {
        for value in values {
            *value = *value / sum;
        }
    }
}

AI-assisted development

This crate is designed for use with AI coding assistants. Each trait covers exactly one concept, all supertraits use blanket implementations, and there is no implicit behavior. The Exp trait's associated Output type enables geometric algebra types (Bivector → Rotor) alongside scalar floats.