At 9:34 AM +0000 12/29/06, Luke Palmer wrote:
When do we do integer/rational math and when do we do floating point math?
That is, is 1 different from 1.0? Should 10**500 be infinity or a 1
with 500 zeroes after it? Should 10**10**6 run out of memory? Should
"say (1/3)**500" print a bunch of digits to the screen or print 0?
These are just examples. Exponentials are the easiest to think about
limit cases with, but the whole general issue needs precise semantics.
Related to that question, I'd like to draw the list's attention to a
#perl6 discussion that several of us had today:
http://colabti.de/irclogger/irclogger_log/perl6?date=2006-12-31
Following from this, I propose that we have distinct-looking
operators (not just multis) that users can explicitly choose when
they want to do integer division/modulus or non-integer
division/modulus.
For example, we could have:
div - integer division
mod - integer modulus
/ - number division
% - number modulus
Or alternately:
idiv - integer division
imod - integer modulus
ndiv - number division
nmod - number modulus
And in that case, "/" and "%" would be aliases for an alphanumeric
pair that can be changed using a lexical pragma; they would default
to ndiv/nmod.
In that case, the explicit "/" and "%" use would be subject to change
behaviour depending on the influence of a pragma, while explicit
idiv/imod/ndiv/nmod use would stay the same no matter what pragma is
in effect.
Note that the i/n variants would cast all their arguments as Int/Num
before performing the operation as appropriate; they do *not* simply
do non-integer work and then cast the result.
Change spelling to taste (eg, they could be spelled
Int::Div/Int::Mod/Num::Div/Num::Mod instead), but I hope you get the
point of what I was saying.
-- Darren Duncan