#numbers #operation #hexga #constant #traits #basic #zero #xor #macro

hexga_number

Provide basic trait and constant for number, and the macro map_on!

16 releases

Uses new Rust 2024

0.0.10-beta.16 Jun 1, 2025
0.0.10-beta.13 May 29, 2025
0.0.10-beta.3 Apr 20, 2025
0.0.10-beta.1 Mar 31, 2025

#2414 in Rust patterns

Download history 692/week @ 2025-03-26 164/week @ 2025-04-02 39/week @ 2025-04-09 153/week @ 2025-04-16 24/week @ 2025-04-23 792/week @ 2025-05-07 274/week @ 2025-05-14 134/week @ 2025-05-21 515/week @ 2025-05-28 38/week @ 2025-06-04 18/week @ 2025-06-11 14/week @ 2025-06-18

599 downloads per month
Used in 14 crates (5 directly)

MIT/Apache

38KB
623 lines

HexGa Number

Provide basic number functionality, like

  • Some constant in trait : Zero One Half, MaxValue, MinValue, NaNValue,

  • Some trait that regroup multiple operation :

    • Type of operations

      • BitArithmetic : For every type that support bit based operation (and &, or |, xor ^, not !, shift << / >>...).
      • UnitArithmetic : +, -, 0
      • NumberArithmetic : +, -, *, /, %, 0 - ArithmeticNegative : same as NumberArithmetic + Neg operator,
      • Number : +, -, *, /, %, 0, 1, ==, >=, min val, max val,
      • NumberNegative same as Number + Neg operator,
    • Float and Int related : Floating, Integer, IntegerUnsigned, IntegerSigned

  • Useful macro : map_on_integer, map_on_integer_unsigned, map_on_integer_signed, map_on_float, map_on_number

Example using a map_on! macro

/// Define the `0` representation : The absorbing element of the multiplication such that `x * X::ZERO = X::ZERO`
pub trait Zero : Sized
{
    /// The absorbing element of the multiplication such that `x * X::ZERO = X::ZERO`
    const ZERO : Self;
}

map_on_number!(
    ($name:ident) =>
    {
        impl Zero for $name
        {
            const ZERO : Self = 0 as Self;
        }
    }
);
// and tada! Zero is now implemented for : (`i8`, `i16`, `i32`, `i64`, `isize`) + (`u8`, `u16`, `u32`, `u64`, `usize`) + (`f32`, `f64`)

Main Hexga crate

Check hexga : https://crates.io/crates/hexga if you are interested in a quick start, it regroup multiple hexga crates.

Dependencies