# New Ticket Created by  Zoffix Znet 
# Please include the string:  [perl #128428]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=128428 >


Current implementation of `mod` has (Real, Real) signature and uses `div 
(Int,Int)` to perform the division. This creates an LTA error that mentions 
`div` when argumenemts aren't Ints:

<Zoffix> m: say 2 mod 1.5
<camelia> rakudo-moar 5ca43c: OUTPUT«Cannot resolve caller infix:<div>(Int, 
Rat); none of these signatures match:␤    (Int:D \a, Int:D \b)␤    (int $a, int 
$b --> int)␤  in block <unit> at <tmp> line 1␤␤»

Reading the spec (http://design.perl6.org/S03.html), descriptions of 
infix:<mod>/infix:<div> suggest they should work on all numeric types, as long 
as LHS/RHS are the same type:

-------------quote from spec----------------------
===========================
infix:<div>, integer division

    $numerator div $denominator

Dispatches to the infix:<div> multi most appropriate to the operand types, 
returning a value of the same type. Not coercive, so fails on differing types.

Policy on what to do about division by zero is up to the type, but for the sake 
of hyperoperators and junctions those types that can represent overflow (or 
that can contain an unthrown exception) should try to do so rather than simply 
throwing an exception. (And in general, other operators that might fail should 
also consider their use in hyperops and junctions, and whether they can 
profitably benefit from a lazy exception model.)

On the other hand, div wants to be very efficient and jittable when used as a 
low-level operation, so when you use div on two native ints, it relies on 
hardware to detect division by 0. Hence, it will always throw an exception 
rather than return a Failure.

In general, div should give the same result as

    $x div $y == floor($x/$y)

but the return value should be the same type as $x.

This identity stops holding when $x/$y degrades to a Num and runs into 
precision limits. A div operation on two Int objects must always be done 
precisely.

===========================
infix:<mod>, integer modulo

    $x mod $y

Dispatches to the infix:<mod> multi most appropriate to the operand types, 
returning a value of the same type. Not coercive, so fails on differing types.

This should preserve the identity

    $x mod $y == $x - ($x div $y) * $y
-------------/quote from spec----------------------

Reply via email to