Created
February 25, 2026 21:47
-
-
Save Yoplitein/0985155bc9f0a93ebde3c249643dcb26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub trait FloatExt { | |
| fn abs_diff(self, rhs: Self) -> Self; | |
| fn approx_equal(self, rhs: Self, epsilon: Self) -> bool; | |
| } | |
| impl FloatExt for f32 { | |
| fn abs_diff(self, rhs: Self) -> Self { | |
| (self - rhs).abs() | |
| } | |
| fn approx_equal(self, rhs: Self, epsilon: Self) -> bool { | |
| self.abs_diff(rhs) < epsilon | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment