On Sun, 20 Jun 2004 15:57:48 +0100, Jonathan Worthington <[EMAIL PROTECTED]> wrote:

"Alexey Trofimenko" <[EMAIL PROTECTED]> wrote:

what do you think about adding C<div> operator, akin %, to perl6 core?

I mean, as                $a   %  $b
  really does          int($a)  %  int($b)
  and returns modulous,

so $a div $b
really does int( int($a) / int($b) )
and returns integer division.
but with native integers, declared as such, and with constants it should
be optimized and done really fast
yes, I realize that it wouldn't speed Perl up much, but I like idea that
such a simple operation can be done using one simple machine instruction.
And I use such a function often, but I hate that it uses floats
internally.

I'd imagine that if you declare a variable as an int, the compiler would be
able to generate optimal code for the % operator anyway, so you'd get the
speed you wanted.


Jonathan

of course! but what I'm talking about is "integer /" , (not "%", which we have already). I talked about division, which takes integer args and return _integer_ result. Sometimes you need exactly this, and Perl would never guess it, even if both args of / are integer, but what if we're expect fraction results? So now perl always calcs float division..

One example -
$t = time - $when_it_happen;
$sec=$t%60;  $t=int($t/60);
$min=$t%60;  $t=int($t/60);
$hours=$t%24; $t=int($t/24);
$days=$t;
return time_elapsed($days,$hours,$min,$sec)



Reply via email to