Hacker News new | ask | show | jobs
by quotemstr 1724 days ago
My position for ages now has been that it was a mistake to make floating point types first-class primitives in most programming languages. Integers and rationals should be the go-to types for most code most of the time. If you really need a IEEE float, you should reach into a library to get it.
6 comments

Well, this isn't very strong support for that position, because Ethereum doesn't support floating point, and yet here we are.
> Ethereum doesn't support floating point

The software that interacts with it does.

I think you mixed up the problem. Had they used floats they would have got a small rounding error, not a 23 million loss.
So all companies will automatically include the float library and thus nothing will change
What you include as a first-class element in your languages, versus what is packed away in a library, will affect what developers do with your language.

For instance, Numpy provides array-language [1] capabilities to Python, but because it isn't a first-class element in the language Python is not thought of as an array language, and using it as one would be a bit clunky.

[1] https://en.wikipedia.org/wiki/Array_programming

If the only thing you use computers for is processing financial transactions then that position is defendable
Any number of sensors, measuring devices and other IoT stuff disagrees with you.
Dumb question on my end, I apologize.

How are rationals used to represent decimals?

> How are rationals used to represent decimals?

Decimals are just the subset of rationals where the denominator is always a power of 10, so the representation and arithmetic operations are simple if you already have rational support (though if you need to preserve decimal results, you need approximation logic for division, since dividing two rationals with denominators that are powers of 10 may result in a rational with a denominator that is not a power of 10.)

> though if you need to preserve decimal results, you need approximation logic for division, since dividing two rationals with denominators that are powers of 10 may result in a rational with a denominator that is not a power of 10.

This is also true for adding, subtracting, and multiplying, though in those cases it is always trivial to convert the result into a form where the denominator is a power of 10.