Hi everyone,
Is there any way that i could assign a large amount of decimal parts to a double variable?
Thx in advance
Printable View
Hi everyone,
Is there any way that i could assign a large amount of decimal parts to a double variable?
Thx in advance
Post the code showing what it is you are trying to do and the unexpected results you receive.
Well ok,
This is actually an issue that arose when i was trying to compare 2 doubles.For example
But to put it more generally .What precision do double vars handle ??Code:
double lim = 1.0000000000000000001 ;
double res = 0.0 ;
/*later on */
res = some_calculation( ) ;
if( res < lim )
do_some_work() ;
else
do_something_else() ;
All floating point number as inaccurate. You'll want to use something like abs to compare them. Search the forum for something like floating point accuracy and you should get plenty on the topic.
Quzah.
It varies.Quote:
Originally Posted by Levia8an
http://c-faq.com/fp/fpequal.html
Hmmm ,
After searching a bit with google , it seems that the precision is defined in float.h . In that case
the number of decimal parts a double can handle is 15 ( system dependent ). Well the question now is how can i hanlde floating point constants of about ,let's say, 20 decimal parts.
To be more specific in the code i posted previously i assumed that the
" res < lim " comparison will depend on the 15 first decimal parts .Is that right?If yes is there a way i could work around this problem?
P.S Thank you Dave_Sinkula , quzah for responding.
Well there's long double, but that doesn't buy much in terms of precision (most of it goes on the exponent).
Failing that, you need a maths library like GMP
http://www.swox.com/gmp/
in microsoft visual studio 98 platform.
So it can't be much of a helpCode:/*float.h*/
#define DBL_DIG 15 /* # of decimal digits of precision */
/*...*/
#define LDBL_DIG 18 /* # of decimal digits of precision */
The gmp library has very cool stuf.Thanx