Live data from Hacker News

0.30000000000000004

0.30000000000000004.com

11–20 of 140 posts

Re: 0.30000000000000004

#12

Why does PHP produce 0.3 instead? edit: Not sure how I missed that. Thanks!

Third example in the article:

PHP converts 0.30000000000000004 to a string and shortens it to "0.3". To achieve the desired floating point result, adjust the precision ini setting: ini_set("precision", 17).

I remember years ago learning something like this and coming to a horrible realization : "My god, they're all strings!"

Re: 0.30000000000000004

#14
post #6

Rexx has decimal arithmetics so 0.1+0.2 is 0.3 ... http://www.rexxla.org/events/2001/mike/rexxsy01.PDF

Unsurprising considering the IBM affiliation of Rexx and decimal arithmetic being IBM’s pet issue.

Re: 0.30000000000000004

#15
post #9
post #4

Previous 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)

Someone should figure out the mean length of time between article repeats on HN. And then find some correlation with university degrees and job tenure.

[deleted]

Re: 0.30000000000000004

#16

Any 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.

Using tricks to make numbers total what you think they "should" other than using rounding to proper amount of precision is lazy and deceitful.

Re: 0.30000000000000004

#17
post #4

Previous 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)?

Re: 0.30000000000000004

#18
>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.

Re: 0.30000000000000004

#20
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.

In a way, not so simple (obvious to you? not to me)

Post reply on HN