fdec
A collection of macros for generating fixed-size fixed-point numeric types that exactly fit your domain. The types are fully equipped for performing mathematical computations and are easy to use.
With a simple macro call you get a type that:
- has no representation errors in the range, defined by the type parameters,
- supports arithmetic operations:
+,-,*,/,%,<<,>>, - comes with mathematical functions:
abs(),powi(),sqrt(), - has special values NaN and ±Infinity, and uses them instead of panicing,
- provides basic mathematical constants,
- seamlessly interacts with Rust's primitive types,
- creates values and performs math operations on stack, avoiding heap allocations.
Usage
First, add the dependency on fdec to your Cargo.toml:
[]
= "0.2"
Second, import it at your crate's root with the macro_use attribute:
extern crate fdec;
Now, everything is ready for adding custom numeric types to your project.
Example
Here, we define the Decimal structure that represents 160-bit numbers
with 30 decimal places.
extern crate fdec;
fdec32!
use *; // Bring the generated stuff to the scope
More examples come with the crate's source code:
- Many ways to create values: creation.rs
- Compute Fibonacci numbers: fibonacci.rs
- Calculate square root with high precision: sqrt.rs