From owner-freebsd-java Fri Jul 9 15:52:32 1999 Delivered-To: freebsd-java@freebsd.org Received: from ns.mt.sri.com (unknown [206.127.79.91]) by hub.freebsd.org (Postfix) with ESMTP id 71E3014E10; Fri, 9 Jul 1999 15:52:27 -0700 (PDT) (envelope-from nate@mt.sri.com) Received: from mt.sri.com (rocky.mt.sri.com [206.127.76.100]) by ns.mt.sri.com (8.8.8/8.8.8) with SMTP id QAA16326; Fri, 9 Jul 1999 16:52:21 -0600 (MDT) (envelope-from nate@rocky.mt.sri.com) Received: by mt.sri.com (SMI-8.6/SMI-SVR4) id QAA10373; Fri, 9 Jul 1999 16:52:19 -0600 Date: Fri, 9 Jul 1999 16:52:19 -0600 Message-Id: <199907092252.QAA10373@mt.sri.com> From: Nate Williams MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Martin Dieringer Cc: Nate Williams , Stephen McKay , freebsd-java@FreeBSD.ORG, java-port@FreeBSD.ORG Subject: Re: strange java calculation errors In-Reply-To: References: <199907091530.JAA05956@mt.sri.com> X-Mailer: VM 6.34 under 19.16 "Lille" XEmacs Lucid Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org > 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. I just spent a bit of time with this, and this is indeed a weird one. It seems to depend on how the storage is allocated, since if I calculate the value of denom as part of the local heap, it seems to work. Either that or I'm just getting lucky, because the code works if I calculate the exact same code and store it in a 'local' variable. (However, local variables are treated almost exactly the same as global variables in java.) In any case, it is indeed a bug, and one that I don't see on Solaris. Whether it's a bug in some FreeBSD library or in the way the VM operates is still unknown. If I had to make a guess, I'd start looking at the C interpreter, given that we are one of the only platforms that use it, while others use the assembly version. However, it's just a wild guess. Thanks again Martin! Nate > //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