# New Ticket Created by Bernhard Schmalhofer # Please include the string: [perl #19834] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=19834 >
Hi, I have been looking into the possibility of adding complex numbers as PMCs. When looking at core.ops I was missing some operations, where INT, NUM and PMC interact. For addition I found the operations: add_i_i, add_n_n, add_p_i, add_p_n, add_p_p, add_i_i_i, add_n_n_n, add_p_p_i, add_p_p_p. Trying to make this more consistent I added: add_n_i, add_n_n_i and app_p_p_n. This means that there are now 12 addition ops. I also brought 'sub', 'mul' and 'div' to the same level. I have put some tests in t/op/arithmetics.t. Each of the operations mentioned above should be called in the test. However I still wonder about operations like 'div_p_n_p'. Unlike 'div_p_p_n', it can't be implemented with the vtable-function divide_float. I have attached the patch for core.ops and the file arithmetics.t. CU, Bernhard -- ************************************************* Bernhard Schmalhofer Senior Developer Biomax Informatics AG Lochhamer Str. 11 82152 Martinsried, Germany Tel: +49 89 89 55 74 - 839 Fax: +49 89 89 55 74 - 25 PGP: https://ssl.biomax.de/pgp/ Email: mailto:[EMAIL PROTECTED] Web: http://www.biomax.de ************************************************* -- attachment 1 ------------------------------------------------------ url: http://rt.perl.org/rt2/attach/47101/37035/779e55/core.ops.patch -- attachment 2 ------------------------------------------------------ url: http://rt.perl.org/rt2/attach/47101/37036/45ee9d/arithmetics.t
--- core.ops Wed Jan 8 20:13:48 2003 +++ core.ops.20020108 Wed Jan 8 18:57:49 2003 @@ -1279,8 +1279,6 @@ =item B<add>(inout INT, in INT) -=item B<add>(inout NUM, in INT) - =item B<add>(inout NUM, in NUM) =item B<add>(inout PMC, in INT) @@ -1293,14 +1291,10 @@ =item B<add>(out INT, in INT, in INT) -=item B<add>(out NUM, in NUM, in INT) - =item B<add>(out NUM, in NUM, in NUM) =item B<add>(inout PMC, in PMC, in INT) -=item B<add>(inout PMC, in PMC, in NUM) - =item B<add>(inout PMC, in PMC, in PMC) Set $1 to the sum of $2 and $3. @@ -1312,11 +1306,6 @@ goto NEXT(); } -inline op add(inout NUM, in INT) { - $1 += $2; - goto NEXT(); -} - inline op add(inout NUM, in NUM) { $1 += $2; goto NEXT(); @@ -1342,11 +1331,6 @@ goto NEXT(); } -inline op add(out NUM, in NUM, in INT) { - $1 = $2 + $3; - goto NEXT(); -} - inline op add(out NUM, in NUM, in NUM) { $1 = $2 + $3; goto NEXT(); @@ -1357,11 +1341,6 @@ goto NEXT(); } -inline op add(inout PMC, in PMC, in NUM) { - $2->vtable->add_float(interpreter, $2, $3, $1); - goto NEXT(); -} - inline op add (inout PMC, in PMC, in PMC) { $2->vtable->add(interpreter, $2, $3, $1); goto NEXT(); @@ -1477,91 +1456,40 @@ ######################################## -=item B<div>(inout INT, in INT) - -=item B<div>(inout NUM, in INT) - -=item B<div>(inout NUM, in NUM) - -=item B<div>(inout PMC, in INT) - -=item B<div>(inout PMC, in NUM) - -=item B<div>(inout PMC, in PMC) - -Divide $1 by $2. - =item B<div>(out INT, in INT, in INT) -=item B<div>(out NUM, in NUM, in INT) - =item B<div>(out NUM, in NUM, in NUM) -=item B<div>(inout PMC, in PMC, in INT) - -=item B<div>(inout PMC, in PMC, in NUM) - =item B<div>(inout PMC, in PMC, in PMC) +=item B<div>(inout PMC, in INT) + Set $1 to the quotient of $2 divided by $3. In the case of INTVAL division, the result is truncated (NOT rounded or floored). =cut -inline op div(inout INT, in INT) { - $1 /= $2; - goto NEXT(); -} - -inline op div(inout NUM, in INT) { - $1 /= $2; - goto NEXT(); -} - -inline op div(inout NUM, in NUM) { - $1 /= $2; - goto NEXT(); -} - -inline op div (inout PMC, in INT) { - $1->vtable->divide_int(interpreter, $1, $2, $1); - goto NEXT(); -} - -inline op div (inout PMC, in NUM) { - $1->vtable->divide_float(interpreter, $1, $2, $1); - goto NEXT(); -} - inline op div(out INT, in INT, in INT) { $1 = $2 / $3; goto NEXT(); } -inline op div(out NUM, in NUM, in INT) { - $1 = $2 / $3; - goto NEXT(); -} - inline op div(out NUM, in NUM, in NUM) { $1 = $2 / $3; goto NEXT(); } -inline op div (inout PMC, in PMC, in INT) { - $2->vtable->divide_int(interpreter, $2, $3, $1); +inline op div (inout PMC, in PMC, in PMC) { + $2->vtable->divide(interpreter, $2, $3, $1); goto NEXT(); } -inline op div (inout PMC, in PMC, in NUM) { - $2->vtable->divide_float(interpreter, $2, $3, $1); +inline op div (inout PMC, in INT) { + $1->vtable->divide_int(interpreter, $1, $2, $1); goto NEXT(); } -inline op div (inout PMC, in PMC, in PMC) { - $2->vtable->divide(interpreter, $2, $3, $1); - goto NEXT(); -} + ######################################## @@ -1703,28 +1631,18 @@ =item B<mul>(inout INT, in INT) -=item B<mul>(inout NUM, in INT) - =item B<mul>(inout NUM, in NUM) =item B<mul>(inout PMC, in INT) -=item B<mul>(inout PMC, in NUM) - =item B<mul>(inout PMC, in PMC) Set $1 to the product of $1 and $2. =item B<mul>(out INT, in INT, in INT) -=item B<mul>(out NUM, in NUM, in INT) - =item B<mul>(out NUM, in NUM, in NUM) -=item B<mul>(inout PMC, in PMC, in INT) - -=item B<mul>(inout PMC, in PMC, in NUM) - =item B<mul>(inout PMC, in PMC, in PMC) Set $1 to the product of $2 and $3. @@ -1736,11 +1654,6 @@ goto NEXT(); } -inline op mul(inout NUM, in INT) { - $1 *= $2; - goto NEXT(); -} - inline op mul(inout NUM, in NUM) { $1 *= $2; goto NEXT(); @@ -1751,11 +1664,6 @@ goto NEXT(); } -inline op mul ( inout PMC, in NUM ) { - $1->vtable->multiply_float(interpreter, $1, $2, $1); - goto NEXT(); -} - inline op mul (inout PMC, in PMC) { $1->vtable->multiply(interpreter, $1, $2, $1); goto NEXT(); @@ -1766,26 +1674,11 @@ goto NEXT(); } -inline op mul(out NUM, in NUM, in INT) { - $1 = $2 * $3; - goto NEXT(); -} - inline op mul(out NUM, in NUM, in NUM) { $1 = $2 * $3; goto NEXT(); } -inline op mul (inout PMC, in PMC, in INT) { - $2->vtable->multiply_int(interpreter, $2, $3, $1); - goto NEXT(); -} - -inline op mul (inout PMC, in PMC, in NUM) { - $2->vtable->multiply_float(interpreter, $2, $3, $1); - goto NEXT(); -} - inline op mul (inout PMC, in PMC, in PMC) { $2->vtable->multiply(interpreter, $2, $3, $1); goto NEXT(); @@ -1881,8 +1774,6 @@ =item B<sub>(inout INT, in INT) -=item B<sub>(inout NUM, in INT) - =item B<sub>(inout NUM, in NUM) =item B<sub>(inout PMC, in INT) @@ -1895,14 +1786,10 @@ =item B<sub>(out INT, in INT, in INT) -=item B<sub>(out NUM, in NUM, in INT) - =item B<sub>(out NUM, in NUM, in NUM) =item B<sub>(inout PMC, in PMC, in INT) -=item B<sub>(inout PMC, in PMC, in NUM) - =item B<sub>(inout PMC, in PMC, in PMC) Set $1 to $2 minus $3. @@ -1914,11 +1801,6 @@ goto NEXT(); } -inline op sub(inout NUM, in INT) { - $1 -= $2; - goto NEXT(); -} - inline op sub(inout NUM, in NUM) { $1 -= $2; goto NEXT(); @@ -1944,11 +1826,6 @@ goto NEXT(); } -inline op sub(out NUM, in NUM, in INT) { - $1 = $2 - $3; - goto NEXT(); -} - inline op sub(out NUM, in NUM, in NUM) { $1 = $2 - $3; goto NEXT(); @@ -1956,11 +1833,6 @@ inline op sub(inout PMC, in PMC, in INT) { $2->vtable->subtract_int(interpreter, $2, $3, $1); - goto NEXT(); -} - -inline op sub(inout PMC, in PMC, in NUM) { - $2->vtable->subtract_float(interpreter, $2, $3, $1); goto NEXT(); }