harness_algebra/arithmetic/primitive.rs
1//! # Primitive Types Implementation
2//!
3//! This module implements the algebraic traits from the crate for Rust's primitive numeric types.
4//!
5//! ## Implementations
6//!
7//! - `Additive`: Implemented for all primitive numeric types, indicating they form an additive
8//! structure
9//! - `Multiplicative`: Implemented for all primitive numeric types, indicating they form a
10//! multiplicative structure
11//! - `Infinity`: Implemented for floating point types (f32, f64), providing access to their
12//! infinity values
13//!
14//! These trait implementations allow primitive types to be used directly with the algebraic
15//! abstractions defined in this crate, enabling seamless integration between Rust's built-in
16//! types and the algebraic structures defined in this library.
17//!
18//! No additional methods are needed as Rust's primitive types already implement the required
19//! operations (`Add`, `Mul`, etc.) with the correct semantics.
20
21use super::*;
22
23// Implement Additive for all primitive numeric types
24impl Additive for u8 {}
25impl Additive for u16 {}
26impl Additive for u32 {}
27impl Additive for u64 {}
28impl Additive for u128 {}
29impl Additive for usize {}
30
31impl Additive for i8 {}
32impl Additive for i16 {}
33impl Additive for i32 {}
34impl Additive for i64 {}
35impl Additive for i128 {}
36impl Additive for isize {}
37
38impl Additive for f32 {}
39impl Additive for f64 {}
40
41// Implement Multiplicative for all primitive numeric types
42impl Multiplicative for u8 {}
43impl Multiplicative for u16 {}
44impl Multiplicative for u32 {}
45impl Multiplicative for u64 {}
46impl Multiplicative for u128 {}
47impl Multiplicative for usize {}
48
49impl Multiplicative for i8 {}
50impl Multiplicative for i16 {}
51impl Multiplicative for i32 {}
52impl Multiplicative for i64 {}
53impl Multiplicative for i128 {}
54impl Multiplicative for isize {}
55
56impl Multiplicative for f32 {}
57impl Multiplicative for f64 {}
58
59// Implement Infinity for float primitive numeric types
60impl Infinity for f32 {
61 const INFINITY: Self = Self::INFINITY;
62}
63
64impl Infinity for f64 {
65 const INFINITY: Self = Self::INFINITY;
66}