Python rounds float values by converting them to string and then back
61–70 of 152 posts
Re: Python rounds float values by converting them to string and then back
#62I remember even writing a program that tested every possible floating point number (must have only been 32 bit). I think I used ctypes and interpreted every binary combination of 32 bits as a float, turned it into a string, then back and checked equality. A lot of them were NaN.
Re: Python rounds float values by converting them to string and then back
#63Apples libc used to shell-out to perl in a function: https://github.com/Apple-FOSS-Mirror/Libc/blob/2ca2ae7464771...
/* XXX this is _not_ designed to be fast */
laughing so hard :')
Re: Python rounds float values by converting them to string and then back
#64https://0.30000000000000004.com/
Somewhat offtopic, but is there a reason some many explanations of this issue lump together the fundamental principle of how numbers are represented (integers vs. fractions vs. exact reals (technically impossible) vs. IEEE 754) and the base (decimal vs. binary)? Every time I read something like the explanation on that site, I wonder if I would understand it if I didn't knew it already.
Re: Python rounds float values by converting them to string and then back
#65Re: Python rounds float values by converting them to string and then back
#66Earlier quoted context omitted.
I don't know that it is "wrong", just unexpected. I suspect most people expect all math functions to be purely implemented in numerical terms, so finding string manipulation is surprising/interesting.
> I don't know that it is "wrong", just unexpected. I suspect most people expect all math functions to be purely implemented in numerical terms, so finding string manipulation is surprising/interesting. You kind of got me thinking now. The decimal representation of a number is really a string representation (in the sense of a certain sequence of characters). Hence rounding to a certain decimal is essentially a string…
It is incorrect to speak of "the" decimal representation of a number, as many numbers have non-unique decimal representations, the most famous example being 1.000...=0.999...
Re: Python rounds float values by converting them to string and then back
#67https://0.30000000000000004.com/
The worst way to explain something is to begin with "It's actually pretty simple."
Humans generally are afraid of new words (especially weird sounding ones) and often will assume that the subject is complex and might intimidate them.
But unknown words can have extremely simple meanings, or be synonyms of already known words.
By asserting: "It's actually pretty simple" You give them confidence that there's not reason to be afraid of the topic or of the words.
Re: Python rounds float values by converting them to string and then back
#68Apples libc used to shell-out to perl in a function: https://github.com/Apple-FOSS-Mirror/Libc/blob/2ca2ae7464771...
I thought this is what the Unix philosophy is supposed to be all about. (Realistically, calling wordexp should just abort the program. Now I actually want to make a hacked up musl that aborts in all the various "libc functions no one should ever use" and see how far I get into a Ubuntu boot..)
Re: Python rounds float values by converting them to string and then back
#69CPython rounds float values by converting them to string and then back
Re: Python rounds float values by converting them to string and then back
#70Earlier quoted context omitted.
> I don't know that it is "wrong", just unexpected. I suspect most people expect all math functions to be purely implemented in numerical terms, so finding string manipulation is surprising/interesting. You kind of got me thinking now. The decimal representation of a number is really a string representation (in the sense of a certain sequence of characters). Hence rounding to a certain decimal is essentially a string…
>The decimal representation of a number is really a string representation It is incorrect to speak of "the" decimal representation of a number, as many numbers have non-unique decimal representations, the most famous example being 1.000...=0.999...
That's true and I'll concede that point, but it's not really relevant to what I said. That just means some numbers have different string representations that represent the same object. That doesn't really contradict anything in my post except the use of the definite article.