Re: Forth PARANOIA



According to Andrew Haley <andrew29@xxxxxxxxxxxxxxxxxxxxxxx>:
Perhaps. C99 says: "The pow functions compute x raised to the power
y. A domain error occurs if x is finite and negative and y is finite
and not an integer value. A domain error may occur if x is zero and y
is less than or equal to zero. A range error may occur." This seems
sensible.

As a point of comparison, here is what Java states about the Math.pow()
function:


public static double pow(double a,
double b)

Returns the value of the first argument raised to the power of the
second argument. Special cases:

* If the second argument is positive or negative zero, then the
result is 1.0.

* If the second argument is 1.0, then the result is the same as
the first argument.

* If the second argument is NaN, then the result is NaN.

* If the first argument is NaN and the second argument is nonzero,
then the result is NaN.

* If:
- the absolute value of the first argument is greater than 1
and the second argument is positive infinity, or

- the absolute value of the first argument is less than 1
and the second argument is negative infinity,

then the result is positive infinity.

* If:
- the absolute value of the first argument is greater than 1
and the second argument is negative infinity, or

- the absolute value of the first argument is less than 1
and the second argument is positive infinity,

then the result is positive zero.

If the absolute value of the first argument equals 1 and the
second argument is infinite, then the result is NaN.

* If:
- the first argument is positive zero and the second
argument is greater than zero, or

- the first argument is positive infinity and the second
argument is less than zero,

then the result is positive zero.

* If:
- the first argument is positive zero and the second
argument is less than zero, or

- the first argument is positive infinity and the second
argument is greater than zero,

then the result is positive infinity.

* If:
- the first argument is negative zero and the second
argument is greater than zero but not a finite odd
integer, or

- the first argument is negative infinity and the second
argument is less than zero but not a finite odd integer,

then the result is positive zero.

* If:
- the first argument is negative zero and the second
argument is a positive finite odd integer, or

- the first argument is negative infinity and the second
argument is a negative finite odd integer,

then the result is negative zero.

* If:
- the first argument is negative zero and the second
argument is less than zero but not a finite odd integer,
or

- the first argument is negative infinity and the second
argument is greater than zero but not a finite odd
integer,

then the result is positive infinity.

* If:
- the first argument is negative zero and the second
argument is a negative finite odd integer, or

- the first argument is negative infinity and the second
argument is a positive finite odd integer,

then the result is negative infinity.

* If the first argument is finite and less than zero:

- if the second argument is a finite even integer, the
result is equal to the result of raising the absolute
value of the first argument to the power of the second
argument

- if the second argument is a finite odd integer, the result
is equal to the negative of the result of raising the
absolute value of the first argument to the power of the
second argument

- if the second argument is finite and not an integer, then
the result is NaN.

* If both arguments are integers, then the result is exactly equal
to the mathematical result of raising the first argument to the
power of the second argument if that result can in fact be
represented exactly as a double value.

(In the foregoing descriptions, a floating-point value is considered
to be an integer if and only if it is finite and a fixed point of
the method ceil or, equivalently, a fixed point of the method floor.
A value is a fixed point of a one-argument method if and only if the
result of applying the method to the value is equal to the value.)

The computed result must be within 1 ulp of the exact result.
Results must be semi-monotonic.



Whether this specification is good or not is arguable. It has some
shortcomings; e.g., it has the ability to destroy a NaN with an exponent
of 0.0 (either +0.0 or -0.0), which I think is quite opposite to the
very purpose of NaN. Nonetheless, this documentation illustrates that
there many special cases to specify or at least worry about with the
pow() function (Java, with its "compile once, run everywhere" dogma,
tends to [over-]specify, as shown above).


--Thomas Pornin
.



Relevant Pages

  • Re: Im always a winner
    ... Divide by zero in any equation and you get ... so you can't just check it against a NaN you happen to have ... True, but then infinity isn't a number either, ...
    (alt.usage.english)
  • Re: infinity
    ... >> If you ask most people what infinity times zero is, ... which is a sparse set in the reals. ... mapped by any finite formula from the naturals. ...
    (sci.math)
  • Re: John Gabriels Theorem Revisited.
    ... w/n can never be zero, no matter how large you make n. ... The difference between zero and infinity is that we can perform finite ... in his proof is the use of what he calls positional derivatives. ... average sum and average tangent theorem. ...
    (sci.math)
  • Re: You Dont Have to Be Nuts to Be a Mathematician ...
    ... Extended from minus infinity to plus infinity. ... a universal meaning of numbers and in particular of zero. ... > neutral zero between positive and negative numbers. ... > must be fundamentally revised in order to purify mathematics from some ...
    (sci.math)
  • Re: Interesting math
    ... And division by zero does not ... it would be wrong since infinity can never be approached: ... Interesting you should mention Zeno. ... Decades back one of my science teachers said, ...
    (alt.usage.english)

Loading