View previous topic :: View next topic |
Author |
Message |
slott_hansen n00b
Joined: 03 Feb 2003 Posts: 40 Location: Denmark, Copenhagen
|
Posted: Sat Mar 01, 2003 9:09 am Post subject: PHP is making wrong calculations |
|
|
I just discovered something terrible on my live server - PHP cant perform correct calculations!!!!
echo sprintf('%.2f', '8.7586206896551724');
is printed as 10.00
On my home server everything is fine and dandy but online everything goes wrong!
The live server is a pentium4 if that could influence anythning and I'm using the AC kernel.
Am I missing a setting for my kernel ? _________________ Best regards,
Morten Slott Hansen |
|
Back to top |
|
|
chatgris Guru
Joined: 14 Oct 2002 Posts: 383 Location: Canada
|
Posted: Fri Mar 28, 2003 6:07 am Post subject: |
|
|
I have the same problem!!! _________________ Open your mind. Open your source.
Due credit for avatar from http://www.aikida.net |
|
Back to top |
|
|
chatgris Guru
Joined: 14 Oct 2002 Posts: 383 Location: Canada
|
Posted: Fri Mar 28, 2003 4:04 pm Post subject: |
|
|
To add a bit more information, I am also using a Pentium 4 and it doesn't work, it works on my athlon though.. I was using a gentoo-sources kernel but I'm reinstalling from scratch and I'm going to try and use a vanilla-sources kernel..
I really hope this works... if anyone has ANY idea of what could possibly be causing this problem I'd love to know..
In addition,
echo sprintf( "%.2f", 10.75 );
returns 0 so it's nto a string to float conversion problem. _________________ Open your mind. Open your source.
Due credit for avatar from http://www.aikida.net |
|
Back to top |
|
|
avendesora Veteran
Joined: 16 Aug 2002 Posts: 1739 Location: Betelgeuse vicinity
|
Posted: Fri Mar 28, 2003 5:43 pm Post subject: |
|
|
Does the same thing work in plain C or Perl?
How aggressive are the CFLAGS you used to build PHP? |
|
Back to top |
|
|
chatgris Guru
Joined: 14 Oct 2002 Posts: 383 Location: Canada
|
Posted: Fri Mar 28, 2003 5:49 pm Post subject: |
|
|
The same thing works in C... it's really weird.. However, after a lot of noise making on the php-bugs list, I got this response
Quote: | This is most likely being caused by over-optimization when
compiling. I had a similar problem on my gentoo box, and
the problem was traced back to over-optimizing when
compiling glibc. (var_dump() was printing some weird
floats, and I believe this problem is similar, as both use
modf() at some point.)
Basically, tone down the optimizations a bit. If you
compile glibc with CFLAGS along the lines of
"-march=pentium4 -O3...", modf() starts dying. The
solution (for gentoo, at least) is to modify your USE flag
in make.conf to use -march=pentium3 if you're using
pentium4 and re-emerge glibc, then recompile PHP.
gcc has problems with march pentium4 spitting out bad
instructions, so you should stay away from it, even if
you're actually on a Pentium 4. Use march=pentium3 or
mcpu=i686 instead. There are threads on the gentoo forums
about this, and newer versions of portage mention it in
the make.conf comments.
If this is indeed the problem, it affects python, too,
fwiw.
J |
I'm going to recompile my entire system with mcpu=i686 and hope for the best.
I'll report on my progress in case anyone else has this hair-pulling problem
Josh. _________________ Open your mind. Open your source.
Due credit for avatar from http://www.aikida.net |
|
Back to top |
|
|
avendesora Veteran
Joined: 16 Aug 2002 Posts: 1739 Location: Betelgeuse vicinity
|
Posted: Fri Mar 28, 2003 6:00 pm Post subject: |
|
|
If it helps any, I'm on a P4 and have built my system with
CFLAGS="-march=i686 -O3", and it doesn't appear to be
misbehaving. |
|
Back to top |
|
|
chatgris Guru
Joined: 14 Oct 2002 Posts: 383 Location: Canada
|
Posted: Fri Mar 28, 2003 6:08 pm Post subject: |
|
|
Oh I didn't know you could do march=i686..
thanks I'm gonna restart everything with those flags. _________________ Open your mind. Open your source.
Due credit for avatar from http://www.aikida.net |
|
Back to top |
|
|
avendesora Veteran
Joined: 16 Aug 2002 Posts: 1739 Location: Betelgeuse vicinity
|
Posted: Fri Mar 28, 2003 6:11 pm Post subject: |
|
|
Also, this currently active thread might help you out a bunch. |
|
Back to top |
|
|
chatgris Guru
Joined: 14 Oct 2002 Posts: 383 Location: Canada
|
Posted: Sat Mar 29, 2003 6:07 pm Post subject: |
|
|
Thanks, I'd been reading that thread and this thread at the same time..
The problem has been fixed now... I compiled with mcpu=pentium4
CFLAGS="-mcpu=pentium4 -O2 -pipe -fomit-frame-pointer"
INSTEAD OF
CFLAGS="-march=pentium4 -O2 -pipe -fomit-frame-pointer"
and it's all working nicely for me.. *phew*. _________________ Open your mind. Open your source.
Due credit for avatar from http://www.aikida.net |
|
Back to top |
|
|
wick n00b
Joined: 27 Mar 2003 Posts: 35
|
Posted: Sun Mar 30, 2003 12:56 am Post subject: |
|
|
According to make.conf:
Quote: |
PENTIUM 4 will generate invalid instructions; use 'pentium3' instead.
|
Just be cautious in your new build. If you see any bizarre results in any of the PHP modules, rebuild with -march=pentium3. I built my whole P4 system with -march=pentium3 specifically because of the P4 warnings.
[/quote] |
|
Back to top |
|
|
|