Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by tremon on Wednesday February 08, 2023 @03:42PM
(#34714736)
Decimals are notoriously hairy to implement
Only floating-point decimal is hairy. Fixed-point decimal is hardly more difficult than integer math.
Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by t8sr on Wednesday February 08, 2023 @04:00PM
(#34715057)
If you simply look at any of the real world implementations, you'll see it's not so easy. Rust has a few readable and educational crates that implement decimals, if you want to take a look.
Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by int_19h on Wednesday February 08, 2023 @05:41PM
(#34716612)
Decimal floating point is fine so long as you constrain the exponent such that delta between two consecutive valid numbers can never be greater than 1 (that is, there should never be any implicit trailing zeroes). .NET Decimal type is a good example.
Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by ElectricalUnion on Wednesday February 08, 2023 @06:00PM
(#34716846)
> Decimals are notoriously hairy to implement
That's because the binary is implemented in hardware for you; and those days you can usually (but not always) trust the hardware to do the correct thing; if you have to implement it youself (say, deterministic, side-effect free math), it's also hairy.
Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by midoridensha on Wednesday February 08, 2023 @10:09PM
(#34719293)
A lot of times, though, currency is not fixed. Stock share prices can be in fractions of a cent; per-unit cost numbers can easily have fractional cents too, just for a couple of quick examples. Sure, if you're just looking at your bank account, or itemizing actual transactions, they're going to be in whole cents only, but lots of financial calculations need more precision than this.
Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by piaste on Thursday February 09, 2023 @04:23AM
(#34721541)
Having different numeric types for currency amounts (integer) and for costs or prices (floating point, whether decimal or binary) is not undesirable. Heck, it's very likely a bonus.
Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by mcv on Thursday February 09, 2023 @06:55AM
(#34722642)
That sounds like a recipe for disaster. If you have fractional unit prices, and multiply by the number of units, floats can still give you errors. No, fixed decimal types definitely have their uses.
(I guess it depends on what you mean by "true" decimal. If you meant BigNum, then sure.)