Trev13@programming.dev to Programming@programming.dev · 9 days agoBig Decimals: Stop Using Floats or Cents for Moneymedium.comexternal-linkmessage-square26fedilinkarrow-up174arrow-down12
arrow-up172arrow-down1external-linkBig Decimals: Stop Using Floats or Cents for Moneymedium.comTrev13@programming.dev to Programming@programming.dev · 9 days agomessage-square26fedilink
minus-squarerandy@lemmy.calinkfedilinkarrow-up13·edit-28 days 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-up13·8 days 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·8 days 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-28 days 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·8 days 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·8 days 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.