in reply to Re: Rounding error?
in thread Rounding error?
"The (probable) reason that you see a different result from C, is that you are (probably) using single precision (floats) in your C code, whilst Perl uses double precision. (Probably:)"
This seems to be a good guess:
#include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { { double a = 40.88050; printf("%.3f\n",a); printf("%.17f\n",a); a = 41.78050; printf("%.3f\n",a); printf("%.17f\n",a); } { float a = 40.88050; printf("%.3f\n",a); printf("%.17f\n",a); a = 41.78050; printf("%.3f\n",a); printf("%.17f\n",a); } return 0; }
Prints:
40.880 40.88049999999999784 41.781 41.78050000000000352 40.881 40.88050079345703125 41.780 41.78049850463867188
|
|---|