[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

re: [MacPerl] Basic question from a raw recruit



"Darin S. Morley" <dmorley@std.saic.com> writes
} >} Now, a friend, who is an experienced programmer, but who doesn't know 
} >} Perl, says it is because Perl is treating the number like an integer 
} >} instead of a floating point number (probably because it IS an integer, 
} >} having no decimal remainder).
} >
} >But Perl works very much like C (or Fortran for that matter) in these
} >cases.  It sees that 1.07 is a float, so it knows it has to promote
} >$gross to float to do the division properly no matter what it contains.
} 
} i thought Perl did *all* of its math in double precision. i know i've 
} seen Larry post to that effect on c.l.p.*, but i can't seem to find that 
} explicitly stated in the docs anywhere. i did find this from the 
} description of pack() in the perlfunc man page:

If Larry Wall says it, then it must be true.  I stand corrected and
enlightened.  I was basing my statement on what's written in the perlop
page (I'd characterize both C and Fortran as doing "most" numerical
computations in float), and the behavior I've seen in Perl while using
it.

} 
} "Note that Perl uses doubles internally for all numeric calculation, and 
} converting from double into float and thence back to double again will 
} lose precision (i.e. unpack("f", pack("f", $foo)) will not ingeneral 
} equal $foo)."
} 
} and this footnote on page 65 of the Camel book:
} 
} "Perl stores numbers as double-precision floating-point values in the 
} machine's native format."
} 
} --
} Darin S. Morley
} dmorley@stow.com
} http://www.stow.com/
} 
} 
---
--------
Paul J. Schinder
NASA Goddard Space Flight Center,
Code 693, Greenbelt, MD 20771 USA
schinder@pjstoaster.pg.md.us