develooper Front page | perl.perl6.users | Postings from December 2021

div & mod don't coerce arguments to Int?

Thread Next
Sean McAfee
December 18, 2021 15:25
div & mod don't coerce arguments to Int?
Message ID:
While coding today, I was a little surprised to discover that the div
operator doesn't coerce its arguments to integers.  So for example, the
expressions 25 div '5' and pi div 5 raise errors.  I checked the Operators
doc page and saw that, sure enough, div (and mod, I found) accept only
actual Ints.  Of all numeric operators at the multiplicative and additive
levels of precedence, they're alone in that respect.

Is there a particular reason these two operators are so restrictive?

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