Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2021-07-28 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?