I'm new here... Being a former C++ programmer I started off
with PERL a year ago and I really like it now,
even though I didn't in the beginning.
Very well, One of these days I got really confused about
how PERL treats floats. If i write the simple code:
#!/usr/bin/perl -w
#============= START PROGRAM ========================
$p_R = .1;<BR>
for( $Go_R = 0.0; $Go_R < 7; $Go_R += $p_R)
{#------------------------------------ FOR $Go_R
print "Go_R = $Go_R\n";<BR>
}#-------------------------------- END FOR $Go_R
#=============== END PROGRAM ========================
I will get the "ending" output:
...
Go_R = 5.8
Go_R = 5.9
Go_R = 5.99999999999999
Go_R = 6.09999999999999
Go_R = 6.19999999999999
Go_R = 6.29999999999999
Go_R = 6.39999999999999
Go_R = 6.49999999999999
Go_R = 6.59999999999999
Go_R = 6.69999999999999
Go_R = 6.79999999999999
Go_R = 6.89999999999999
Go_R = 6.99999999999999
That is, I get a roundoff error VERY soon.
Why is that. This doesn't happen if I write the same kind of code in C++...
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.