Messages in this thread | | | Date | Wed, 17 Apr 2002 10:26:03 -0400 (EDT) | From | "Richard B. Johnson" <> | Subject | Re: FPU, i386 |
| |
On Wed, 17 Apr 2002, Andrey Ulanov wrote:
> Look at this: > > $ cat test.c > #include <stdio.h> > > main() > { > double h = 0.2; > > if(1/h == 5.0) > printf("1/h == 5.0\n"); > > if(1/h < 5.0) > printf("1/h < 5.0\n"); > return 0; > } > $ gcc test.c > $ ./a.out > 1/h < 5.0 > $ > > I also ran same a.out under FreeBSD. It says "1/h == 5.0". > It seems there is difference somewhere in FPU > initialization code. And I think it should be fixed. >
No. No. No. Read something about basic programming of floating-point operations before complaining about something you obviously know nothing about. "==" has no use in floating-point operations. Any code that uses "==", referencing floating-point numbers is broken.
If the BSD 'C' runtime library fortuously says that 1.0/0.2 == 5, than you just got lucky. Time to play the lottery. FYI, you can set the per-process FPU initialization anyway you want. FYI, by default it ignores 1/0 errors:
Cheers, Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Windows-2000/Professional isn't. /* * Note FPU control only exists per process. Therefore, you have * to set up the FPU before you use it in any program. */ #include <i386/fpu_control.h>
#define FPU_MASK (_FPU_MASK_IM |\ _FPU_MASK_DM |\ _FPU_MASK_ZM |\ _FPU_MASK_OM |\ _FPU_MASK_UM |\ _FPU_MASK_PM)
void fpu() { __setfpucw(_FPU_DEFAULT & ~FPU_MASK); }
main() { double zero=0.0; double one=1.0; fpu();
one /=zero; }
| |