JLS 3.10.2 -- Exposition of hexadecimal f.p. literals

Alex Buckley alex.buckley at oracle.com
Fri Oct 25 00:04:38 UTC 2019


On 10/24/2019 1:38 PM, Joe Darcy wrote:
> To make an explicit statement about the value of a floating-point 
> literal, I suggest after the sentence
> 
> "A floating-point literal may be expressed in decimal (base 10) or 
> hexadecimal (base 16). "
> 
> adding something like
> 
> "The exact numerical value of a decimal floating-point literals is
> 
>      decimal_sequence * 10 ^ exponent
> 
> The exact numerical value of a hexadecimal floating-point literal is
> 
>      hex_sequence * 2 ^ exponent
> 
> The conversion of the exact numerical value to a particular 
> floating-point value is handled as if by Float.valueOf or Double.valueOf 
> for literals of type float and double, respectively."

This is a good start, but needs tightening up. Please consider this text 
as if you're seeing it for the first time, bearing in mind that it's 
defining terms which map to productions in the grammar immediately after.

-----
A floating-point literal may be expressed in decimal (base 10) or 
hexadecimal (base 16).

For decimal floating-point literals, at least one digit (in either the 
whole number or the fraction part) and either a decimal point, an 
exponent, or a float type suffix are required. All other parts are 
optional. The exponent, if present, is indicated by the ASCII letter e 
or E followed by an optionally signed integer.

The exact numerical value of a decimal floating-point literal is:
   decimal_sequence * 10 ^ exponent

For hexadecimal floating-point literals, at least one digit is required 
(in either the whole number or the fraction part), and the exponent is 
mandatory, and the float type suffix is optional. The exponent is 
indicated by the ASCII letter p or P followed by an optionally signed 
integer.

The exact numerical value of a hexadecimal floating-point literal is:
   hex_sequence * 2 ^ exponent

Underscores are allowed as separators between digits that denote the 
whole-number part, and between digits that denote the fraction part, and 
between digits that denote the exponent.
-----

- What is "decimal_sequence"? The answer must be in terms of the 
artifacts mentioned in the immediately preceding paragraph -- or modify 
the grammar to introduce new artifacts that can be described in the 
narrative.

- Similarly for "hex_sequence".

- A decimal f-p literal need not include the exponent part, so the 
definition can't just assume "exponent" is known.

- For a hexadecimal f-p literal, the questioner mentioned that the 
(mandatory) exponent is "in base 2", but there is no requirement to 
write the exponent in binary. There's lots of potential for confusion 
here. What are some examples of hexadecimal f-p literals?

In the JLS, it is often the most fundamental descriptions and operations 
that are the hardest to phrase. We're not there yet for f-p literal values.

Alex


More information about the jls-jvms-spec-comments mailing list