🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.java.programmer
1 messages
1 total messages Started by Alexander Anderson Sun, 08 Jun 1997 00:00
Complex versions of isNaN & isInfinite
#215
Author: Alexander Anderson
Date: Sun, 08 Jun 1997 00:00
127 lines
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
*/
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads