Emmanuel Arias
Emmanuel Arias

Reputation: 484

Python3 and C different math division result

I have a simple number division. I have this two number:

So, if I do the division on C:

// ...
float ii = 39.654;
double bb = 8.381903173E-8;
printf("\n%.20f\n", ii/bb);
// ... 

The output is: 473090639.56200009584426879883

But, if I work on Python3:

39.654/8.381903173E-8

The output is: 473090647.5719557

If I use a calculator, indeed, the true value is that of Python3

What is wrong with my C code?

Thanks! Regards!

Upvotes: 1

Views: 89

Answers (1)

DYZ
DYZ

Reputation: 57033

You must compare apples to apples. In Python, all floating-point variables are of type double, so you should use the same data type in your C program:

double ii = 39.654;
double bb = 8.381903173E-8;
printf("\n%.20f\n", ii/bb);

Upvotes: 9

Related Questions