in reply to Numeric overloading with 64-bit Perl

As I understand it, this is what the use integer; pragma is for... Test results: Putting this at the top of your code under the other pragma declarations did indeed make the problem go away when I tested it.

-M

Free your mind

Replies are listed 'Best First'.
Re^2: Numeric overloading with 64-bit Perl
by jdhedden (Deacon) on Oct 06, 2005 at 13:34 UTC
    Yes, use integer will coerce the overload result back to integer format, as will using the int() function. But these are just workarounds. (And use integer is worse because it affects all arithmetic within a block, or the entire application, if placed at the top as you recommended.)

    The issue is how to stop the needless coercion of the integer return value (1000000000000000) to a floating-point result (1e+15) in the first place.


    Remember: There's always one more bug.
      The manual, clearly describes that "use integer;" controls the actual computation, rather than coercing anything afterwards. Specifically, when use integer is in effect, floating point numbers will be rounded, but integers will not be coerced into floating point - they will stay integer before during and after any computation in the relevant scope.

      I suggested placing it at the top of the example program because the example program had only one purpose - to show where float conversion took place for 16 digits. This should not be construed as a recommendation to always place it at the top of every program.

      Re your subsequent objection to the block scope nature of use integer, I can't conceive of any actual case where the use of

      { use integer;" # statements where the pragma is required # ... "}"
      wherever the pragma is actually required, can fail to control the scope - curly brackets can be applied anywhere you like!

      -M

      Free your mind