Advertisement
Guest User

Untitled

a guest
May 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. struct Float(f32);
  2.  
  3. impl PartialEq<f32> for Float {
  4. fn eq(&self, other: &f32) -> bool {
  5. (self.0 as f32).eq(other)
  6. }
  7. }
  8.  
  9. impl PartialEq<f64> for Float {
  10. fn eq(&self, other: &f64) -> bool {
  11. (self.0 as f64).eq(other)
  12. }
  13. }
  14.  
  15. fn main() {
  16. let f = Float(5.0);
  17. let a = 10.0f32;
  18. let b = 10.0f64;
  19. let c = 10.0;
  20. dbg!(f == a);
  21. dbg!(f == b);
  22. dbg!(f == c);
  23. dbg!(std::mem::size_of_val(&a));
  24. dbg!(std::mem::size_of_val(&b));
  25. dbg!(std::mem::size_of_val(&c)); // <- this cast and compares both
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement