classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Quadratic and cubic equations


From: Sascha Brawer
Subject: Fwd: Quadratic and cubic equations
Date: Thu, 8 Jan 2004 16:27:27 +0100

---------------- Begin Forwarded Message ----------------
Subject: Re: Quadratic and cubic equations
Date Sent: Thursday, January 8, 2004 12:18 PM
From: Brian Gough <address@hidden>
To: Sascha Brawer <address@hidden>
CC: Mark Wielaard <address@hidden>, Michael Koch <address@hidden>

Sascha Brawer writes:
 > I suspect that the problem is the test for (disc == 0) in gsl/poly/
 > solve_quadratic.c, line 61. With the Java version of your code, we get a
 > very small negative number in gcj (the Java front-end for the GCC) on IA-
 > 32, and exactly 0.0 with some other Java Virtual Machines.

The coefficient 0.1 does not have an exact representation in binary,
so the number used will depend on the precision and the rounding
mode.  This will cause different results.

I suspect that GCJ on Intel uses the 80-bit extended-precision
floating point registers (which are the gcc default, in C also) while
the other virtual machines probably use strict double-precision.

I don't know much about GCJ but I'm sure the developers are aware of
the issue, so there may be an option to control it.

 > Could it be that the test for (disc == 0) should actually be replaced by
 > something like (fabs(disc - 0.0) < EPSILON)? If so, which value is
 > appropriate for EPSILON?

The best value is 0, as there is no natural choice for epsilon (it
introduces an arbitrary constant).

My recommendation: choose test coefficients which are exact in binary
(e.g. in this case multiply the polynomial by 5) to avoid the problem.

regards,

-- 
Brian Gough

Network Theory Ltd -- Publishing Free Software Manuals
15 Royal Park
Bristol BS8 3AL
United Kingdom

Tel: +44 (0)117 3179309
Fax: +44 (0)117 9048108
Web: http://www.network-theory.co.uk/


----------------- End Forwarded Message -----------------






reply via email to

[Prev in Thread] Current Thread [Next in Thread]