total_float_wrap 0.1.1

Floating point wrapper implementing Hash and Ord according to IEEE 754 totalOrd.
Documentation
  • Coverage
  • 25%
    1 out of 4 items documented1 out of 1 items with examples
  • Size
  • Source code size: 43.75 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.26 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • tritoke/total_float_wrap
    1 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • tritoke

total_float_wrap

A wrapper around Rust's floating point types which provides a total ordering and hashing which allows it to be used in data structures such as hashmaps etc. The ordering of this wrapper agrees with IEEE 754 totalOrd.

Example Code

Below is example code using TotalF64 as the key in a hashmap, it can be run with cargo run --example hashmap.

use std::collections::HashMap;
use total_float_wrap::TotalF64;

fn main() {
    let mut triangles: HashMap<TotalF64, Vec<(u32, u32)>> = Default::default();

    let start_adj = 1;
    let end_adj = 10;
    let start_opp = 1;
    let end_opp = 30;

    for adjacent in start_adj..=end_adj {
        for opposite in start_opp..=end_opp {
            triangles
                .entry(f64::atan2(adjacent.into(), opposite.into()).into())
                .or_default()
                .push((adjacent, opposite));
        }
    }

    let (_, vals) = triangles.iter().max_by_key(|v| v.1.len()).unwrap();
    
    println!("For the triangles in the square of points [{start_adj}..{end_adj}]x[{start_opp}..{end_opp}]");
    for (TotalF64(angle), group) in triangles.iter().filter(|v| v.1.len() == vals.len()) {
        println!("The group {group:?} has the maximal members");
        println!(
            "- with an angle of {:.2}° - a ratio of {:.5} between the opposite and the adjacent.",
            angle.to_degrees(), angle.tan()
        );
    }
}