| Crates.io | metallic |
| lib.rs | metallic |
| version | 0.2.0 |
| created_at | 2024-08-04 12:25:08.162241+00 |
| updated_at | 2025-08-03 12:27:36.296584+00 |
| description | C math functions from scratch |
| homepage | |
| repository | https://github.com/jdh8/metallic-rs |
| max_upload_size | |
| id | 1324940 |
| size | 7,631,268 |
A fast correctly rounded math library in Rust!
This library is a successor to Metallic, my C library for WebAssembly started in 2017. Its most wanted feature turned out to be math functions I wrote from scratch, so I decided to rewrite them in Rust.
This crate extensively uses the fused multiply-add instruction if available.
Sadly, Rust does not enable it in the default generic target. To achieve best
performance, add the following to your .cargo/config.toml either in your
project or home directory:
[build]
rustflags = ["-Ctarget-cpu=native"]
I struggle to make some functions faster than CORE-MATH. You can enable the
core-math feature in your Cargo.toml:
[dependencies]
metallic = { version = "0.1.2", features = ["core-math"] }
This would replace the following functions with those from
core-math:
f32f32::powf for correct roundingC libraries tend to have strict yet obsolete assumptions on math functions.
For example, float functions dare not use double instructions for fear
that the host does not support them. In this library, I assume all Rust
primitive types are IEEE 754 compliant and native to the host. In other
words, I assume the following instructions are available to floating-point
types:
f32::sqrt)f32::mul_add)f32::truncThe assumptions beyond the four basic arithmetic operations creates dependency on the Rust standard library.
Besides, I ignore the floating-point environment, which is not available in
Rust. It is also mostly unused in C and C++ because it requires #pragma STDC FENV_ACCESS ON and compiler support. Therefore, the only rounding mode in this
library is the default rounding half to even.
f32 functions faster than the system library.rint, round, and trunc because
f32::round_ties_even,
f32::round,
f32::trunc,
etc.fabs.f32/float functions in <math.h>
f32/float functions in <complex.h>f64/double functions in <math.h>
f64/double functions in <complex.h>