[r6rs-discuss] Why are fx+ and fx* restricted to two arguments
On Tue, 20 Feb 2007, William D Clinger wrote:
>Earlier in this thread, following a context of fx+ and fx*,
>Mikael Tillenius wrote:
>
>> Related to the above, how is ordinary "+" for handled. According to
>> IEEE, + (and -, *, /, sqrt) should first be done _exact_ and then
>> rounded. Of course IEEE speeks only about binary "+". Do we compute the
>> exact sum of all arguments and then round or do we add and round pairs
>> of numbers? If so, in what order? Same for "fl+".
Principle of least surprise and implementation ease
indicates adding the numbers from left to right, in
the order in which they appear in the code.
Best practices for obtaining the most precise answer
in flonum mathematics indicate adding from smallest
absolute value to largest absolute value.
Best practices for obtaining known-and-finite results
in fixnum mathematics with overflow errors raising
exceptions indicate selecting at each step the number
that leaves the intermediate sum nearest zero. But
if you're presuming modular fixnum mathematics rather
than fixnum mathematics that raise exceptions or overflow
errors, there is no rationale for selecting any particular
order.
>> When all of the arguments are exact, the result will
>> also be exact and the order doesn't matter.
>
>To this, Mikael replied:
>
>> Sorry for nitpicking but this is not true. In fact, the order can
>> determine whether the result will be exact or inexact, and in the case
>> of inexact it affacts the roundin and whether the result i finite or an Inf.
in modular fixnum mathematics, when the addends are exact,
the sum is perforce exact (even though the modularity
of this addition-like operator may mean that the number
is not the same value that mathematical addition would
give for the same arguments). In flonum mathematics, the
addends are inexact anyway so the statement is inapplicable.
Bear
Received on Sun Mar 11 2007 - 14:17:22 UTC
This archive was generated by hypermail 2.3.0
: Wed Oct 23 2024 - 09:15:01 UTC