Bug #79595 [NEW]: zend_init_fpu() alters FPU precision
From: v-yitam at microsoft dot com
Operating system: Alpine Linux
PHP version: 7.4.5
Package: Math related
Bug Type: Bug
Bug description:zend_init_fpu() alters FPU precision
Description:
------------
A PHP extension which depends on the FPU precision being the default of
the ABI (80 bit) will produce subtly incorrect results with floating
point number.
In particular, it breaks any musl libc-linked binaries that use floating
point strtod(). In Alpine Linux, musl's strtod
(https://git.musl-libc.org/cgit/musl/tree/src/internal/floatscan.c)
depends on long double, which requires FPU set to 80-bit precision to
actually work
To illustrate, I wrote two simple test scripts (one cpp and one php),
using the example provided in a similar issue
(https://github.com/microsoft/WSL/issues/830):
The output from the test program: 1.00000000000000000e-05
The output from running php: 1.00000000000000008e-5
Please see below.
Test script:
---------------
alpine:~$ more test_print.cpp
#include <stdio.h>
int main()
{
long double n = 1;
printf("%.17Le\n", n / 100000);
}
alpine:~$ g++ -std=c++11 -static -o test_print test_print.cpp
alpine:~$ ./test_print
1.00000000000000000e-05
alpine:~$ more test_print.cpp
#include <stdio.h>
int main()
{
long double n = 1;
printf("%.17Le\n", n / 100000);
}
alpine:~$ g++ -std=c++11 -static -o test_print test_print.cpp
alpine:~$ ./test_print
1.00000000000000000e-05
alpine:~$ more test_print.php
<?php
$n = 1;
printf("%.17e\n", 1/100000);
?>
alpine:~$ php test_print.php
1.00000000000000008e-5
Expected result:
----------------
FPU precision should not be changed
Actual result:
--------------
Have to save/restore FPU state and force it back to 80-bit
--
Edit bug report at https://bugs.php.net/bug.php?id=79595&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79595&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79595&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79595&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79595&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79595&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79595&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79595&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79595&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79595&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79595&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79595&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79595&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79595&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79595&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79595&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79595&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79595&r=mysqlcfg
Thread (21 messages)
- v-yitam at microsoft dot com
- v-yitam at microsoft dot comBug #79595 [Opn]: zend_init_fpu() alters FPU precision
- cmb@php.netBug #79595 [Opn]: zend_init_fpu() alters FPU precision
- v-yitam at microsoft dot comBug #79595 [Opn]: zend_init_fpu() alters FPU precision
- nikic@php.netBug #79595 [Opn]: zend_init_fpu() alters FPU precision
- v-yitam at microsoft dot comBug #79595 [Opn]: zend_init_fpu() alters FPU precision
- cmb@php.netBug #79595 [Opn]: zend_init_fpu() alters FPU precision
- v-yitam at microsoft dot comBug #79595 [Opn]: zend_init_fpu() alters FPU precision
- v-yitam at microsoft dot comBug #79595 [Opn]: zend_init_fpu() alters FPU precision
- cmb@php.netBug #79595 [PATCH]: zend_init_fpu() alters FPU precision
- cmb@php.netBug #79595 [Asn->Csd]: zend_init_fpu() alters FPU precision
- cmb@php.netBug #79595 [Csd]: zend_init_fpu() alters FPU precision
- cmb@php.netBug #79595 [PATCH]: zend_init_fpu() alters FPU precision
- cmb@php.netBug #79595 [Csd->ReO]: zend_init_fpu() alters FPU precision
- v-yitam at microsoft dot comBug #79595 [ReO]: zend_init_fpu() alters FPU precision
- cmb@php.netBug #79595 [ReO]: zend_init_fpu() alters FPU precision
- cmb@php.netBug #79595 [ReO->Csd]: zend_init_fpu() alters FPU precision
- cmb@php.netBug #79595 [Csd]: zend_init_fpu() alters FPU precision
- v-yitam at microsoft dot comBug #79595 [Csd]: zend_init_fpu() alters FPU precision
- bugdal at aerifal dot cxBug #79595 [Com]: zend_init_fpu() alters FPU precision
- nikic@php.netBug #79595 [Csd]: zend_init_fpu() alters FPU precision