Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Configuration.Debug

2955182Jul 15 2015 — edited Jul 15 2015

Greetings,

I am trying to understand the purpose of this code

private static double scale(double x, int n)

2363:   {

2364:    if (Configuration.DEBUG && abs(n) >= 2048)

2365:    throw new InternalError("Assertion failure");

2366:    if (x == 0 || x == Double.NEGATIVE_INFINITY

2367:   || ! (x < Double.POSITIVE_INFINITY) || n == 0)

2368:    return x;

2369:    long bits = Double.doubleToLongBits(x);

2370:    int exp = (int) (bits >> 52) & 0x7ff;

2371:    if (exp == 0) // Subnormal x.

2372:   {

2373:    x *= TWO_54;

2374:    exp = ((int) (Double.doubleToLongBits(x) >> 52) & 0x7ff) - 54;

2375:   }

2376:    exp += n;

2377:    if (exp > 0x7fe) // Overflow.

2378:    return Double.POSITIVE_INFINITY * x;

2379:    if (exp > 0) // Normal.

2380:    return Double.longBitsToDouble((bits & 0x800fffffffffffffL)

2381:   | ((long) exp << 52));

2382:    if (exp <= -54)

2383:    return 0 * x; // Underflow.

2384:    exp += 54; // Subnormal result.

2385:    x = Double.longBitsToDouble((bits & 0x800fffffffffffffL)

2386:   | ((long) exp << 52));

2387:    return x * (1 / TWO_54);

2388:   }

I do not understand what  Configuration.DEBUG is doing.  Simple example will be helpful. 

The above masterpiece comes from the following link:   http://developer.classpath.org/doc/java/lang/StrictMath-source.html

I am attempting it to translate it (configuration.debug as well) to c++ and possible use it  in other java applications.

Thanks in advance.

Adam

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 12 2015
Added on Jul 15 2015
2 comments
448 views