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

div & mod don't coerce arguments to Int?

Thread Next
From:
Sean McAfee
Date:
December 18, 2021 15:25
Subject:
div & mod don't coerce arguments to Int?
Message ID:
CANan03ZYBAiL-o1VPjxxshsDAcYw-nZXZy1UKMBG=2hkxFvSrg@mail.gmail.com
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About