Article View: comp.lang.java.programmer
Article #215Complex versions of isNaN & isInfinite
From: Alexander Anderson
Date: Sun, 08 Jun 1997 00:00
Date: Sun, 08 Jun 1997 00:00
127 lines
4614 bytes
4614 bytes
Dear Java Programmer,
There is are two methods in java.lang.Double related to the IEEE-754
standards for handling floating point arithmetic. (See Section 5.15.2 &
5.15.3 of Chapter 5, "Tokens, Operators, and Expressions" of "The Java
Programming Language" by Ken Arnold & James Gosling, ISBN 0-201-63455-4)
isNaN...
public boolean isNaN()
Returns true if this Double value is the special Not-a-
Number (NaN) value.
Returns:
true if the value represented by this object is NaN;
false otherwise.
and isInfinite...
public boolean isInfinite()
Returns true if this Double value is infinitely large in
magnitude.
Returns:
true if the value represented by this object is
positive infinity or negative infinity;
false otherwise.
-------------------------
*
Now, I recently announced a Complex class (0.96 BETA).
I've just added the two methods 'isNaN' and 'isInfinite', in keeping
with class Double. The way they work is:
isNaN...
// return true if either component is NaN; otherwise false.
public boolean isNaN () {
return ( Double.isNaN(re) || Double.isNaN(im) );
}// isNaN()
isInfinite...
// return true if either component is infinite; otherwise false.
public boolean isInfinite () {
return ( Double.isInfinite(re) || Double.isInfinite(im) );
}// isInfinite()
************************************************************************
* *
* Now looking at this for a while now; is 'isInfinite' the *
* behaviour you really want? Let me explain. Say you end up with a *
* result, z, like *
* *
* *
* z = ( NaN + Infinity * i ) *
* *
* *
* The real component is NaN. So the whole Complex is really NaN *
* -- not a number -- and 'isInfinite' should return false. It makes *
* no mathematical sense to "know", when at least one component is *
* NaN, whether the other component "is" infinite. *
* *
************************************************************************
In other words, should the definition of Complex 'isInfinite'
instead be:
isInfinite:
// if isNaN returns false AND either real or imaginary component
// is infinite, return true; false otherwise.
public boolean isInfinite () {
return ( ! isNaN()
&&
( Double.isInfinite(re) || Double.isInfinite(im) )
);
}// isInfinite()
Thanks in advance,
Sandy
*
http://www.almide.demon.co.uk/html/Complex/Complex_for_Java.html
/* Correct my address in any reply, or it'll be treated as spam:
--
// Alexander Anderson <DELETE_THIS.sandy@almide.demon.co.uk>
// Home Fone +44 (0) 171-794-4543
// London, UK http://www.almide.demon.co.uk/
// PGP print C6 8C 55 F2 77 7B 99 9B 14 77 66 F5 B8 74 CF 12
*/
Technical Details
Message-ID:
<6zDV7AAH2vmzEww4@almide.demon.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10a146,9399da0dd2c302ed,start X-Google-Attributes: gid10a146,public X-Google-Thread: 10d67e,9399da0dd2c302ed,start X-Google-Attributes: gid10d67e,public X-Google-Thread: 109d8a,9399da0dd2c302ed,start X-Google-Attributes: gid109d8a,public From: Alexander Anderson <DELETE_THIS.sandy@almide.demon.co.uk> Subject: Complex versions of isNaN & isInfinite Date: 1997/06/08 Message-ID: <6zDV7AAH2vmzEww4@almide.demon.co.uk> X-Deja-AN: 247087679 Distribution: world X-NNTP-Posting-Host: almide.demon.co.uk [158.152.137.110] Organization: ALMA Services Newsgroups: comp.lang.java.programmer,aus.mathematics,sci.math