Re: floating point inaccuracies when compiling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is the behaviour I'd expect.

The 1.0e-10 is being represented as a double-precision floating point value. Not all values can be represented exactly, and in this case the machine picks the closest value to 1.0e-10 that it can represent.

Double precision generally provides 15 significant figures of precision; as you can see, the value chosen by the machine is precise to that point.

If you really need your computations to have greater precision, in spite of any performance penalty, you might like to consider the GMP library:

  http://www.swox.com/gmp/

Neil.

Florian Hackenberger wrote:
Hi!

I'm using gcc 3.4.3-20050110 compiled with flags "-O2 -march=i686 -pipe" for C and C++. When compiling expressions like the following

Array2D< double > numerical_damper = pow(local_model.sum_e_upd2 / (local_model.sum_e_cv2 + 1.0e-10 ), 4);

I noticed, that the values used for 1.0e-10 are not really 1.0e-10. To visualise that, I forced gcc to produce an error message:

./rfwr.cpp: In member function `void Rfwr::updateCovTriangular(const TNT::Array2D<double>&, const TNT::Array2D<double>&, LocalModel&, const TNT::Array2D<double>&)': ./rfwr.cpp:251: error: no match for 'operator+' in 'local_model->LocalModel::sum_e_cv2 + 1.0000000000000000364321973154977415791655470656e-10'

Is this behaviour as expected, or is there something wrong with my installation?

Thanks in advance!

Regards,
	Florian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux