That "digits=18" in R example probably bothers me more than it should.
0.30000000000000004
21–30 of 140 posts
Re: 0.30000000000000004
#22It's stuff that should be a part of very beginning of any CS101. Float arithmetics != Decimal arithmetics
Re: 0.30000000000000004
#23Previous discussions: https://news.ycombinator.com/item?id=10558871 (1.5 years ago, 240 comments) https://news.ycombinator.com/item?id=1846926 (6.5 years ago, 128 comments)
I haven't seen it yet... what's with that final four (common to all languages)?
See IEEE754
Re: 0.30000000000000004
#24Key idea is not just to map binary floating point value X to a decimal floating point value Y, but instead (in extended precision, with 64-bit mantissa) compute an interval of decimal floating point values [Y1, Y2] which maps back to X (in standard precision, with 53-bit mantissa). Then choose such Y from [Y1, Y2] that Y has the shortest decimal representation.
Re: 0.30000000000000004
#25It'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. In a way, not so simple (obvious to you? not to me)
Re: 0.30000000000000004
#26Any time you're generating percentage data that should sum to 100, not appreciating floating point math will burn you. For those interested, the largest remainder method ( https://gist.github.com/hijonathan/e597addcc327c9bd017c ) is useful for dealing with this.
Re: 0.30000000000000004
#27>Perl 6, unlike Perl 5, uses rationals by default I'm not sure this is such a good idea. I love rational datatype, but it's too easy to shoot yourself in the foot with simple numerical procedures resulting in gigantic bignum denominators.
Any time there’s any degree of uncertainty about a quantity (e.g. it comes from a physical measurement) there’s also no longer any advantage to using rational arithmetic. This turns out to encompass most practical situations.
Rational arithmetic also breaks down entirely in the face of square roots or trig functions, unless you go for a fully symbolic computation environment, which gets even much slower.
Rational arithmetic is mostly nice when the problems have been carefully chosen so the operations will stay rational and the answers will work out nicely, e.g. in high school homework.
Re: 0.30000000000000004
#28Re: 0.30000000000000004
#29Once I wrote a library for double-to-string conversion and vice versa, which handles such roundings nicely: https://github.com/mkupchik/dconvstr Key idea is not just to map binary floating point value X to a decimal floating point value Y, but instead (in extended precision, with 64-bit mantissa) compute an interval of decimal floating point values [Y1, Y2] which maps back to X (in standard precision, with 53-bit man…
Re: 0.30000000000000004
#30It'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. In a way, not so simple (obvious to you? not to me)
10^d*n = 10^d*p/q
so 10^d*p must be divisible by q. Since p and q are relatively prime, 10^d must be divible by q. That's only possible if all prime factors of q are 2 or 5.