Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Jul 1999 00:01:41 +0200 (CEST)
From:      Martin Dieringer <martin@dieringe.dialup.fu-berlin.de>
To:        Nate Williams <nate@mt.sri.com>
Cc:        Stephen McKay <syssgm@detir.qld.gov.au>, freebsd-java@FreeBSD.ORG
Subject:   Re: strange java calculation errors 
Message-ID:  <Pine.BSF.4.10.9907092353330.44163-100000@ThinkPad.nowhere.local>
In-Reply-To: <199907091530.JAA05956@mt.sri.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 9 Jul 1999, Nate Williams wrote:

> > >I use the latest jdk1.1.8_ELF.V99-6-3.tar.gz with applied net-patch.
> > >On a few-weeks-old 3.2-STABLE.
> > >I have strange arithmetic errors.  I sometimes get NaN-s
> > >and very big numbers (...E306) which don't appear on any other machine/os
> > >and don't appear with the linux-jdk1.2 pre-v2.
> > 
> > We are getting occasional failures in the GregorianCalendar routines.
> > For some inexplicable reason it is full of floating point calculations.
> > Every so often, one of these calculations is wildly incorrect, and we
> > get an ArrayIndexOutOfBoundsException (when looking up the month in
> > an array).  We have a little bit of trace showing one of the statements
> > returning 0 or 9223372036854775807 sometimes (instead of an expected
> > result of a few thousand).
> 
> As always, unless we can reproduce this bug, it's almost impossible to
> track down.  If you can provide us a test case, there is a very good
> chance we can fix this.


Ok, I set up a sample program. I think it needs to be an awt-application.
I don't get any errors without setVisible(), but with a visible frame
I get errors every few seconds. It has to be a Thread, too, I think.
Probably you know how to track this down further.
Martin


//BugTest.java ----------------------------------------------

import java.awt.*;
import java.util.Random;

public class BugTest extends Frame implements  Runnable
{

    Random random = new Random();

    double weight;
    double denom;
    double meatEnergy;
    double weightgain;

    public BugTest(){
	setSize(100,100);
 	setVisible(true);
    }


    public void run(){
	while (true){
	    try{
		calc();
	    } catch (ArithmeticException a) {
		System.err.println("weight: "+ weight + "\ndenom: "+ denom);
		a.printStackTrace();
	    }
	}
    }

    void calc() throws ArithmeticException {
	weight =  random.nextDouble()*10.;
	meatEnergy= 0.029994563969828213;
	denom = (.0836 * Math.pow(weight, 1.37));
	weightgain = .2849372 * meatEnergy * weight / denom;
	if (weightgain > 1000.) 
		throw new ArithmeticException("weightgain "+weightgain);
    }	

    public static void main(String args[]){
	BugTest bug = new BugTest();
	Thread bugThread = new Thread(bug);
	bugThread.setPriority(Thread.MIN_PRIORITY);
	bugThread.start();
    }
    
}

//------------------------------------------------------



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.9907092353330.44163-100000>