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

And don't forget to adjust after multiplication, e.g. ($ * kg) = (price * qty) / (10 ^ qty_scale).

But not before you finished with a "sequence-point" in calculations, cause otherwise rounding will accumulate, e.g. ((price * qty) * (100 * (10 ^ pct_scale) - discount)) / (10 ^ (qty_scale + pct_scale)).

Thus no operator[+-*/%^] magic for you either. Also, all these temporary ...0000000s will bite into your "mantissa" part along the way. Fixed point sounds reasonable until you have to actually implement a sales/debt/tax/trade-related routine that takes a couple of pages with proper decimals alone.



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

Search: