Community
Participate
Working Groups
The JLS3 states that the floating-point literals can now have a binary exponent. Here are the rules to create a floating-point literal: FloatingPointLiteral DecimalFloatingPointLiteral HexadecimalFloatingPointLiteral DecimalFloatingPointLiteral: Digits . Digitsopt ExponentPartopt FloatTypeSuffixopt . Digits ExponentPartopt FloatTypeSuffixopt Digits ExponentPart FloatTypeSuffixopt Digits ExponentPartopt FloatTypeSuffix ExponentPart: ExponentIndicator SignedInteger ExponentIndicator: one of e E SignedInteger: Signopt Digits Sign: one of + - FloatTypeSuffix: one of f F d D HexadecimalFloatingPointLiteral: HexSignificand BinaryExponent FloatTypeSuffixopt HexSignificand: HexNumeral HexNumeral . 0x HexDigitsopt . HexDigits 0X HexDigitsopt . HexDigits BinaryExponent: BinaryExponentIndicator SignedInteger BinaryExponentIndicator: one of p P HexNumeral: 0 x HexDigits 0 X HexDigits HexDigits: HexDigit HexDigit HexDigits HexDigit: one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F The unsupported format is HexadecimalFloatingPointLiteral.
Created attachment 14584 [details] Apply on HEAD Here is a zipped file that contains a patch for the scanner, problem reporter, IProblem and messages.properties. It seems to work fine. I will write more tests. The problem remains that the compiler requires 1.5 libraries in order to compute the new floating-point literal constants.
Created attachment 14586 [details] Apply on FloatLiteral and DoubleLiteral Apply the two patches on FloatLiteral and DoubleLiteral. It is a hack to compute the float or double constant when the compiler runs on 1.4 libraries.
I forgot to change the FloatLiteral class. Replace: try { computedValue = Float.valueOf(String.valueOf(source)); } catch (NumberFormatException e) { computedValue = getFloatingPoint(); } with: try { computedValue = Float.valueOf(String.valueOf(source)); } catch (NumberFormatException e) { try { computedValue = getFloatingPoint(); } catch(NumberFormatException e1) { return; } }
First draft released. We will review the constant computation in case the libraries used to compile are < 1.5.
I will add scanner tests to be sure that the new float and double literals are propertly scanned.
This change requires changes in the ToolFactory. We have indeed three modes: - compliance 1.5 and source < 1.5: => This is one token - compliance 1.4 and source < 1.5: => This is mode than one token - compliance 1.5 and source 1.5: => This is one token
Fixed and released in HEAD. Regression tests added.
Verified in I200409231635.
Reopening to include patches for improved handling of hex floating point literals.
Created attachment 14808 [details] Patch to o.e.jdt.core project The patch replaces Util.getFloatingPoint(char[]) with FloatUtil.valueOfHexDoubleLiteral(char[]) and FloatUtil.valueOfHexFloatLiteral(char[]). These new methods handle all the corner cases, including rounding, overflow, and gradual underflow.
Created attachment 14809 [details] Patch to o.e.jdt.core.tests.compiler Patch adds a new test, InternalHexFloatTest, to test the new internal FloatUtil class's methods.
Verified for 3.1M3 with build I20041101