Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Aren't floating point comparisons frowned upon? https://github.com/google/pebble/blob/main/src/libc/math/flo...

I guess you can freeze some compiler options to give you consistent results.



This case looks okay. It's converting a double to an int64_t and then back to double for comparison. It doesn't really suffer from the typical reason why floating point comparison is frowned upon, such as catastrophic cancellation.

I've once optimized a function to be faster, and in a unit test asserted that the old slower version gives exactly the same floating point answer as the new optimized version. It's doable in some cases.


I've only done a little bit of arduino programming, but for that you had to import a whole library for floating point math which took a huge amount of space, and many chips didn't even have hardware support for it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: