3 ms·
> binary floating points as the default representation for literals expressed as precise decimals. For better or worse, it is a widespread practice appearing i
by kazinator 11y ago
> binary floating points as the default representation for literals expressed as precise decimals.
For better or worse, it is a widespread practice appearing in numerous programming languages, including some widely used popular ones.
To conform with the practice, if you want, in your language, a way to use decimals to write exact fractional numbers, it's better to have an explicit notation for that like, say, 10.5r (rational number, another spelling for 21/2). Or hey: 10R5. Electrical Engineers will love you to death. :)
- dragonwriter 11y ago> For better or worse, it is a widespread practice appearing in numerous programming languages, including some widely used popular ones. Well, yeah, I've been programming since the 1980s. I know that. > To conform with the practice, if you want, in your language, a way to use decimals to write exact fractional numbers, it's better to have an explicit notation for that Sure, given that your goal is to conform with that practice. I'm just saying its a bad practice that reflects a generally premature optimization that often harms correctness, so we shouldn't conform to it in new languages.
- raiph 11y ago> [implicitly approximating numbers like `0.1`] is a widespread practice Sure, but the key point is that it leads to approximation that may cause problems. It makes much more sense to interpret `0.1` as meaning exactly that number. Same with, say, `29/7`. If someone wants approximation, then have an explicit notation for that, like, say, `1.23e45`.