develooper Front page | perl.perl5.porters | Postings from May 2003

[perl #22193] perlop and integer docs are inconsistent about use integer

Thread Previous | Thread Next
Adam M. Costello
May 13, 2003 17:52
[perl #22193] perlop and integer docs are inconsistent about use integer
Message ID:
# New Ticket Created by  "Adam M. Costello" 
# Please include the string:  [perl #22193]
# in the subject line of all future correspondence about this issue. 
# <URL: >

I want to perform integer division.  According to perldoc integer, 4/3
is guaranteed to be 1 in the scope of use integer.  But according to
perldoc perlop, "this doesn't mean everything is only an integer, merely
that Perl may use integer operations if it is so inclined".

One of those documents needs to be fixed.  Which one?  (The
inconsistency exists in both 5.6.1 and 5.8.)

If use integer does not guarantee that 4/3 is 1, then my next
thought would be int(4/3).  But I can't find any guarantees about
the precision of floating-point division.  Is 2121212121 exactly
representable?  Even if I knew that it were, I see no guarantee that
int(2121212121/707070707) is 3; maybe on some platforms it could come
out as 2.99999... and get truncated to 2.

If use integer does not guarantee integer division, then I guess my only
hope for predictable integer division is Math::BigInt.  I don't need the
bigness, I just need predictable results for integers within a known
range.  I don't even need to know the range when I write the code, if I
can discover it at runtime.  If the range is too small, at least I can
fail explicitly, rather than risk getting silently wrong answers.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About