6 ms·
It is a shame we tend to teach floats as the computer version of reals. Thinking of them as "scientific numbers" really helps a ton with this.
by taeric 1y ago
It is a shame we tend to teach floats as the computer version of reals. Thinking of them as "scientific numbers" really helps a ton with this.
- atn34 1y agoI want to make a Birds Aren't Real[0] style t-shirt that says "Floats Aren't Real" [0]: https://en.wikipedia.org/wiki/Birds_Aren%27t_Real https://en.wikipedia.org/wiki/Birds_Aren%27t_Real
- tialaramex 1y agoI would buy this T-shirt. I would also take "Floats Aren't Normal"
- munchler 1y agoTrue, but we also have to be careful about teaching ints as the computer version of integers.
- jrvieira 1y agowait, why?
- neepi 1y agoProper integers aren’t bounded. Computer ints are.
- jrvieira 1y agoUnbounded integer types exist, which have infinite precision in theory and are only limited by available memory in practice. You can make the argument that "proper" integers are also bounded in practice by limitations of our universe :)
- layer8 1y agoUnbounded integer types aren't ints. The important point is that the arithmetic operators on int perform modulo arithmetics, not the normal arithmetics you would expect on unbounded integers. This is often not explained when first teaching ints.
- adastra22 1y agoIn many langue’s (e.g. Python, so not even obscure languages), ints are unbounded.
- layer8 1y agoThat’s not the notion of ints the article, nor GP by “computer ints”, was referring to. Python is rather atypical in its nomenclature here. Arbitrary-precision integers are generally called “integer” or something like “bigint”.
- MathMonkeyMan 1y agoUnsigned ints are the non-negative integers mod 2^n. Signed ints behave like the integers in some tiny subset of representable values. Maybe it's something like the interval (-sqrt(INT_MAX), sqrt(INT_MAX)).
- AlotOfReading 1y agoThat's one way of looking at them. You can also look at the signed integers as bounded 2-adic numbers.
- LegionMammal978 1y ago"Bounded 2-adic integers" would only make sense if you were bounding the 2-adic norm. Integers mod 2^n would be closer to "approximate fixed-point 2-adic integers". (Alas, most languages don't expose a convenient multiplicative inverse for their integer types, and it's a PITA to write a good implementation of the extended Euclidean algorithm every time.)
- sjrd 1y agoSigned ints are also the integers mod 2^n. The beauty of modular arithmetics is that it's all equivalent. At least for all the operations that work in modular arithmetics in the first place. They just have different canonical representatives for their respective equivalence classes, which are used for the operations that don't work in modular arithmetics (like divisions, comparisons or conversions to string with a sign character).
- SkeuomorphicBee 1y agoNot in C. In C signed integer overflow is underined behaviour that may or may not be compiled to the equivalent of mod arithmetic dependingonthe whims of the compiler.
- adastra22 1y agoC oddities should be relegated to a footnote, not define what computer science is.
- perching_aix 1y agoAre they even reals? Math classes were a while ago at this point, but I'm fairly convinced they're just rationals. Not trying to be pedantic, just wondering.
- jrvieira 1y agoYes, all floating numbers are rational. (It's also true that they are all reals but i get your point.)
- neepi 1y agoThey aren’t pure rational either. They are a subset of rational numbers.
- perching_aix 1y agoI think that's more of how one frames it, no? Like you won't be able to store any arbitrary rational in a float, as you'd need arbitrarily large storage for that. But all the numbers a float can store are rationals (so excluding all the fanciful IEEE-754 features of course).
- tialaramex 1y agoIt's not so much the need for arbitrary storage, the problem is that even easy rationals can't be expressed in the IEEE floats Take realistic::Rational::fraction(1, 3) ie one third. Floats can't represent that, but we don't need a whole lot of space for it, we're just storing the numerator and denominator. If we say we actually want f64, the 8 byte IEEE float, we get only a weak approximation, 6004799503160661/18014398509481984 because 3 doesn't go neatly into any power of 2. Edited: An earlier version of this comment provided the 32-bit fraction 11184811/33554432 instead of the 64-bit one.
- neepi 1y agoThey aren’t reals. They aren’t continuous and are bounded.
- analog31 1y agoThe pitfalls of floats were taught when I was a college math major. That was in the mid 80s.
- capyba 1y agoIsn’t the `real` datatype in Fortran a float64? Or am I making that up?