• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

JRE Version Inconsistency between Math classes

I'm writing a java applet where I need to be able to get perfectly consistent results for any given set of calculations, no matter what version of the JRE is on the client computer.  This is mildly problematic thanks to the fact that Sun has renamed the Math class to the StrictMath class, and created a new version of the Math class for later versions of the JRE.  

My applet provides consistent results for anyone using a version of java above 1.3.0 (the newer version of the Math class), and consistent results for anyone using a version of java below 1.3.0 (the old version of the Math Class that got renamed to StrictMath); but these two sets of results, while consistent, are different from each other.

Does anyone have any suggestions as to how to solve this?  Precision isn't vital to the results, but consistency is.
 
0
Rezantis
Asked:
Rezantis
  • 6
  • 3
1 Solution
 
objectsCommented:
> is mildly problematic thanks to the fact that Sun has
> renamed the Math class to the StrictMath class

Are you sure about that, as it is not my understanding.
Do you have a reference confirming that?

> but these two sets of results, while consistent, are different from each other.

This sort of implies that Sun didn't rename Math to StrictMath doesn't it?

afaik you can only get consistency using StrictMath. ie. you cannot support earlier vm versions <1.3 (unless you use your own Math implementation).


0
 
objectsCommented:
System.getProperty("java.version") can be used to determine the vm version.
0
 
RezantisAuthor Commented:
Here's a reference here; it's down the bottom:  http://java.sun.com/j2se/1.3/docs/guide/performance/speed.html

The pre-1.3.0 Math class was renamed to StrictMath thereafter.  Sorry, I probably wasn't clear . . .

I'm using the Math class all the way through here as a blanket thing, not the StrictMath class.  I can determine the version of the JRE present . . .  However, if I try and use the StrictMath class in the project I can't run it under older versions of the JRE, as the class isn't present when the applet tries to load it.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
> I'm using the Math class all the way through

If you want consistency of results then shouldn't you be using StrictMath? That was my understanding of its purpose.
0
 
objectsCommented:
Not sure on Sun's semantics :) Here's another reference which seems to imply the classes differ:

http://java.sun.com/j2se/1.3/docs/guide/lang/enhancements.html

Does the pre-1.3 Math class provide consistent results with the StrictMath class?

If so, you could create a wrapper class that channelled the call to the correct class depending on the vm version.


0
 
RezantisAuthor Commented:
You're right, that does imply that.  ^^;

I can't use StrictMath for consistency, though, because I need this to work on older versions of the JRE . . . and as far as I've been able to tell, pre 1.3 Math class does provide consistent results.  If it does differ, it's minor enough that it's not shown up as a problem to me befoer.  ^^  

How would I go about creating a wrapper class to do that without throwing the class loading exceptions?  It's probably not that complicated in it's calls, I'm just not sure how to load one class and not another.
0
 
objectsCommented:
Something like:

public class MyMath
{
   public static boolean v13 = true;

   public static double abs(double a)
   {
      if (v13)
      {
         return Math.abs(a);
      }
      else
      {
         return StrictMath.abs(a);
      }
    }

     ...
0
 
RezantisAuthor Commented:
That works . . . I can go with this.  Thanks much for your time.  ^^
0
 
objectsCommented:
Happy to help :)

http://www.objects.com.au/staff/mick
Brainbench MVP for Java 1
http://www.brainbench.com
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now