Comparing double NaN

It seems that there is a bug in the way the virtual machine compares floating point NaN's. My understanding of the spec is that dcmpg and fcmpg should return +1 if one of the stack elements are NaN. As far as I can see -1 is returned (which is what dcmpl and fcmpl does).
I have tried 1.4.2 on win2000 and kvm cldc1.1 on win2000.
Any comments?

Interesting, but if you look at:
http://java.sun.com/docs/books/vmspec/2nd-edition/html/
nstructions2.doc3.html
the spec for dcmp says that it should push 1 to the
stack, which it does not. The VM and language spec
seems to say different things. And the VM is following
the language spec and not its own spec.
I don't understand what you are talking about. The code that you posted is java - not byte codes. The java code should return nothing which it does.
But looking a the bytes codes for the above (using 1.4.0_01-b03) I get the following partial byte code listing for the first expression ...
    14 dcmpg
    15 ifge 26
    18 getstatic #15 <Field java.io.PrintStream out>
    21 ldc #117 <String "one">
    23 invokevirtual #23 <Method void println(java.lang.String)>From the VM spec for ifge...
<if>ge succeeds if and only if value >= 0
And your code doesn't print 'one'. That means the branch is being taken.
That means only one of the following is true.
1. There is a '1' (or some positive value on the stack.)
2. The documentation for ifge is wrong.
So are you also stating that the documentation for ifge is wrong?
If not then you need to provide exact information on how you determine that there is a '-1' on the stack instead of a '1'. And perhaps provide the real context that demonstrates this.

