0
double P = 3.5/(.1 * sqrt(2.0*3.14159)) * exp(-pow(5.0,2) / (2.0*pow(.1,2)));
	cout << P << endl;
	if (P==0)
		cout << "P is zero!" << endl;

Is this underflowing so it is getting rounded to zero? The problem is that I am taking the log of this, so if it is zero it breaks everything because it is -inf instead of a normal double. Is there a way to prevent this?

Thanks,

Dave

4
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Rashakil Fol
0
double P = 3.5/(.1 * sqrt(2.0*3.14159)) * exp(-pow(5.0,2) / (2.0*pow(.1,2)));
	cout << P << endl;
	if (P==0)
		cout << "P is zero!" << endl;

Is this underflowing so it is getting rounded to zero? The problem is that I am taking the log of this, so if it is zero it breaks everything because it is -inf instead of a normal double. Is there a way to prevent this?

Thanks,

Dave

You are raising e to the -1125th power. That's below 10 to the -308th power, which is the bare minimum of what a double can hold before rounding to 0. You may need to use an arbitrary precision data type instead.

0

You may want to implement your own Double Class (which will hold data as a string internally)

Or how about a better representation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.