|
|
|
|
|
by Lowkeyloki
2525 days ago
|
|
I agree that fixed point is the way to go for currency. But I read that as meaning COBOL didn't have floating point data types at all. I'm guessing that assumption was wrong. The advantage to floating point math over fixed point is speed. If it wasn't for that, nobody would ever want to use floating point. |
|
The main reason people use floating-point math is convenience. It's like dynamic typing: write your real quadratic equation solver with floating-point math and you can use it for everything, whether the values are 6.02e23 or 555e-9, at the expense of having to do extra computation at run-time, just like dynamic typing lets you implement a single hash table type that works for any type of value. But in fixed-point, unless you're using a pretty fancy language, you need to decide on the magnitude range of your values up front. Maybe 3e-6 to 3e5? Use 16.16. Maybe 4e-3 to 1e11? Use 24.8. It's a pain in the bohonkus. But it's faster, more portable (if reproducible results are necessary) and easier to reason about than floating point.