• 11-11-2003
andreasb
I am writing code that deals with very small numbers. I am having problems with these small numbers getting set to zero. I am using gcc in RedHat 9. For example, if I declare x to be a long double, and I then say

x = pow(10, -400)

I get that my program thinks x is 0. The magic exponent at which x is set to zero appears to be -325. Additionally, if I say
x = pow(10,-324)

I get x to be equal to about 9.88E-324. I have roughly the same problem with the exp() function. I've tried setting LDBL_MIN_EXP and LDBL_MIN_10_EXP, but it doesn seem to work. Does anyone know what is going on? What am I doing wrong, or what am I not doing? Do I have to recompile something (besides my program) after I set LDBL_MIN_EXP or LDBL_MIN_10_EXP?

Andreas
• 11-11-2003
bennyandthejets
The size of a double is limiting the precision you can attain. You may just have to accept that it is not possible to store a value that low.

However, what you could do, is create your own class/structure that stores scientific notation:
Code:

```class Number { public:     double num1; //first part: 3.45     double num2; //second part: -400     //and a bunch of custom operators };```
This would equate to 3.45*10^-400. This may be a possible way to store really small or really large numbers. You would have to create a few operators to deal with this abnormal numerical type, but it shouldn't be too hard.

If you were to indicate the purpose of doing this, perhaps a better solution could be found.
• 11-11-2003
Salem
> I've tried setting LDBL_MIN_EXP and LDBL_MIN_10_EXP
They're read-only, you can't change them (unless you're actually writing the run-time support yourself)

Either do as Benny suggests and write your own custom class, or use an existing package like http://www.swox.com/gmp/
• 11-11-2003
andreasb
RH 9 gcc -- exponentially small numbers getting set to zero
Thanks bennyandthejets and Salem,
Since bennyandthejets asked, I am trying to numerically integrate a function that involves a sensitive exponential. The exponential function looks like

exp(-a/(T(1-T^4)^2)

Here 'a' is a relatively large number and 'T' varies from 0 to 1. If you are curious, I am looking at how the universe goes through a first-order phase transition. The exponential describes how many bubbles (of protons and neutrons) form in the universe as it cools. The 'T' in the above equation is a dimensionless temperature. These bubbles then grow as the universe evolves. So, what started out as an extremely small bubble can grow to macroscopic sizes. Therefore, I need to keep exponentially small numbers.

I've looked briefly at what you both suggest. I'm not sure which one will be best for me at this point. I'll give try one and then get back to you.