Skip to main content
GameDev.net gamedev.net
🔒 Locked

Just something I noticed with DOUBLE_MIN

Started by Muzzy A Jun 6, 2013 at 10:28 PM 3 replies 2.1k views
Original Post
Muzzy A
Muzzy A
I was just testing the how many decimal places a double is accurate up to when doing calculations, and I noticed i was getting results that were smaller than DBL_MIN.
So why would they make DBL_MIN actually ALOT bigger than the actual DBL_MIN?
Double Min: 2.22507e-308
My Value: 9.88131e-324
Paradigm Shifter
Paradigm Shifter

DBL_MIN is the smallest possible normalized double, you can have denormalized doubles as well.


Since the smallest exponent is -1022, the smallest positive normalized number is 1.0 × 2-1022 ? 2.2 × 10-308. In C, this is defined as DBL_MIN. However, it is not the smallest positive number representable as a floating point number, only the smallest normalized floating point number. Smaller numbers can be expressed in denormalized form, albeit at a loss of significance. The smallest denormalized positive number occurs with f has 51 0?s followed by a single 1. This corresponds to 2-52*2-1022 = 2-1074 ? 4.9 × 10-324. Attempts to represent any smaller number must underflow to zero.

http://www.johndcook.com/blog/2009/04/06/anatomy-of-a-floating-point-number/

EDIT: And read this too http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
frob
frob

It is floating point math, so it can get complicated.

DBL_MIN is the minimum positive normalized value.

Your number is less than DBL_MIN, so it means your number is denormalized.

Denormal numbers are a special case in floating point numbers. They are very slow to process, and are only meaningful in exceptionally rare cases. In almost every case they are just a byproduct of rounding error.

If your number is between DBL_MIN and 0 then it is almost certainly just a result of rounding error. Round it to zero.

Also, consider what the number means. 9.88131e-324 is tiny. It is 0.0000000...[324 zeros total]...00098131. That is unfathomably close to zero.

For reference, consider the Plank length is the smallest meaningful distance measurement of the Universe. The entire Universe is only about 4.4e26 meters. That means the ratio of the entire Universe to the smallest meaningful distance is on the order of 10e-61 units, or about 0.000...[61 zeros total]...0001 units.

Anything smaller than e-61 is small enough even physics says it probably doesn't exist.

Anything smaller than DBL_MIN is small enough to be rounded to zero.

Muzzy A
Muzzy A

Thanks for replying, I find things like this interesting, so I'm always testing them lol.

@frob: My astronomy > Your astronomy ;). Jk lol

rnlf_in_space
rnlf_in_space

Just as a side-note: In C++, you better use std::numeric_limits::min() from instead of DBL_MIN. It is better readable and can be used in template code where you don't know the exact floating point type for which you want to know the limits at the time of writing the code.

It also has denorm_min() which gives you the very smallest possible denormalized value. (As does DBL_TRUE_MIN, stupid name ;-))

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.