?
Solved

JRE Version Inconsistency between Math classes

Posted on 2003-03-11
9
Medium Priority
?
209 Views
Last Modified: 2013-12-29
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
Comment
Question by:Rezantis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 8117028
> 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
 
LVL 92

Expert Comment

by:objects
ID: 8117210
System.getProperty("java.version") can be used to determine the vm version.
0
 

Author Comment

by:Rezantis
ID: 8117603
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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 92

Expert Comment

by:objects
ID: 8117637
> 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
 
LVL 92

Expert Comment

by:objects
ID: 8117692
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
 

Author Comment

by:Rezantis
ID: 8117740
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
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 8117802
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
 

Author Comment

by:Rezantis
ID: 8117852
That works . . . I can go with this.  Thanks much for your time.  ^^
0
 
LVL 92

Expert Comment

by:objects
ID: 8117919
Happy to help :)

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

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question