5 ms·
How do they represent real numbers? If anything, they represent rational numbers. Also I think your answer is unnecessarily nitpicky. Sentence 'floats can't re
by msm_ 4y ago
How do they represent real numbers? If anything, they represent rational numbers.
Also I think your answer is unnecessarily nitpicky. Sentence 'floats can't represent "simple" values like 0.1 (...)' is perfectly clear to everyone on HN, I hope. In fact, I disagree that changing "values" here to a more precise mathematical term would improve anything.
- astrange 4y ago> How do they represent real numbers? If anything, they represent rational numbers. That's an interesting philosophical question. Does M_PI represent a rational number? (M_PI isn't mentioned in my copy of the C spec, unless I just can't find it.)
- wadd1e 4y agodoes it not have to represent a rational approximation of Pi? Real numbers in the set theoretic sense are defined as limits of Cauchy sequences[0], and since we can't quite store an infinite sequence, it has to be a finite approximation due to the limitations of the real world. [0]: https://en.wikipedia.org/wiki/Cauchy_sequence https://en.wikipedia.org/wiki/Cauchy_sequence
- astrange 4y agoIt does after it's assigned to a variable, but maybe it doesn't before that.
- CamperBob2 4y agoRationals are a subset of the reals.
- otabdeveloper4 4y agoNo current computing architecture provides primitives for dealing for rational numbers. (Which is why you need to roll your own implementation in software, so nobody bothers.) But we have great native support for approximating real numbers instead. (Because computing is designed first and foremost to make numerical methods efficient.)
- otabdeveloper4 4y agoFloats are designed to be computationally and mathematically efficient approximations of the real numbers. The exist so that trigonometry and logarithms work properly in numerical methods. (A vastly more important problem than getting '0.1' to print pretty on the screen.) There is no such thing as a 'value' in mathematics, and fixating on 0.1 in particular is pointless. tldr - everyone should learn the math behind this first.