# Thread: Assigning values to double vars

1. ## Assigning values to double vars

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

2. Post the code showing what it is you are trying to do and the unexpected results you receive.

3. 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() ;```
But to put it more generally .What precision do double vars handle ??

4. 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.

5. Originally Posted by Levia8an
What precision do double vars handle ??
It varies.
http://c-faq.com/fp/fpequal.html

6. 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.

7. 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/

8. 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 */```
So it can't be much of a help

The gmp library has very cool stuf.Thanx