Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Float(f32);
- impl PartialEq<f32> for Float {
- fn eq(&self, other: &f32) -> bool {
- (self.0 as f32).eq(other)
- }
- }
- impl PartialEq<f64> for Float {
- fn eq(&self, other: &f64) -> bool {
- (self.0 as f64).eq(other)
- }
- }
- fn main() {
- let f = Float(5.0);
- let a = 10.0f32;
- let b = 10.0f64;
- let c = 10.0;
- dbg!(f == a);
- dbg!(f == b);
- dbg!(f == c);
- dbg!(std::mem::size_of_val(&a));
- dbg!(std::mem::size_of_val(&b));
- dbg!(std::mem::size_of_val(&c)); // <- this cast and compares both
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement