# Double.scalb fails for higher exponents.

XMLWordPrintable

#### Details

• Type: Bug
• Status: Closed
• Priority: P4
• Resolution: Not an Issue
• Affects Version/s: 8, 11, 16, 17
• Fix Version/s: None
• Component/s:
• Labels:
• Subcomponent:

#### Description

This bug occurs accross all versions i tried including 11

A DESCRIPTION OF THE PROBLEM :
Comparing
System.out.println("pow 2^max: "+Math.pow (2, 127));
System.out.println("sca 2^max: "+Math.scalb(1, 127));
yields
pow 2^max: 1.7014118346046923E38
sca 2^max: 1.7014118E38

but even worse,
System.out.println("pow 2^max: "+Math.pow (2, 128));
System.out.println("sca 2^max: "+Math.scalb(1, 128));
yields
pow 2^max: 3.4028236692093846E38
sca 2^max: Infinity
Wheras pow works until Double.MAX_EXPONENT, scalb continues to fail.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just write a class with main method containing the two lines in the description.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
2^127 shall be the same with pow and with scalb and i have good reasons to suspect,
that scalb is wrong.
2^128 until 2^Double.MAX_EXPONENT shall be finite as it is for pow, but not for scalb.

Note: scalb for float seems ok.
ACTUAL -
lower exponents until 127 inaccurate result, 128 to Double.MAX_EXPONENT infinite result.

---------- BEGIN SOURCE ----------
see above.
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
well, use the cumbersome pow. but this is not as exact.
I need in particular scalb(1,...) i.e. powers of 2 which shall be exact using scalb but not for pow.
So, for high precision computing: no workaround.
Well long to double.

FREQUENCY : always

#### Attachments

1. JI-9069314.iml
0.4 kB

#### People

Assignee:
Joe Darcy
Reporter:
Webbug Group