7 ms·
I would like to see a language use decimal by default. Under the hood, it could use floating point for certain types of calculations where less precision is req
by insertion 11y ago
I would like to see a language use decimal by default. Under the hood, it could use floating point for certain types of calculations where less precision is required. If I want to know the answer to 0.2 + 0.1, chances are I want the answer to be 0.3. If I'm writing performance-sensitive code, maybe I can drop down a level and opt for float(0.2) + float(0.1). Are any languages doing this currently?
- dpkendal 11y agoPerl 6 uses rationals by default. They have the advantages of being base-agnostic, able to accurately represent any recurring digit expansion accurately regardless of eventual base, and also faster (since, especially if you normalize (convert to lowest terms) lazily, most operations are just a few integer instructions with no branching, looping, or bit-twiddling involved).
- grondilu 11y agoTrue. Also notice that if the user wants a floating point, the literal format is the one with the e<exponent> suffix: 0.1e0, 1e-1, 0.2e0, 2e-1 etc.
- Kristine1975 11y agoYou want COBOL. It did decimal by default 50 years ago.
- dragonwriter 11y ago> I would like to see a language use decimal by default. So, Scheme?
- dTal 11y agoScheme has rationals, but decimal literals aren't rational by default. You have to type #e in front of it, or express it as a fraction. It really ought to be fixed at the implementation level (how much stuff would it really break if floatin point errors went away?), but failing that I'd love a macro that did it for me. I can't figure out how to write one robustly.
- grondilu 11y agoWouldn't you get other issues with decimal numbers? Consider 1/3 for instance. What you really want, I think, is rationals by default, as in Perl 6.