Trev13@programming.dev to Programming@programming.dev · 2 months agoBig Decimals: Stop Using Floats or Cents for Moneymedium.comexternal-linkmessage-square28fedilinkarrow-up174arrow-down12
arrow-up172arrow-down1external-linkBig Decimals: Stop Using Floats or Cents for Moneymedium.comTrev13@programming.dev to Programming@programming.dev · 2 months agomessage-square28fedilink
minus-squarerandy@lemmy.calinkfedilinkarrow-up13·edit-22 months agoI got hung up on this line: This requires deterministic math with explicit rounding modes and precision, not the platform-dependent behavior you get with floats. Aren’t floats mostly standardized these days? The article even mentions that standard. Has anyone here seen platform-dependent float behaviour? Not that this affects the article’s main point, which is perfectly reasonable.
minus-squarenimpnin@sopuli.xyzlinkfedilinkarrow-up14·2 months agoMostly standardized? Maybe. What I know is that float summation is not associative, which means that things that are supposed to be equal (x + y + z = y + z + x) are not necessarily that for floats.
minus-squarepinball_wizard@lemmy.ziplinkfedilinkarrow-up2·2 months agoThe real standard is whatever Katherine in accounting got out of the Excel nightmare sheets they reconcile against.
minus-squarebleistift2@sopuli.xyzlinkfedilinkEnglisharrow-up2arrow-down2·edit-22 months agoIf you count the programming language you use as ‘platform’, then yes. Python rounds both 11.5 and 12.5 to 12.
minus-squareWolfLink@sh.itjust.workslinkfedilinkarrow-up3·2 months agoThis is a common rounding strategy because it doesn’t consistently overestimate like the grade school rounding strategy of always rounding up does.
minus-squareFizzyOrange@programming.devlinkfedilinkarrow-up2·2 months agoThat is default IEEE behaviour: https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even This is the default rounding mode used in IEEE 754 operations for results in binary floating-point formats. Though it’s definitely a bad default because it’s so surprising. Javascript and Rust do not do this. Not really anything to do with determinism though.
I got hung up on this line:
Aren’t floats mostly standardized these days? The article even mentions that standard. Has anyone here seen platform-dependent float behaviour?
Not that this affects the article’s main point, which is perfectly reasonable.
Mostly standardized? Maybe. What I know is that float summation is not associative, which means that things that are supposed to be equal (x + y + z = y + z + x) are not necessarily that for floats.
The real standard is whatever Katherine in accounting got out of the Excel nightmare sheets they reconcile against.
If you count the programming language you use as ‘platform’, then yes. Python rounds both 11.5 and 12.5 to 12.
This is a common rounding strategy because it doesn’t consistently overestimate like the grade school rounding strategy of always rounding up does.
That is default IEEE behaviour: https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even
Though it’s definitely a bad default because it’s so surprising. Javascript and Rust do not do this.
Not really anything to do with determinism though.