T
Thomas G. Marshall
Roedy Green coughed up:
Actually, I know that code (the one you quote below) already, before I
posted. When you said "any such library method", I was think also of C
(native code), but more so for languages that are far more platform specific
and as such tied to the vaguaries of their chipset.
-a is a -1 * a. Perhaps this is to avoid the multiply. Perhaps for speed
issues, but perhaps also to maintain the NaN, +0, -0, as explained in the
comments?
For the record, the integer variants use unary -a.
Turns out not:
Actually, I know that code (the one you quote below) already, before I
posted. When you said "any such library method", I was think also of C
(native code), but more so for languages that are far more platform specific
and as such tied to the vaguaries of their chipset.
/**
* Returns the absolute value of a <code>double</code> value.
* If the argument is not negative, the argument is returned.
* If the argument is negative, the negation of the argument is
returned.
* Special cases:
* <ul><li>If the argument is positive zero or negative zero, the
result
* is positive zero.
* <li>If the argument is infinite, the result is positive
infinity.
* <li>If the argument is NaN, the result is NaN.</ul>
* In other words, the result is the same as the value of the
expression:
....[rip]...
the interesting thing is the
0.0D -a
not just -a
Where's Patricia to explain the conditions those are not equivalent?
-a is a -1 * a. Perhaps this is to avoid the multiply. Perhaps for speed
issues, but perhaps also to maintain the NaN, +0, -0, as explained in the
comments?
For the record, the integer variants use unary -a.