Website hosting service by Active-Venture.com
  

 Back to Index

Numerical Traps

Perl4-to-Perl5 traps having to do with numerical operators, operands, or output from same.

* Numerical

Formatted output and significant digits. In general, Perl 5 tries to be more precise. For example, on a Solaris Sparc:

 
    print 7.373504 - 0, "\n";
    printf "-.18f\n", 7.373504 - 0;

    # Perl4 prints:
    7.3750399999999996141
    7.375039999999999614

    # Perl5 prints:
    7.373504
    7.375039999999999614  

Notice how the first result looks better in Perl 5.

Your results may vary, since your floating point formatting routines and even floating point format may be slightly different.

* Numerical

This specific item has been deleted. It demonstrated how the auto-increment operator would not catch when a number went over the signed int limit. Fixed in version 5.003_04. But always be wary when using large integers. If in doubt:

 
   use Math::BigInt;  

* Numerical

Assignment of return values from numeric equality tests does not work in perl5 when the test evaluates to false (0). Logical tests now return a null, instead of 0

 
    $p = ($test == 1);
    print $p,"\n";

    # perl4 prints: 0
    # perl5 prints:  

Also see "General Regular Expression Traps using s///, etc." for another example of this new feature...

* Bitwise string ops

When bitwise operators which can operate upon either numbers or strings (& | ^ ~) are given only strings as arguments, perl4 would treat the operands as bitstrings so long as the program contained a call to the vec() function. perl5 treats the string operands as bitstrings. (See perlop/Bitwise String Operators for more details.)

 
    $fred = "10";
    $barney = "12";
    $betty = $fred & $barney;
    print "$betty\n";
    # Uncomment the next line to change perl4's behavior
    # ($dummy) = vec("dummy", 0, 0);

    # Perl4 prints:
    8

    # Perl5 prints:
    10

    # If vec() is used anywhere in the program, both print:
    10  

 

 

 

Domain name registration service & domain search - 
Register cheap domain name from $7.95 and enjoy free domain services 
 

Cheap domain name search service -
Domain name services at just
$8.95/year only
 

Register domain name -
Buy domain name registration and cheap domain transfer at low, affordable price.

© 2002-2004 Active-Venture.com Web Site Hosting Service

 

[ Never underestimate the bandwidth of a station wagon full of backup tapes hurling down the highway.   ]

 

 
 
 

Disclaimer: This documentation is provided only for the benefits of our web hosting customers.
For authoritative source of the documentation, please refer to http://www.perldoc.com