Posts

Showing posts with the label Math

[Not] Floating Point Math

Floating point math is something I always took for granted in software development, but I’ve recently been exposed to some of its nuances and how to better calculate values in some cases. Crash course, floating point is effectively just math with decimal places. Different languages use different terminology for the specific data types (“float” and “double” for double precision are common), but they’re all pretty much the same in concept. In decimal (base 10), it’s really not a big deal. Positive exponents go left or more significant from the decimal point, while negative exponents go right or less significant. You multiply or divide by 10, you go up or down in significance. This is all pretty elementary for most of us. The problem is that computers don’t operate in decimal, they use binary (base 2), zeroes and ones. So numbers with digits after the decimal point, fractions of a whole number, aren’t easily represented in binary. Instead, floating point data types use a combination of pr...