Crates.io | i_float |
lib.rs | i_float |
version | 1.2.0 |
source | src |
created_at | 2023-08-28 08:13:40.1783 |
updated_at | 2024-07-13 10:01:39.574944 |
description | This fixed float math library provides an efficient and deterministic solution for arithmetic and geometric operations. |
homepage | |
repository | https://github.com/iShape-Rust/iFloat |
max_upload_size | |
id | 956675 |
size | 48,994 |
This fixed float math library provides an efficient and deterministic solution for arithmetic and geometric operations.
Fixed-point arithmetic using FixNumber for deterministic calculations
2D fixed-point vector operations with FixVec
Trigonometric functions using fixed-point angles
Angle conversion and manipulation utilities in FixAngle
use i_float::fix_float::FixFloat;
use i_float::fix_vec::FixVec;
The `FixFloat` struct uses fixed-point arithmetic to perform calculations with a high degree of precision and determinism. It supports numbers in the range 2^21 - 1 to -2^21 + 1 with a precision of 1/1024, and is most suitable for the range 1,000,000 to -1,000,000 with a precision of 0.01.
Fixed-point numbers are represented using a fixed number of bits for the fractional part. In this implementation, the number of bits representing the fractional part of the fixed-point number is 10, which allows for a precision of 1/1024 or approximately 0.001.
Here are some examples of fixed-point number representation:
By using the `FixFloat` struct, you can perform arithmetic operations using i64 values while maintaining the precision of floating-point numbers, ensuring deterministic behavior across different platforms and devices.
The `FixFloat` struct represents a fixed-point number using a `i64` as the underlying storage, allowing deterministic arithmetic operations. Use `FixFloat` for calculations instead of `i32` or `i64` when deterministic behavior is required. `FixFloat` provides a way to perform arithmetic operations with `i64` values while maintaining the precision of floating-point numbers.
let a = FixFloat::new_number(1);
let b = FixFloat::new_number(2);
let c = a + b;
The `FixVec` struct represents a 2D fixed-point vector, providing various utility methods and operators for vector operations. Use `FixVec` for 2D geometric calculations when deterministic behavior is required.
let a = FixVec::new_number(1, 1);
let b = FixVec::new_number(1, -1);
let c = a + b;
The `FixAngle` class provides various utility methods for working with fixed-point angles, including trigonometric functions and angle conversion.
let fix_angle = FixAngle::new_from_radians_f64(angle);
let fix_sin = fix_angle.sin();
let i64_sin = fix_sin.double();