Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Perl 5 numeric type and simplifications

by haukex (Bishop)
on May 05, 2021 at 05:41 UTC ( #11132053=note: print w/replies, xml ) Need Help??

in reply to Perl 5 numeric type and simplifications

I'm interested in knowing if this is always the case (can I rely on this behaviour of simplifying the number?)

The Perl Cookbook says "When Perl is told to print a floating-point number but not told the precision, it automatically rounds that number to however many decimal digits of precision that your machine supports." So when you state the question so generally, then I would say that I wouldn't rely on it, and I would use e.g. int or sprintf (or, if you wanted to trade precision for performance, bignum). See also What Every Programmer Should Know About Floating-Point Arithmetic.

  • Comment on Re: Perl 5 numeric type and simplifications

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11132053]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2021-09-23 00:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found