Re: numerical conditioning MAGNITUDE and / William D Clinger (21 Jun 2006 13:29 UTC)
Re: numerical conditioning MAGNITUDE and / John Cowan (21 Jun 2006 13:38 UTC)
Re: numerical conditioning MAGNITUDE and / Aubrey Jaffer (21 Jun 2006 17:32 UTC)

Re: numerical conditioning MAGNITUDE and / Aubrey Jaffer 21 Jun 2006 17:32 UTC

 | From: William D Clinger <xxxxxx@ccs.neu.edu>
 | Date: Wed, 21 Jun 2006 09:29:44 -0400
 |
 | Aubrey Jaffer wrote:
 | ...
 | > Does SRFI-77 (or R5RS) mandate that floating-point procedures
 | > work for arguments generating the full range of possible outputs?
 |
 | No.  Neither mandates that ... implementations
 | of the standard procedures be of high quality.

R5RS Section 6.2.6 "Numerical Input and Output" places a stringent
constraint on the quality of NUMBER->STRING:

     If Z is inexact, the radix is 10, and the above expression can be
     satisfied by a result that contains a decimal point, then the
     result contains a decimal point and IS EXPRESSED USING THE
     MINIMUM NUMBER OF DIGITS (exclusive of exponent and trailing
     zeroes) NEEDED TO MAKE THE ABOVE EXPRESSION TRUE [howtoprint],
     [howtoread]; otherwise the format of the result is unspecified.

The operations for computing complex MAGNITUDE and / are:

magnitude	flonum operations
	 sum  product quotient abs  <
naive:	  1	 2	 0	0   0
correct:  1	 2	 1	2   1

    /		flonum operations
	 sum  product quotient abs  <
naive:	  3	 6	 2	0   0
correct:  3	 3	 3	2   1

Floating-point ABS involves just flipping one bit; it should be very
fast.

The correct versions are unlikely to be much slower than naive ones;
correct-/ is perhaps faster.  So the arguments for implementing these
procedures incorrectly are weak.