Why do PHP float division and POW give wrong results and unexpected results?

Does anyone know why this is happening and whether it can be fixed. I compare the results with C and PHP, but PHP gives me different results.

I can provide some code if necessary, but has anyone experienced this before?

thank

Php code

$ tempnum = 1.0e - 5 * -44954; // substr ($ line1,53,6);
$ bstar = $ tempnum / pow (10.0, 3);

$ bstar gives me -0.00044954 in PHP but it should be -0.000450

C code

double tempnum = 1.0e - 5 * -44954;
double bstar = tempnum / pow (10.0, 3);

printf bstar gives me -0.000450

Thanks for your answers so far, but how does PHP come to this conclusion ...

$ twopi = 6.28318530717958623; / * 2 * Pi * /
$ xmnpda = 1440; //1.44E3; / * Minutes per day * /

$ temp = (($ twopi / $ xmnpda) / $ xmnpda);

$xndt2o = -0.000603;
$xndt2o = $xndt2o * $temp;

echo $xndt2o gives me -1.8256568188E-9 in PHP but in C it gives me -0.000000

, PHP.

+3
3

, . , , . .

, , , , . ..

, , , PHP- - 32- float-, 6-/7- , , 32- .

+3

C , printf :

printf("%.8f\n", bstar);
+2

. .

PHP. , 32- , 64- BIGINT.

, 64- PHP. , , 64- , . , PHP , 64- . 52 , 2 ^ 53-1 . 53 , .

, .

Float to string PHP. , , float ( 32- , 32- int float) , , . sprintf(), , , "" PHP : int; ; .

- MySQL

0

Source: https://habr.com/ru/post/1787351/


All Articles