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

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.

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

Or how about a better representation.

This article has been dead for over six months. Start a new discussion instead.