pugs-comm...@feather.perl6.nl wrote:
Author: lwall
Date: 2009-08-29 21:06:40 +0200 (Sat, 29 Aug 2009)
New Revision: 28113

[S03] some tidying of /, %, div, and mod
@@ -699,7 +699,16 @@
$numerator / $denominator -If either operand is of C<Num> type, converts both operands to C<Num>
+Performs division of real or complex numbers, returning a real or complex
+number of appropriate type.
+If both operands are of integer type, the operator returns the
+corresponding C<Rat> value.

     $numerator div $denominator
-Use of C<div> on two C<Int> values results in a ratio of the C<Rat> type.
+Use of C<div> on built-in integer types is equivalent to taking the
+floor of a real division:
+ $x div $y == floor($x/$y);

This is a great move; thanks for this change.

So now writing things like 5/43 in code will DWIM and produce a Rat which maintains the intended value exactly, with no floating-point imprecision; and so plain 5/43 is now a plain Rat literal, same as 1.23 is.

Similarly its good that by default 'div' can be counted on to result in values of the same type as its operands, such as Int,Int-->Int.

Generally speaking, the simpler/terse looking numeric operators like "/" should produce exact results from exact inputs where possible, and leave the inexact (float) results from exact inputs to more complex/verbose looking operators.

Much appreciated.

-- Darren Duncan

Reply via email to