We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Traits:
It would be useful to be able to derive implementations for simple types that are composed of already comparable types, for example:
#[derive(FloatUlps, FloatDiff, FloatEq, FloatEqDebug)] struct MyComplex32 { re: f32, im: f32, }
Would generate the following:
struct MyComplex32Ulps { re: Ulps<f32>, im: Ulps<f32>, } impl FloatUlps for MyComplex32 { type Ulps = MyComplex32Ulps; } impl FloatDiff for MyComplex32 { type Output = Self; fn abs_diff(self, other: Self) -> Self::Output{ Self::Output { re: self.re.abs_diff(other.re), im: self.im.abs_diff(other.im), } } fn ulps_diff(self, other: Self) -> Option<Self::UlpsDiff> { Some(MyComplex32Ulps { re: self.re.ulps_diff(other.re)?, im: self.im.ulps_diff(other.im)?, }) } } impl FloatEq for MyComplex32 { type Epsilon = <f32 as FloatEq>::DiffEpsilon; fn eq_abs(&self, other: &Self, max_diff: &Self::DiffEpsilon) -> bool { self.re.eq_abs(&other.re, max_diff) && self.im.eq_abs(&other.im, max_diff) } fn eq_rel(&self, other: &Self, max_diff: &Self::DiffEpsilon) -> bool { self.re.eq_rel(&other.re, max_diff) && self.im.eq_rel(&other.im, max_diff) } fn eq_ulps(&self, other: &Self, max_diff: &Ulps<Self::Epsilon>) -> bool { self.re.eq_ulps(&other.re, max_diff) && self.im.eq_ulps(&other.im, max_diff) } } impl FloatEqDebug for MyComplex32 { type DebugEpsilon = Self; fn debug_abs_epsilon(&self, other: &Self, max_diff: &Self::DiffEpsilon) -> Self::DebugEpsilon { MyComplex32 { re: self.re.debug_abs_epsilon(&other.re, max_diff), im: self.im.debug_abs_epsilon(&other.im, max_diff), } } fn debug_rel_epsilon(&self, other: &Self, max_diff: &Self::DiffEpsilon) -> Self::DebugEpsilon { MyComplex32 { re: self.re.debug_rel_epsilon(&other.re, max_diff), im: self.im.debug_rel_epsilon(&other.im, max_diff), } } fn debug_ulps_epsilon( &self, other: &Self, max_diff: &Ulps<Self::Epsilon>, ) -> Ulps<Self::DebugEpsilon> { MyComplex32Ulps { re: self.re.debug_ulps_epsilon(&other.re, max_diff), im: self.im.debug_ulps_epsilon(&other.im, max_diff), } } }
The text was updated successfully, but these errors were encountered:
Implemented for all float_eq traits in 4cfdcad
Sorry, something went wrong.
No branches or pull requests
Traits:
It would be useful to be able to derive implementations for simple types that are composed of already comparable types, for example:
Would generate the following:
The text was updated successfully, but these errors were encountered: