provekit-whir 0.1.1

An implementation of the WHIR polynomial commitment scheme
Documentation
use std::{
    cmp::Ordering,
    fmt::{self, Display},
    hash::Hash,
};

use serde::{Deserialize, Serialize};

/// Wrapper for `bits` value types.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct Bits(f64);

impl Hash for Bits {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.0.to_bits().hash(state);
    }
}

impl Eq for Bits {}

impl Bits {
    pub fn new(bits: f64) -> Self {
        assert!(bits.is_finite());
        Self(bits)
    }

    pub fn is_zero(&self) -> bool {
        self.0 == 0.0
    }
}

impl From<f64> for Bits {
    fn from(bits: f64) -> Self {
        Self::new(bits)
    }
}

impl From<Bits> for f64 {
    fn from(bits: Bits) -> Self {
        bits.0
    }
}

impl Display for Bits {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        <f64 as Display>::fmt(&self.0, f)
    }
}

impl PartialOrd for Bits {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for Bits {
    fn cmp(&self, other: &Self) -> Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}