Hacker News new | ask | show | jobs
by opportune 1225 days ago
In addition to what others mentioned, to start from the basics I would try to learn how floating point values are implemented and how processors evaluate floating point expressions. For example the float is separated into two parts, it’s not able to efficiently represent many decimal numbers, etc.

A simple rule of thumb is to try to avoid using floating point values at all outside of contexts like scientific simulations. For basic situations, you can almost always use either a library (for big numbers, decimals, fractions, etc.) or express your logic with ints by using established patterns (make the unit of measurement smaller/bigger, explicitly round up or down, etc.). Any time you take something that is an int 99% of the time, convert it to a float for something, then convert it back to an int, you are doing something wrong.