fast_inv_sqrt 1.0.1

Fast inverse square root algorithm implementation.
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented0 out of 4 items with examples
  • Size
  • Source code size: 13.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 337.16 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • emkw/rust-fast_inv_sqrt
    6 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • emkw

fast_inv_sqrt

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

InvSqrt32 trait provide inv_sqrt32() function for primitive numeric types. InvSqrt64 provides inv_sqrt64().

How do I use it?

Cargo.toml:

[dependencies]
fast_inv_sqrt = "~1.0"

Code:

extern crate fast_inv_sqrt;

use fast_inv_sqrt::InvSqrt32;
use fast_inv_sqrt::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::bench_plain_impl ... bench:           6 ns/iter (+/- 0)
test test32::bench_plain_ref  ... bench:          13 ns/iter (+/- 0)

test test32::bench_real_impl  ... bench:           6 ns/iter (+/- 0)
test test32::bench_real_ref   ... bench:          13 ns/iter (+/- 0)

test test64::bench_plain_impl ... bench:           6 ns/iter (+/- 0)
test test64::bench_plain_ref  ... bench:          20 ns/iter (+/- 0)

test test64::bench_real_impl  ... bench:           6 ns/iter (+/- 0)
test test64::bench_real_ref   ... 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::bench_plain_impl ... bench:           2 ns/iter (+/- 0)
test test32::bench_plain_ref  ... bench:          13 ns/iter (+/- 0)

test test32::bench_real_impl  ... bench:           3 ns/iter (+/- 0)
test test32::bench_real_ref   ... bench:          13 ns/iter (+/- 0)

test test64::bench_plain_impl ... bench:           2 ns/iter (+/- 0)
test test64::bench_plain_ref  ... bench:          20 ns/iter (+/- 0)

test test64::bench_real_impl  ... bench:           3 ns/iter (+/- 0)
test test64::bench_real_ref   ... bench:          20 ns/iter (+/- 0)