Crates.io | intfinity |
lib.rs | intfinity |
version | 0.3.3 |
source | src |
created_at | 2024-09-03 14:41:25.327064 |
updated_at | 2024-09-29 15:47:31.586538 |
description | An abstraction over numeric types with infinity implemented. |
homepage | |
repository | https://github.com/samarthsoup/intfinity |
max_upload_size | |
id | 1361719 |
size | 57,530 |
intfinity
is a Rust crate that provides a generic type for representing and working with both finite and infinite numeric values. It supports operations that automatically handle overflow and underflow, mapping them to positive or negative infinity as appropriate.
Add
, Sub
, Mul
, and Div
traits with built-in overflow and underflow detection.Zero
, Negate
, Unsigned,CheckedAdd
, CheckedSub
, CheckedMul
, and CheckedDiv
allow for extensibility to custom numeric types.Add intfinity
to your Cargo.toml
:
[dependencies]
intfinity = "0.3.3"
use intfinity::DoubleInfiniteNumber;
fn main() {
let a = DoubleInfiniteNumber::new(42);
let b = DoubleInfiniteNumber::PosInfinity;
let result = a + b;
assert_eq!(result, DoubleInfiniteNumber::PosInfinity);
}
Intfinity comes with several traits that are essential for working with numeric types:
Zero: Defines the concept of zero for a type.
Negate: Provides a method to negate a value.
CheckedAdd, CheckedSub, CheckedMul, CheckedDiv: Provide arithmetic operations with overflow and underflow checks.
This project is under the MIT license.