I'm not an expert on floating point math, but the "Does adding a small number do nothing?" example caught my eye, because the numbers used are constants, which are arbitrary precision in some languages (https://stackoverflow.com/questions/57511935/what-is-the-pur...). For instance, Go answers the question with false (but still prints out "1e+16" when you try to print 1e16 + 1): https://go.dev/play/p/mSAktWpCRJA
Rust explicitly requires that constants are typed.
const FOO: f32 = 0.75; // The 32-bit floating point value three quarters
If you try
const UNTYPED = 0.75; // Does not compile, pick a type
I don't find the SO answer very convincing because it seems like it's trying to argue this is the Reals, and it just isn't, it's only a subset of the Rationals which happened to be convenient for Go to work with it. The Reals are much stranger.
Real numbers include rational numbers (numbers which can be represented as a fraction of two integers) and irrational numbers (numbers that can't be represented as a fraction - the most famous one is probably π). Since irrational numbers have an infinite number of decimal places, they obviously can't be stored as a floating point value and also can't be written down exactly, no matter how many decimal places you use. "Arbitrary precision" constants might get you closer, but yes, you will never be able to store a "true" irrational number in a computer.
roughly represent each number as a turing machine, which on input i outputs the ith digit. it works fine (it's slower than floats, but that's a different concern).
the issue is that the computable numbers are relatively small. in particular, there are countably many turing machines, so they're a countable subset (in fact subfield) of the reals. so in a precise sense they only make up a vanishingly small fraction of the real numbers. but they still capture many important mathematical constants, e.g. e and pi.
Comments
I'm not an expert on floating point math, but the "Does adding a small number do nothing?" example caught my eye, because the numbers used are constants, which are arbitrary precision in some languages (https://stackoverflow.com/questions/57511935/what-is-the-pur...). For instance, Go answers the question with false (but still prints out "1e+16" when you try to print 1e16 + 1): https://go.dev/play/p/mSAktWpCRJA
Rust explicitly requires that constants are typed.
If you try I don't find the SO answer very convincing because it seems like it's trying to argue this is the Reals, and it just isn't, it's only a subset of the Rationals which happened to be convenient for Go to work with it. The Reals are much stranger.Real numbers include rational numbers (numbers which can be represented as a fraction of two integers) and irrational numbers (numbers that can't be represented as a fraction - the most famous one is probably π). Since irrational numbers have an infinite number of decimal places, they obviously can't be stored as a floating point value and also can't be written down exactly, no matter how many decimal places you use. "Arbitrary precision" constants might get you closer, but yes, you will never be able to store a "true" irrational number in a computer.
> you will never be able to store a "true" irrational number in a computer.
Joke's on you, in my programming language all numbers are written in phinary: https://en.wikipedia.org/wiki/Golden_ratio_base
It must be interesting to program in it!
But yes, you can absolutely represent irrational numbers (only a finite amount of them of course). You can even do it symbolically.
it's worth mentioning the infinite number of decimal places isn't an issue. there is the formalism of computable numbers to get around this
https://en.wikipedia.org/wiki/Computable_number
roughly represent each number as a turing machine, which on input i outputs the ith digit. it works fine (it's slower than floats, but that's a different concern).
the issue is that the computable numbers are relatively small. in particular, there are countably many turing machines, so they're a countable subset (in fact subfield) of the reals. so in a precise sense they only make up a vanishingly small fraction of the real numbers. but they still capture many important mathematical constants, e.g. e and pi.
Sorry, what exactly is your disagreement with the SO answer? It doesn't mention the reals.