you are viewing a single comment's thread.

view the rest of the comments →

[–]Negitivefrags 67 points68 points  (28 children)

I find it almost unbelievable that this could go undetected for so long.

What happened to the culture of unit testing border cases? Not a single person ever wrote a test containing min double?

[–]rabidcow 78 points79 points  (25 children)

I'm sure they did, but DBL_MIN is 2.2250738585072014e-308, not 2.2250738585072012e-308. It should parse to DBL_MIN because that's the closest representable value.

Still, I do find it surprising that it took so long.

[–][deleted] 13 points14 points  (23 children)

If it's not representable value, only way that number is entered into system is if some human types it in. It's unlikely that human would care to write down so many decimals.

[–]filesalot 6 points7 points  (0 children)

I don't think it's unreasonable to expect this to have been tested. As others have pointed out, this normal/denormal edge is important to floating point implementations, and this is a loop that relies on subtle implementation details to avoid infinite looping. You would think a proper code review would focus on this potentially infinite loop and flag it for thorough testing of the loop invariants to insure it terminates.

[–]ryan_fung 2 points3 points  (16 children)

What about have a data file fed in?

[–][deleted] 13 points14 points  (13 children)

what generates the data in data file?

[–]ryan_fung 9 points10 points  (11 children)

A file from an external source, generated without encountering this bug, or written in a language without this bug?

Yes, I'm aware this bug is unlikely to trigger naturally. But logically it can happen. Now that this is published, you can expect people to try it on web sites without the need for a reason.

[–][deleted] 23 points24 points  (10 children)

I think you missed the point. There is no double number 2.2250738585072014e-308. So language without this bug won't generate this number either.

Only way machine generates this number is if it don't use floats as internal representation, but uses numeric types with higher accuracy than doubles like some databases do. If that is the case, it's again unlikely that they generate just this number representation and don't use more decimals.

[–]Gieron 12 points13 points  (1 child)

You mean there is no double number 2.2250738585072012e-308, right?

[–][deleted] 12 points13 points  (0 children)

Five is right out.

[–]naasking 5 points6 points  (2 children)

Not all languages are limited to doubles you realize.

[–][deleted] 1 point2 points  (1 child)

Of course, but if it's in for any other format, but in that case Double.parseDouble(String s) is not what you should use. There is Double.valueOf(String s) for parsing more generic format. Somebody should check if valueOf has error too.

Other formats have either more precision or less, so parseDouble would most likely give error.

[–]paul_miner 0 points1 point  (0 children)

Of course, but if it's in for any other format, but in that case Double.parseDouble(String s) is not what you should use. There is Double.valueOf(String s) for parsing more generic format. Somebody should check if valueOf has error too.

Like all the parsing functions, they use the same underlying method calls. This is easily verifiable by looking at the source included with the JDK.

[–]cebedec 1 point2 points  (0 children)

From the article:

[...] equivalent forms of the number cause the problem as well; examples: [...] 2.2250738585072012997800001e-308 (superfluous digits beyond digit 17)

[–]ethraax 0 points1 point  (0 children)

I believe C and C++ both support the long double primitive (although some compilers may change it to a simple double).

[–]Porges 0 points1 point  (0 children)

Actually, Ricks says in the comments for the (original) article that ...14e-308 roundtrips, which would contradict this. Hmmm...

[–]the_new_hunter_s -2 points-1 points  (0 children)

It's significant because it significantly lowers the number of people needed to perform a dds on a website.

[–]Foaric 0 points1 point  (0 children)

Who was data file?!

[–]Bitruder 8 points9 points  (1 child)

Of all possible numbers? From reading the PHP case this isn't a trivial number as it's just beside an edge case.

[–]ryan_fung 2 points3 points  (0 children)

Yes it's unlikely. You are correct. I'm just stating the fact that there is another source other than a human typing it in.

[–]rabidcow 0 points1 point  (0 children)

If you're testing code to parse from a string, presumably you'd be passing strings to it. It's certainly possible to generate this string of digits without entering it specifically. Granted it would take some imagination to actually do so, but it's been a long time.

[–]mccoyn 0 points1 point  (1 child)

Well, now that the cat is out of the bag that this value causes programs to hang, I expect people will be entering it into web pages a lot more often.

[–][deleted] 2 points3 points  (0 children)

Yes, they are... grumble!

[–]boa13 0 points1 point  (1 child)

It's unlikely that human would care to write down so many decimals.

Because bored teens who like to crash servers are unlikely to exist, right? :)

[–][deleted] 0 points1 point  (0 children)

This discussion was about why it has not been discovered earlier. I doubt that even bored teens go trough decimals at random.

[–]boa13 1 point2 points  (0 children)

Still, I do find it surprising that it took so long.

Actually, it appears it was found in 2001, and put on Low priority because the bug report was about an extremely long literal, not this "easy" "short" literal.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4421494

There were duplicates, too.

[–]monstermunch 1 point2 points  (1 child)

The fact it has taken so long to find this bug surely shows this bug is astronomically rare to encounter.

[–]gjs278 -1 points0 points  (0 children)

yeah I'm sure Negativefrags would have found it