fastinvsqrt

This was made purely for fun and testing crates.io publishing, but may actually be usable.

InvSqrt32 trait provide invsqrt32() function for primitive numeric types. InvSqrt64 provides invsqrt64().

How do I use it?

Cargo.toml:

toml [dependencies] fast_inv_sqrt = "1.0.0"

Code:

```rust extern crate fastinvsqrt;

use fastinvsqrt::InvSqrt32; use fastinvsqrt::InvSqrt64;

fn main() { let f: f32 = 1.234; println!("{}", f.inv_sqrt32());

let i: i8 = 55;
println!("{}", i.inv_sqrt64());

} ```

Benchmarks

Benchmarks require nightly compiler.

"ref" benchmarks use f1 / f2.sqrt() "impl" benchmarks use f1 * f2.inv_sqrtXX()

$ cargo bench --features 'nightly' ``` test test32::benchplainimpl ... bench: 8 ns/iter (+/- 0) test test32::benchplainref ... bench: 13 ns/iter (+/- 0)

test test32::benchrealimpl ... bench: 8 ns/iter (+/- 0) test test32::benchrealref ... bench: 13 ns/iter (+/- 0)

test test64::benchplainimpl ... bench: 10 ns/iter (+/- 0) test test64::benchplainref ... bench: 20 ns/iter (+/- 0)

test test64::benchrealimpl ... bench: 10 ns/iter (+/- 0) test test64::benchrealref ... bench: 20 ns/iter (+/- 0) Feature 'omit-checking' disables checks of if value passed is_sign_positive() and is_normal(), and will produce invalid results for denormalized and negative values, but this is fast: test test32::benchplainimpl ... bench: 2 ns/iter (+/- 0) test test32::benchplainref ... bench: 13 ns/iter (+/- 0)

test test32::benchrealimpl ... bench: 3 ns/iter (+/- 0) test test32::benchrealref ... bench: 13 ns/iter (+/- 0)

test test64::benchplainimpl ... bench: 2 ns/iter (+/- 0) test test64::benchplainref ... bench: 20 ns/iter (+/- 0)

test test64::benchrealimpl ... bench: 3 ns/iter (+/- 0) test test64::benchrealref ... bench: 20 ns/iter (+/- 0) ```