Similar Messages

  • What is Double.NaN for?

    I'm trying to understand what is Double.NaN for. I did understand the use od Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY. I did try
    double value = Double.parseDouble("123ws34");
    and then
    if (value == Double.NaN)

    NaN (not a number) is returned by various methods when the result from a function is undefined. You can use this fact to code a reasonable action when the program does something silly - like dividing zero by zero.

  • What is  Double.NaN

    hi i want to know what is Double.NaN ?
    the SUN doc says, "....... A constant holding a Not-a-Number (NaN) value of type double...." then what is the content of Double.NaN ?
    suppose i am writing Double a = new Double(Double.NaN); what is the content of a ?
    i want an example of Double.NaN ? can you give one example of what does that mean ?

    It is a value that is the result of certain arithmetic
    operations, such as multiplying infinity by zero or
    dividing infinity by infinity. ok...i am not doing any illegal arithmetic operation below. how about the code ?
    public class Base
            public static void main(String args[])
            Double a = new Double(Double.NaN);
        Double b = new Double(Double.NaN);
        System.out.println(a.NaN); // trying to see what is the  default of Nan field
        System.out.println(b.NaN); // trying to see what is the  default of Nan field
        if( Double.NaN == Double.NaN )  // line 1
           System.out.println("True");
        else
           System.out.println("False");
        if( a.equals(b) ) // line 2
          System.out.println("True");
        else
          System.out.println("False");
       i am getting output
    NaN
    NaN
    False
    True
    Press any key to continue...
    that means default of NaN field is a NaN. look //line 1 . if both of them gets default value NaN then why not the output is true ?
    and also look at line 2 . both of them have contents NaN. why why not the output is true here also.
    so , the output should have been
    NaN
    NaN
    true
    true
    but it is not.
    where is the mistake ?

  • Help with Double.NaN

    This class is supposed to check how many real numbers are being sent to All and depending on that perform further operations with those numbers.
    It works just fine if all four number are present, but if one number is missing (i.e. fourth number in n2 in main), when it goes to All the first condition is ALWAYS true, even though it says if the number is not NaN it just skips it and goes to AllN with four numbers. Am I not using Double.NaN right?
    public class Numbers {
    public double num1 = Double.NaN, num2 = Double.NaN;
    public double num3 = Double.NaN, num4 = Double.NaN;
    public double first = Double.NaN, second = Double.NaN;
    public double third = Double.NaN, fourth = Double.NaN;
    public String snum0;
    // accessor methhods
    public void setNum1 (double value) {
    num1 = value;
    public void setNum2 (double value) {
    num2 = value;
    public void setNum3 (double value) {
    num3 = value;
    public void setNum4 (double value) {
    num4 = value;
    public double getNum1 () {
    return num1;
    public double getNum2 () {
    return num2;
    public double getNum3 () {
    return num3;
    public double getNum4 () {
    return num4;
    public double getFirst () {
    if (first != Double.NaN)
    return first;
    else
    return Double.NaN;
    public double getSecond () {
    if (second != Double.NaN)
    return second;
    else
    return Double.NaN;
    public double getThird () {
    if (third != Double.NaN)
    return third;
    else
    return Double.NaN;
    public double getFourth () {
    if (fourth != Double.NaN)
    return fourth;
    else
    return Double.NaN;
    public void All (Numbers s) {
    if (s.num4 != Double.NaN &&
    s.num3 != Double.NaN &&
    s.num2 != Double.NaN &&
    s.num1 != Double.NaN)
    AllN(s.num1, s.num2, s.num3, s.num4);
    else if (s.num4 == Double.NaN &&
    s.num3 != Double.NaN &&
    s.num2 != Double.NaN &&
    s.num1 != Double.NaN)
    AllN(s.num1, s.num2, s.num3);
    else if (num4 == Double.NaN &&
    num3 == Double.NaN &&
    num2 != Double.NaN &&
    num1 != Double.NaN)
    AllN(num1, num2);
    else if (s.getNum4() == Double.NaN &&
    s.getNum3() == Double.NaN &&
    s.getNum2() == Double.NaN &&
    s.getNum1() != Double.NaN)
    AllN(num1);
    else if (s.getNum4() == Double.NaN &&
    s.getNum3() == Double.NaN &&
    s.getNum2() == Double.NaN &&
    s.getNum1() == Double.NaN)
    AllN();
    }// end SortAll
    public void AllN() {
    snum0 = "There are no numbers to sort";
    public static void main (String args[]) {
    Sort n1 = new Sort();
    n1.setNum1(13);
    n1.setNum2(14);
    n1.setNum3(15);
    n1.setNum4(16);
    n1.SortAll(n1);
    Sort n2 = new Sort();
    n2.setNum1(57);
    n2.setNum2(34);
    n2.setNum3(50);
    n2.SortAll(n2);
    System.out.println(n1.getSecond());
    System.out.println(n2.getFirst());
    } // End Main

    double v = 5.0;
    if (v == v) {
      System.out.println("v is a number: "+v);
    } else { // (v != v)
      System.out.println("v is not a number: "+v);
    // or
    if (Double.isNaN(v)) {
      System.out.println("v is not a number: "+v);
    } else {
      System.out.println("v is a number: "+v);
    }

  • Strange behaviour of Double.NaN

    I have a question, which is purely for my own interest as I've read the documentation and know that when checking for a doulbe being "Not a Number" you should use Double.isNan() and not double== Double.NaN.
    However,
    I'm confused as to how this works. If you look inside the Double Class, you will see that Double.NaN is defined as a static final - i.e. a constant.
    Now the following code:
    if(Double.NaN == Double.NaN) will always return false. But should the compiler optimise this and realise the result is true? After all its just a static final like any other constant.
    Secondly, the inplementation of Double.isNan(double d) is as follows:
    static public boolean isNaN(double v) {
         return (v != v);
    }Again, when this was compiled, shouldn't the compiler just optimize it and realise the result is always false?
    If anyone can shed light on this I would be most interested!
    Thanks

    erm...wrong again.
    consider the following code:
    public static final double a = 1.0;
    public static final double NaN = 0.0d/0;
    if(a!=a) System.out.println("This is wierd");
    if(NaN!=NaN) System.out.println("This is wierder");
    No, not wrong again.
    Your question was specific to Double.NaN, and like you said yourself, and like this code demonstrates, Double.NaN != Double.NaN
    The result is that only the second print statement
    appears. How my question is, they are both just
    constants, not evaluated dynamically at runtime but
    fixed at compile time. So how does it work?I fail to see the problem. Yes, Double.NaN is a compile-time constant. So what? I fail to see how that should make any difference.
    The == operator always gives false when one or both of its arguments is Double.NaN. What does it matter how it works - the actual implementation of it will be different from one compiler and JVM to another - you shouldn't really care how it works - you just need to know that it is defined to work that way.

  • Comparing NaN

    I need to compare two big arrays of double which may contain items set to not-a-number (NaN).
    When both arrays contain NaN items, the comparison should yield "equal" if all NaN elements are placed at the same index position and, of course, if all numeric items (elements that are not NaN) are equal.
    Unfortunately this is not the standard behavior: if you compare two NaNs, LabVIEW yields "different" with the standard operator.
    I have tried "flattening" to string both arrays before the comparison in order to achieve the expected behaviour. However in this case the performance is very poor (350ms to compare 1MB of data).
    Finally I had to implement an external DLL function that merely yields the result of the "memcmp" C function. In this way comparing 1M
    b of data requires at the most 100ms.
    Isn't there a more elegant way in LabVIEW to obtain the same result?

    > I need to compare two big arrays of double which may contain items set
    > to not-a-number (NaN).
    > When both arrays contain NaN items, the comparison should yield
    > "equal" if all NaN elements are placed at the same index position and,
    The equals node in LV act the way it does because that is the way IEEE
    defines it. The string comparison is a good idea, but most of the time
    is being spent converting the data into a string and possibly swapping
    bytes.
    Another approach, that will probably be faster is to do a simple
    comparison first, but when it returns false, look at the elements that
    are FALSE and see if both are NaNs. If there aren't that many NaNs, it
    should go pretty quick. To get the more detailed equals data, popup on
    the equals node and turn
    on Compare Aggregates. This will now return an
    array of Booleans instead of a single one. You can either loop through
    or search for FALSE. The index returned can be used to index the input
    elements and see if they are both NaN using the IsNan function.
    Of course if you want to use a DLL and C code to do the comparison, that
    will work too and will probably be even faster.
    Greg McKaskle

  • Why not Integer.NaN?

    Hello
    I wonder why Integer does not supply a NaN like Double.NaN. I find the Double.Nan to be very useful.
    Regards
    JT

    :) I think what you mean is that integers are
    normally only used with the basic arithmetic
    operations: +, -, *, and / (I miss having Python's
    built-in exponentiation operator). These operations
    never return infinity or NaN, with the single notable
    exception of division by zero. And dividing by zero
    is almost always an accident with integers, and is
    easy to check for.Yes, that's what I meant. My post was so dumb even I have to laugh at it. First, I didn't say integers are closed over multiplication, and then I said modulo and remainder like they're two different things. And integers aren't closed under integer division because of 0, as you said.
    Floating point numbers, on the other hand, are often
    used with transcendental functions and fractional
    exponents and things, which frequently result in
    infinity or NaN. Moreover, it's important to be able
    determine that the result is one of those things, so
    we have constants for them. Also, it's often hard to
    check these things ahead of time with these
    functions.
    You dig?
    As an aside, I wonder if an operator-overloading
    framework could be developed for Java by explicitly
    basing the use of operators on interfaces. For
    instance, to use the arithmetic operators, you would
    implement an interface called Field. To use
    the comparison operators, you would implement an
    interface called Ordered (which would
    basically be identical to the Comparable interface).
    You get the idea. The premise would be that it
    t would the operators to conform with their standard
    mathematical definitions.As someone adamantly opposed to operator overloading in Java, this proposal is ok to me. If you're familiar with the matlab language, operator overloading is done there by defining functions like "plus()", etc... so its sort of similar I think. I think C++ gets difficult because you can overload operators like the function call operator (), and the member of operator(s) which gets confusing really quick.

  • Float.NaN doesn't seem to work with appserver7

    I am in the process of upgrading an existing application that uses Float.NaN for invalid values when persisting to the database. I am upgrading from just using SQL statements to entity beans for the persistence layer. Is Float.NaN or Double.NaN not supported in EJB2.0 in appserver 7? The error message I get is that it is column 'NaN' does not exist.

    Here is the descriptor in ejb-jar:
    <entity>
    <display-name>Attribute</display-name>
    <ejb-name>Attribute</ejb-name>
    <local-home>com.dataservices.common.ejb.entity.attribute.AttributeLocalHomeIF</local-home>
    <local>com.dataservices.common.ejb.entity.attribute.AttributeLocalIF</local>
    <ejb-class>com.dataservices.common.ejb.entity.attribute.AttributeBean</ejb-class>
    <persistence-type>Container</persistence-type>
    <prim-key-class>com.dataservices.common.ejb.entity.attribute.AttributeKey</prim-key-class>
    <reentrant>False</reentrant>
    <abstract-schema-name>Attribute</abstract-schema-name>
    <cmp-field>
    <field-name>id</field-name>
    </cmp-field>
    <cmp-field>
    <field-name>resultId</field-name>
    </cmp-field>
    <cmp-field>
    <field-name>x</field-name>
    </cmp-field>
    <cmp-field>
    <field-name>y</field-name>
    </cmp-field>
    <cmp-field>
    <field-name>z</field-name>
    </cmp-field>
    <cmp-field>
    <field-name>comments</field-name>
    </cmp-field>
    <query>
    <query-method>
    <method-name>find</method-name>
    <method-params>
    <method-param>int</method-param>
    </method-params>
    </query-method>
    <ejb-ql>SELECT OBJECT (attribute) FROM Attribute AS attribute WHERE attribute.id = ?1</ejb-ql>
    </query>
    <query>
    <query-method>
    <method-name>findByIdAndResultId</method-name>
    <method-params>
    <method-param>int</method-param>
    <method-param>int</method-param>
    </method-params>
    </query-method>
    <ejb-ql>SELECT OBJECT (attribute) FROM Attribute AS attribute WHERE attribute.id = ?1 AND attribute.resultId = ?2</ejb-ql>
    </query>
    <query>
    <query-method>
    <method-name>findAllByResultId</method-name>
    <method-params>
    <method-param>int</method-param>
    </method-params>
    </query-method>
    <ejb-ql>SELECT OBJECT (attribute) FROM Attribute AS attribute WHERE attribute.resultId = ?1</ejb-ql>
    </query>
    </entity>
    Here is sun-cmp-mapping:
    <entity-mapping>
    <ejb-name>Attribute</ejb-name>
    <table-name>Attribute</table-name>
    <cmp-field-mapping>
    <field-name>x</field-name>
    <column-name>Attribute.x</column-name>
    </cmp-field-mapping>
    <cmp-field-mapping>
    <field-name>comments</field-name>
    <column-name>Attribute.comments</column-name>
    </cmp-field-mapping>
    <cmp-field-mapping>
    <field-name>y</field-name>
    <column-name>Attribute.y</column-name>
    </cmp-field-mapping>
    <cmp-field-mapping>
    <field-name>z</field-name>
    <column-name>Attribute.z</column-name>
    </cmp-field-mapping>
    <cmp-field-mapping>
    <field-name>id</field-name>
    <column-name>Attribute.id</column-name>
    </cmp-field-mapping>
    <cmp-field-mapping>
    <field-name>resultId</field-name>
    <column-name>Attribute.resultId</column-name>
    </cmp-field-mapping>
    </entity-mapping>
    Here is the bean:
    package com.dataservices.common.ejb.entity.attribute;
    import javax.ejb.*;
    * Created Apr 13, 2005 8:05:33 AM
    * Code generated by the Sun ONE Studio EJB Builder
    * @author mebrewster
    public abstract class AttributeBean implements javax.ejb.EntityBean {
    private javax.ejb.EntityContext context;
    * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
    public void setEntityContext(javax.ejb.EntityContext aContext) {
    context=aContext;
    * @see javax.ejb.EntityBean#ejbActivate()
    public void ejbActivate() {
    * @see javax.ejb.EntityBean#ejbPassivate()
    public void ejbPassivate() {
    * @see javax.ejb.EntityBean#ejbRemove()
    public void ejbRemove() {
    * @see javax.ejb.EntityBean#unsetEntityContext()
    public void unsetEntityContext() {
    context=null;
    * @see javax.ejb.EntityBean#ejbLoad()
    public void ejbLoad() {
    * @see javax.ejb.EntityBean#ejbStore()
    public void ejbStore() {
    public abstract int getId();
    public abstract void setId(int id);
    public abstract int getResultId();
    public abstract void setResultId(int resultId);
    public abstract double getX();
    public abstract void setX(double x);
    public abstract double getY();
    public abstract void setY(double y);
    public abstract double getZ();
    public abstract void setZ(double z);
    public abstract java.lang.String getComments();
    public abstract void setComments(java.lang.String comments);
    public com.dataservices.common.ejb.entity.attribute.AttributeKey ejbCreate(com.dataservices.common.cbo.attribute attribute) throws javax.ejb.CreateException {
    setId(attribute.getId());
    setResultId(attribute.getResultId());
    setX(attribute.getX());
    setY(attribute.getY());
    setZ(attribute.getZ());
    setComments(attribute.getComments());
    return null;
    public void ejbPostCreate(com.dataservices.common.cbo.Attribute attribute) throws javax.ejb.CreateException {
    x, y, z are all floats in the database and in the Attribute object. If I change setX(attribute.getX()); to setX(Float.NaN); (Did this to make sure it wasn't in the code outside the beans)I get the invalid column name in list error message in the servers log file.(It doesn't matter if I change x or y or z, they all do it.)
    Thanks for your help!

  • NumberFormatException: Infinite or NaN

    I do some heavy calculations with lots of variables and formulars. Depending on the values, some other values (results) can get the value "NaN" or Infinite. At the end, I want to store the results in database and convert my doubles to BigDecimal objects. At this point I get such exceptions:
    java.lang.NumberFormatException: Infinite or NaN
         at java.math.BigDecimal.<init>(BigDecimal.java:274)The only workaround i found so far, is to check each value via
                if (value1 == Double.NaN || value1 == Double.POSITIVE_INFINITY || value1 == Double.NEGATIVE_INFINITY) {
                    value1 = 0.0;
                }And i have up to 30 values that can be NaN/Infinity. So, I'm looking for some other solution?

    Well, I got a shorter form, but I hoped to somehow workaround this NaN/Infinity problem different:
            private final double resetNaN(double value) {
                double result = value;
                if (Double.isNaN(value) || Double.isInfinite(value)) {
                    result = 0.0;
                return result;
            }//resetNaN()

  • Point4D.Multiply inconsistent behaviour with NaN values

    I've noticed some peculiar behaviour with System.Windows.Media.Media3D.Point4d.Mutiply when used with NaN values.
    The following assumes that I expect that 0 * NaN should result in 0. There is an argument against that logic, but that is not the point here.
    I have a 4x4 matrix defined, in the case that it is an Identity matrix and there is a NaN component in the vector, I would like to get some defined vector output where it is possible to calculate the component.
    E.g. (1,2,NaN,4) * (Identity Matrix) = (1,2,NaN,4).
    I was caught out for a while:
    By stepping through using the debugger gives the output I want (1,2,NaN,4).
    But allowing the debug code to run through uninterrupted gives the result (NaN, NaN, Nan, Nan).
    There is a slightly surprising workaround: - using Matrix.IsIdentity seems to trigger the result I want
    If I use the default Matrix constructor instead of a manually created one (normally created elsewhere in code), there is no problem.
    Can anyone explain this inconsistency?
    Simple C# console demo:
    using System;
    using System.Windows.Media.Media3D;
    namespace TestNan
    class Program
    static void Main(string[] args)
    Point4D testPoint = new Point4D(1.0, 2.0, Double.NaN, 4.0);
    Matrix3D testMatrix = new Matrix3D(1.0, 0.0, 0.0, 0.0,
    0.0, 1.0, 0.0, 0.0,
    0.0, 0.0, 1.0, 0.0,
    0.0, 0.0, 0.0, 1.0);
    var testResult1 = Point4D.Multiply(testPoint, testMatrix);
    Console.WriteLine(testResult1.ToString());// NaN,NaN,NaN,NaN
    var b = testMatrix.IsIdentity;
    var testResult2 = Point4D.Multiply(testPoint, testMatrix);
    Console.WriteLine(testResult2.ToString());// 1, 2, NaN, 4
    Console.ReadKey();

    >>Can anyone explain this inconsistency?
    The Matrix3D class has an internal boolean flag that it uses to determine if the matrix is actually an identity matrix and this flag is not set when you create a Matrix3D object using the constructor that takes the 16 double values despite the fact that
    you are actually creating an identity matrix (the flag is then eventually set when you access the IsIdentity property).
    If you use the Matrix3D.Identity static property, the flag will get set to the correct value immediately and the results will be the expected:
    static void Main(string[] args)
    Point4D testPoint = new Point4D(1.0, 2.0, Double.NaN, 4.0);
    Matrix3D testMatrix = Matrix3D.Identity;
    var testResult1 = Point4D.Multiply(testPoint, testMatrix);
    Console.WriteLine(testResult1.ToString());
    var b = testMatrix.IsIdentity;
    var testResult2 = Point4D.Multiply(testPoint, testMatrix);
    Console.WriteLine(testResult2.ToString());// 1, 2, NaN, 4
    Console.ReadKey();
    Hope that helps.
    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't post several questions in the same thread.

  • NaN value on database

    Hi all!
    I'd like to know what kind of data Oracle database stores when I insert a NaN value. For example:
    Row myRow = viewObject.createRow();
    myRow.setAttribute("NumberField1", new oracle.jbo.domain.Number(Double.NaN));
    vo.insertRow();
    viewObject.insertRow(myRow);
    appModule.getDBTransaction.postChanges();
    appModule.getDBTransaction.commit();
    It's a kind of problematic situation, because any PL/SQL operation on field, like division or multiplication, will generate a loss of service.
    Thanks
    Gleber

    Hi 73012 !!!
    Thanks for your response.
    Is this a new Oracle10g function? I think this function is not available on Oracle 9.2.0.5.0, is it right?
    How can I handle NaN values on Oracle 9.2.0.5.0?
    Thank you again!
    Gleber

  • Converting byte[] to float the value become NaN even there is value existing.

    I tried from the online Sample but,  
                        Array.Reverse(data, index * 4, 4);
                        result = BitConverter.ToSingle(data, index * 4);
    When the  condition  index*4>data.length it will through exception.
    Thanks,

    Hi sasikumar.93,
    In C# the NAN is related to this:
    https://msdn.microsoft.com/en-us/library/system.double.nan(v=vs.110).aspx and also
    https://msdn.microsoft.com/en-us/library/system.single.nan.aspx
    Maybe the convert here becomes NaN field which raised the exception.
    Best regards,
    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Inconsistent Floating Point Math and NaNs on Windows Laptops?

    All -
    I am seeing some very strange inconsistent floating point calculations on Windows Laptops, and I am wondering if anyone has any ideas. Read on, as (to me!) it's very interesting....
    I have attached a segment of our code, along with some sample output. Looking at the code and the output, it seems like it's totally impossible.
    With supposedly non-NaN and non-infinite double values, I am seeing unrepeatable and inconsistent math - the below example only illustrates one such case where we're seeing this behavior.
    If you look at the code below, you will see that I do things like:
    double rhoYo = ...  // some math
    double rho = ...  // exact same mathStrangely enough, I might get rhoYo = 1.51231231 etc and rho = NaN.
    If I reverse those lines (vertically), then again, rhoYo comes out good and rho comes out NaN; however, this is unpredictable and inconsistent. If I project a source point, get a destination point with NaNs as a result, and project the source again, the second destination point may be just fine. Matter of fact, i can put a loop in the code such as:
          double rho = Double.NaN;
          for( int i = 0; i < 10; i++ )
            rho = my_earthRad * my_F / Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n);
            if( ! Double.isNaN( rho ) )
              break;
            System.out.println("NaN'ed rho");
          }and rho will eventually become non-NaN (random # of iterations)!!
    How's that possible? Our code might be tromping on memory somewhere, but this sure seems crazy to me, especially considering that
    we're only using local variables. Anyone know of floating point errors on Windows Laptops?
    With the exact same codebase, this behavior ONLY happens on Windows Laptops, including brand new Dells, old Dells, IBM, Intel and AMD chips (I've tried several ;-). It does NOT happen on Mac or Linux, including the Linux side of a Linux/Windows dual-boot (where it does happen with the Windows side). Even more strangely, it does NOT happen with Windows desktops. I have tried several 1.5.x JVMs, webstart vs no webstart, etc, to no avail. Always and only on Windows Laptops.
    Please help.... ;-) and thanks in advance.
    Sample code:
    public class Projection
      protected Point2D.Double _project(Point2D.Double srcPt, Point2D.Double dstPt) {
        final double my_degToRad = Math.PI / 180.0;
        final double my_originLon = -95.0;
        final double my_originLonRad = my_originLon * my_degToRad;
        final double my_originLat = 25.0;
        final double my_originLatRad = my_originLat * my_degToRad;;
        final double my_stdLat1 = 25.0;
        final double my_stdLat1Rad = my_stdLat1 * my_degToRad;
        final double my_earthRad = 6371.2;
        final double my_n = Math.sin( my_stdLat1Rad );
        final double my_F = Math.cos( my_stdLat1Rad ) * Math.pow( Math.tan( Math.PI / 4.0 + my_stdLat1Rad / 2.0 ), my_n ) / my_n;
        final double my_rhoZero = my_earthRad * my_F / Math.pow( Math.tan( Math.PI / 4.0 + my_originLatRad / 2.0 ), my_n );
        if ( Double.isNaN( my_n ) || Double.isNaN( my_F ) || Double.isNaN( my_rhoZero )) {
          return new Point2D.Double(Double.NaN, Double.NaN);
        if( Double.isNaN( srcPt.x ) || Double.isNaN( srcPt.y ) )
            System.out.println("======= _project received a srcPt with NaNs. Returning NaN point.");
            Point2D.Double nanPoint = new Point2D.Double();
            nanPoint.x = nanPoint.y = Double.NaN;
            return nanPoint;
        if( Double.isInfinite( srcPt.x ) || Double.isInfinite( srcPt.y ) )
            System.out.println("======= _project received a srcPt with isInfinite. Returning NaN point.");
            Point2D.Double nanPoint = new Point2D.Double();
            nanPoint.x = nanPoint.y = Double.NaN;
            return nanPoint;
        //  Inputs are lon, lat degrees.
        final double lonRad = srcPt.x * my_degToRad;
        final double latRad = srcPt.y * my_degToRad;
        final double theta = my_n * (lonRad - my_originLonRad);
        // One Std lat -- tangential cone.
        final double rhoYo = my_earthRad * my_F / Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n);
        final double rho   = my_earthRad * my_F / Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n);
        // Computes kilometers in lambert space.
        dstPt.x = rho * Math.sin(theta);
        dstPt.y = my_rhoZero - (rho * Math.cos(theta));
        // WANK - Here's the problem!  These values shouldnt be NaN!
        if( Double.isNaN( dstPt.x ) || Double.isNaN( dstPt.y ) )
            System.out.println("======= A _projected dstPt has NaNs. Dumping...vvvvvvvvvvvvvvvvvvvvvvvvvvvv");
            if( Double.isNaN( dstPt.x ) )
                System.out.println("======= dstPt.x is NaN");
            if( Double.isNaN( dstPt.y ) )
                System.out.println("======= dstPt.y is NaN");
            System.out.println("======= my_stdLat1 = " + my_stdLat1 );
            System.out.println("======= my_n = " + my_n );
            System.out.println("======= my_originLonRad = " + my_originLonRad );
            System.out.println("======= my_F = " + my_F );
            System.out.println("======= my_earthRad = " + my_earthRad );
            System.out.println("======= lonRad = " + lonRad );
            System.out.println("======= latRad = " + latRad );
            System.out.println("======= theta = " + theta );
            System.out.println("======= Math.tan(Math.PI/4.0 + latRad/2.0) = " + Math.tan(Math.PI/4.0 + latRad/2.0) );
            System.out.println("======= Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n) = " + Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n) );
            System.out.println("======= rho = " + rho );
            System.out.println("======= rhoYo = " + rhoYo );
            System.out.println("======= Math.sin(theta) = " + Math.sin(theta) );
            System.out.println("======= dstPt.x = " + dstPt.x );
            System.out.println("======= Math.cos(theta) = " + Math.cos(theta) );
            System.out.println("======= my_rhoZero = " + my_rhoZero );
            System.out.println("======= (rhoYo * Math.cos(theta)) = " + (rho * Math.cos(theta)) );
            System.out.println("======= my_rhoZero - (rhoYo * Math.cos(theta)) = " + (my_rhoZero - (rho * Math.cos(theta)) ));
            System.out.println("======= dstPt.y = " + dstPt.y );
            System.out.println("======= A _projected dstPt had NaNs. Done dumping. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
        return dstPt;
    }And here's the sample output:
    ======= A _projected dstPt has NaNs. Dumping...vvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ======= dstPt.x is NaN
    ======= dstPt.y is NaN
    ======= my_stdLat1 = 25.0
    ======= my_n = 0.42261826174069944
    ======= my_originLonRad = -1.6580627893946132
    ======= my_F = 2.5946660025799146
    ======= my_earthRad = 6371.2
    ======= lonRad = -2.7564670759053924
    ======= latRad = 0.3730758324037379
    ======= theta = -0.4642057102537187
    ======= Math.tan(Math.PI/4.0 + latRad/2.0) = 1.4652768116539785
    ======= Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n) = 1.175224090766834
    ======= rho = NaN
    ======= rhoYo = 14066.369269924155
    ======= Math.sin(theta) = -0.44771270676160557
    ======= dstPt.x = NaN
    ======= Math.cos(theta) = 0.8941774612481554
    ======= my_rhoZero = 13663.082491950498
    ======= (rhoYo * Math.cos(theta)) = NaN
    ======= my_rhoZero - (rhoYo * Math.cos(theta)) = NaN
    ======= dstPt.y = NaN
    ======= A _projected dstPt had NaNs. Done dumping. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    HI JSchell (and others?) -
    I have created a simple example attached below, that when run repeatedly, does indeed generate spurious NaNs. I have made it as simple as possible. In the code, I use my own lon/lat binary data file, though I am sure any will do. Let me know if anyone wants that file.
    So the deal is that (with my data at least) this program should never generate NaN results. And if one runs it 25432 (eg: random #) times, it wont, but then the 25433th time, it will create NaNs, etc. ie: inconsistent NaN math results.
    As I said before, I have run this on old and new Dell laptops under Windows XP, using java 1.5_02, 1.5_04 and 1.5_08. The latest run was on a brand new Dell with a Intel Core Duo T2600 processor, running XP. If this is a result of the Pentium bug, one would think that would be fixed by now. I have NOT yet tested on AMD, though I will do that this afternoon.
    Remember, this ONLY happens with Windows Laptops.
    Any ideas anyone? Thanks in advance ;-)
    Here's the code that produces spurious NaNs:
    import java.awt.geom.Point2D;
    import java.io.DataInputStream;
    import java.io.EOFException;
    import java.io.File;
    import java.io.FileInputStream;
    public class FloatingPointTest2 implements Runnable
      private static final int NUM_ITERATIONS = 100000;
      private double _degToRad = Math.PI / 180.0;
      private double _originLon = -95.0;
      private double _originLat = 25.0;
      private double _originLonRad = _originLon * _degToRad;
      private double _originLatRad = _originLat * _degToRad;;
      private double _stdLat1 = 25.0;
      private double _stdLat1Rad = _stdLat1 * _degToRad;
      private double _earthRad = 6371.2;
      private double _n = _n = Math.sin( _stdLat1Rad );
      private double _F = Math.cos( _stdLat1Rad ) * Math.pow( Math.tan( Math.PI / 4.0 + _stdLat1Rad / 2.0 ), _n ) / _n;
      private double _rhoZero = _earthRad * _F / Math.pow( Math.tan( Math.PI / 4.0 + _originLatRad / 2.0 ), _n );
      private Point2D.Double _project( Point2D.Double srcPt, Point2D.Double dstPt )
        if( Double.isNaN( srcPt.x ) || Double.isNaN( srcPt.y ) )
          System.out.println( "FloatingPointTest2: received a NaN srcPt.  Skipping." );
          return new Point2D.Double( Double.NaN, Double.NaN );
        //  Inputs are lon, lat degrees.
        final double lonRad = srcPt.x * _degToRad;
        final double latRad = srcPt.y * _degToRad;
        final double theta = _n * ( lonRad - _originLonRad );
        double rho = _earthRad * _F / Math.pow( Math.tan( Math.PI / 4.0 + latRad / 2.0 ), _n );
        dstPt.x = rho * Math.sin( theta );
        dstPt.y = _rhoZero - ( rho * Math.cos( theta ) );
        return dstPt;
      public void doTest()
        DataInputStream instream = null;
        int thisRunNaNCount = 0;
        Point2D.Double tempPt = new Point2D.Double();
        Point2D.Double dstPt = new Point2D.Double();
        try
          instream = new DataInputStream( new FileInputStream( System.getProperty(
            "user.home" ) + File.separatorChar + "lonLatBinaryData.bin" ) );
          try
            while( true )
              double lon = instream.readDouble();
              double lat = instream.readDouble();
              if( Double.isNaN( lon ) || Double.isNaN( lat ) )
                continue;
              tempPt.x = lon;
              tempPt.y = lat;
              dstPt = _project( tempPt, dstPt );
              if( Double.isNaN( dstPt.x ) || Double.isNaN( dstPt.y ) )
                thisRunNaNCount++;
          catch( EOFException e )
    //        System.out.println( "End of file" );
          if( thisRunNaNCount > 0 )
            System.out.println( "thisRunNaNCount = " + thisRunNaNCount );
          instream.close();
        catch( Exception e )
          e.printStackTrace();
          System.exit( 1 );
      public void run()
        doTest();
      public static void main( String args[] )
        System.out.println( "Executing FloatingPointTest2." );
        for( int i = 0; i < NUM_ITERATIONS; i++ )
          FloatingPointTest2 test = new FloatingPointTest2();
          test.doTest();
    }

  • Opening new window from separate class

    Hello. I am currently writing a program that should be able to open a new window.
    Upon clicking a button in the first window, a second window should open up.
    The second window has to contain it's own buttons and methods, and upon
    clicking the button in the first window, it should close.
    So far I am only interested in making the button, and making the second class
    that will open when I click it. So far I've tried doing this in many different ways,
    but no matter what I do something either goes wrong, or it behaves weirdly.
    Class1: Contains the button that opens the second window
    /* Imports */
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class SecondWindowExample extends JFrame implements ActionListener {
        /* Initialization */
        private JButton xPress;
        /* My main method */
        public static void main (String[] Args) {
            SecondWindowExample frame = new SecondWindowExample();
            frame.setSize(200,120);
            frame.createGUI();
            frame.setVisible(true);
        /* The interface */
        private void createGUI() {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            Container window = getContentPane();
            window.setLayout(new FlowLayout());
            /* Button to open new window */
            xPress = new JButton("Press me");
            window.add(xPress);
            xPress.addActionListener(this);
        /* The actionPerformed for my actionlisteners
         * This only works when you press the button with your mouse */
        public void actionPerformed(ActionEvent e) {
            Object source = e.getSource();
            if (source == xPress) {
                /* Code to open and close second window */
    }Class2: Contains the second window to be opened by the first class
    It has to be able to contain it's own buttons and components
    import java.awt.*;
    import javax.swing.*;
    public class calcFunctions extends JFrame {
    public calcFunctions(){
            createNewGUI();
            setVisible(false);
            setTitle("Functions");
            setSize(300, 300);
            setLocation(200, 200);
            setResizable(false);
          private void createNewGUI() {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            Container window = getContentPane();
            window.setLayout(new FlowLayout());
    }Thanks in advance, any help is greatly appreciated.
    Sincerely, Ulverbeast

    I would make the second "window" a JPanel (or better a class that is able to create a JPanel), and display it in a modal JDialog. For e.g.,
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    public class SecondWindowExampleB extends JFrame implements ActionListener {
      /* Initialization */
      private JButton xPress;
      private JTextField sumField = new JTextField(10);
      /* My main method */
      public static void main(String[] Args) {
        SecondWindowExampleB frame = new SecondWindowExampleB();
        frame.setSize(200, 120);
        frame.createGUI();
        frame.setVisible(true);
      /* The interface */
      private void createGUI() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Container window = getContentPane();
        window.setLayout(new FlowLayout());
        /* Button to open new window */
        xPress = new JButton("Press me");
        window.add(xPress);
        xPress.addActionListener(this);
        sumField.setEditable(false);
        window.add(sumField);
      public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();
        CalcSumPanel calcSumPanel = new CalcSumPanel();
        JDialog dialog = new JDialog(this, "Calculate Sum", true);
        dialog.getContentPane().add(calcSumPanel);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        if (source == xPress) {
          sumField.setText("");
          dialog.setVisible(true);
          double sum = calcSumPanel.getSum();
          if (Double.compare(sum, Double.NaN) != 0) {
            sumField.setText(String.format("%.4f", sum));
    import java.awt.Window;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    class CalcSumPanel extends JPanel {
      private JTextField field1 = new JTextField(10);
      private JTextField field2 = new JTextField(10);
      private double sum = Double.NaN;
      public CalcSumPanel() {
        JButton calcSumBtn = new JButton("Calculate Sum");
        calcSumBtn.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            calcSumActionPerformed();
        add(field1);
        add(field2);
        add(calcSumBtn);
      private void calcSumActionPerformed() {
        try {
          double d1 = Double.parseDouble(field1.getText());
          double d2 = Double.parseDouble(field2.getText());
          sum = d1 + d2;
        } catch (NumberFormatException e) {
          sum = Double.NaN;
          JOptionPane.showMessageDialog(this, "Non-numeric data entered", "Input Error",
              JOptionPane.ERROR_MESSAGE);
          field1.setText("");
          field2.setText("");
        Window win = SwingUtilities.getWindowAncestor(this);
        win.dispose();
      public double getSum() {
        return sum;
    }

  • Updating the value in frame1 if changed in frame2

    hi,
    i have two frames....frame 1 has button calculate....frame 2 has button update which can update the data on frame two.....so the scene can be like that user might or might not want to update data on form 2 but in either case will calculate.....The approach that i was thinking of is that if i update it i store it in a JtextField2 on frame2 ...read the value in frame1 and compare with the value when updated wasnt hit....if values are same the result can be the standard value else it will store the value from JtextField.....now i have a question....
    1) is this approach fine??.....How can i tell calculate that Update was hit or not?????...is there any way by which i can get that a button in frame2 was hit or not???
    private void jButtonAction2Performed(java.awt.event.ActionEvent evt) {
                table1 t1 = new table1();                    //frame 2
                String a1 = t1.jTextField1.getText();   //frame2....reads the data from textfield 1
                String a4 = jTextField1.getText();  //frame1
               double anum1, anum4;
            anum1 = Double.parseDouble(a1);
             anum4 = Double.parseDouble(a4);
              double asum = anum1*anum4 ;
          System.out.println("i am NOT UPDATED value--> "+asum );
              String tabsum = t1.jTextField2.getText();    //text field2 has the updated value of the product with which asum will be compared
          double tsum1 = Double.parseDouble(tabsum);
         System.out.println("i am UPDATED value--> "+tsum1);for some reason it is not reading the content of jTextField2 of frame2 and showing the error -------> Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "jTextField2"
    Thanks

    or find a workaround?
    but since am using NETBEANS making SSCCE takes me even longer thats why i was trying to do it myselfThen don't use Netbeans.
    The point is to make a simple example that you understand. Once you get the simple example working you incorporate the knowledge you learned into your main program.
    It makes no difference if a component is defined on a second frame or the same frame. As long as you have the correct reference you can update it from any frame.
    We can't help you with your currently stated question, because the problem is probably contained outside the posted code. As I told you earlier, the problem is likely that you have an incorrect reference to one of your components. Since we can't see where you declared each variable we can't help you.

Maybe you are looking for

  • Create purchase order automatically from Sales order.

    Hi, I have ticked  Create purchase order automatically check box in item category TAS and TAB but still not able to generate Purchase Order automatically.??? any clue. thanks/ashu

  • Problems with renewing Skype Premium.

    I got a issue with my premium account, my account expire date 7th December 14. Skype attempt charge my credit card on 4th December and card was declined cause my card was changed. than I contact with skype customer service on 5th December. They advic

  • PDF Output of Spfli!

    Hi,    I've created an Input Node node_in which consists of the carrid of the table spfli. I've created a PDF interactive form which outputs all the details of spfli. Now my requirement is when i select a carrid in the view and say submit. It should

  • Change document icons during Document Refresh

    I'm working with a custom crawler, and one of the things I do is give the document a special (a.k.a "non-default") icon based on one of the property values. During the document refresh, if this property value has changed I would like the icon to chan

  • Hiding modified date in LinkListExplorer

    Hello How do I hide the "last modified" date in the LinkListExplorer layoutset?  I was expecting to find it in the "Visible Properties" of the Resource Renderer, but it's not there. Thanks! Chris EP6SP14 Message was edited by:         Christopher Gri