# Thread: problems with sqrt function

1. ## problems with sqrt function

Dear All,

I am terribly confused by something at the moment. If anyone could tell me what they think the problem is that would be great.

Code:
```#include<stdio.h>
#include<math.h>

int main()
{
double a=(sqrt(4*M_PI*M_PI+1)/2),b=(sqrt(M_PI*M_PI+1/4));

printf("a=%f\t\tb=%f",a,b);

return(0);
}```
As you can easily tell mathematically my definitions of a and b are identical. However when one runs the program a has the correct value stored, but b has the value M_PI.

Thank you for all of your time.
Edz 2. This is because this is computers, not mathematics!

C believes that 1/4 == 0, since it does integer division when dividing integers. 3. 1/4 = 0. 4. try this way
Code:
`    double a=(sqrt(4.0*M_PI*M_PI+1.0)/2.0),b=(sqrt(M_PI*M_PI+1.0/4.0));`
Kurt 5. Thank you all 6. you can also type cast by using the data type a constant is referring to..

like:
int(1.0)=1
float(1)=1.0 7. M_PI is nonstandard, although GCC's <math.h> has it. For portability, use something like
Code:
`  const double Pi = 4.*atan(1.);` ```#ifndef M_PI Popular pages Recent additions 