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

- 11-22-2006Levia8anAssigning values to double vars
Hi everyone,

Is there any way that i could assign a large amount of decimal parts to a double variable?

Thx in advance - 11-22-2006Dave_Sinkula
Post the code showing what it is you are trying to do and the unexpected results you receive.

- 11-22-2006Levia8an
Well ok,

This is actually an issue that arose when i was trying to compare 2 doubles.For example

Code:

double lim = 1.0000000000000000001 ;

double res = 0.0 ;

/*later on */

res = some_calculation( ) ;

if( res < lim )

do_some_work() ;

else

do_something_else() ;

- 11-22-2006quzah
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. - 11-22-2006Dave_SinkulaQuote:

Originally Posted by**Levia8an**

http://c-faq.com/fp/fpequal.html - 11-23-2006Levia8an
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. - 11-23-2006Salem
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/ - 11-23-2006Levia8an
in microsoft visual studio 98 platform.

Code:`/*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