News for hackers. Stuff that matters.
Re:Python rounds float values by converting them to string a... by TekMol on Wednesday August 28, 2019 @06:58AM (#20818564)

    Computers can only natively store integers,
    so they need some way of representing decimal numbers.
Really? How do computers "natively" store integers?
Re:Python rounds float values by converting them to string a... by mumblemumble on Wednesday August 28, 2019 @07:28AM (#20818701)
The intent of that sentence is a lot clearer if you also consider the subsequent text, which expands on the idea quite a bit:

> Computers can only natively store integers, so they need some way of representing decimal numbers. This representation comes with some degree of inaccuracy. . . Why does this happen? It's actually pretty simple. When you have a base 10 system (like ours), it can only express fractions that use a prime factor of the base. . .

Perhaps a more formally correct way to put it is that integers (and natural numbers) are the only numbers that a computer can manage in a way that behaves reasonably similarly to the corresponding mathematic set. Specifically, as long as you stick to their numeric range, computer ints behave like a group, just like real integers do. But IEEE floats break the definition of a field in every which way, so they're really not a great match for the rationals.

That said, you could represent the rationals as a pair of integers, and that would be better-behaved, and some programming languages do do that. But I'm not aware of an ISA that supports it directly.

Re:Python rounds float values by converting them to string a... by tyingq on Wednesday August 28, 2019 @07:04AM (#20818592)
It seems to just be layman shorthand for storing (not huge) integers as binary isn't lossy.
Re:Python rounds float values by converting them to string a... by Dylan16807 on Wednesday August 28, 2019 @07:34AM (#20818727)
Storing integers as decimal (which computers can do easily) isn't lossy either.
Re:Python rounds float values by converting them to string a... by viraptor on Wednesday August 28, 2019 @08:08AM (#20818947)
I believe that's where "natively" comes in. If you store it in binary, you can operate on the values as numbers. If you do some decimal conversion, it's a blob of data. (Yes, there are BCD instructions but they're massively limited)
Re:Python rounds float values by converting them to string a... by SmellyGeekBoy on Wednesday August 28, 2019 @08:27AM (#20819070)
Decimal numbers are still "stored as binary" at the silicon level.
Re:Python rounds float values by converting them to string a... by mondoshawan on Wednesday August 28, 2019 @09:16AM (#20819429)
Unless you're on an IBM 1401... :D
Re:Python rounds float values by converting them to string a... by Merrill on Wednesday August 28, 2019 @11:30AM (#20820762)
z14 and Power 9 appear to support decimal integer and float. Does Python on those processors support their use?
Re:Python rounds float values by converting them to string a... by tyingq on Wednesday August 28, 2019 @10:59AM (#20820441)
I meant as opposed to floats, precision loss, etc.
Re:Python rounds float values by converting them to string a... by bregma on Wednesday August 28, 2019 @10:24AM (#20820058)
Maybe you need to parse "decimal numbers" as "fractional numbers" rather than "expressed using a radix of 10".

Perhaps it would be better phrased as "computers can only store whole numbers, so they need some way to represent other information, including integers, rational numbers and approximations to complex numbers."