"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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.