public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug java/23432] New: Incorrect parsing and rounding off of large floating-point literals
@ 2005-08-17  6:12 rmathew at gcc dot gnu dot org
  2005-08-17  6:14 ` [Bug java/23432] " rmathew at gcc dot gnu dot org
  2005-08-17 12:19 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 4+ messages in thread
From: rmathew at gcc dot gnu dot org @ 2005-08-17  6:12 UTC (permalink / raw)
  To: java-prs

According to JLS 3.10.2:

  http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.2

large (in the number of characters, not the value) floating-point literal
tokens must be rounded off to the nearest representable value.

The current mainline (4.1.0 20050817) does not do this. See the attached
testcase. Both Jikes and Sun javac (1.5.0.03) correctly compile this class,
while GCJ gives:
---------------------------------- 8< ----------------------------------
~/src/tmp > $MYGCJ --syntax-only Snafu.java
Snafu.java:3: error: Numeric overflow for 'int' literal.
  double foo =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882;
                                                                               
                                                                               
                                                                               
                                  ^
Snafu.java:4: error: Class or interface declaration expected.
}
   ^
2 errors
---------------------------------- 8< ----------------------------------

See also Jacks testcase 3.10.2-round-6 (and other such tests). Eric
Blake says:
---------------------------------- 8< ----------------------------------
>>What is the actual length of the longest of the tokens in question
>>allowed by the JLS?
> 

Literal token length is technically unlimited - the longest string
possible that still parses as a floating point number without causing
overflow or underflow must be parsed as such.  However, there IS a fixed
maximum length of significant characters at which the decision of which
exact 2's complement number the decimal string will round to (or can be
determined simply by scanning for the first non-zero digit after that
length); this limit is determined by the actual base-10 representation of
the 1ulp 2's complement denormal.  I wrote the jacks tests in question,
which purposefully use a 800+ character mantissa of the halfway point
between the smallest two denormals, as the longest string of non-zero
characters where rounding can make a difference.  I don't remember the
exact number of significant characters, but you can reverse engineer that
from the jacks test.  Remember that you need to strip leading zeros of
both the mantissa and exponent before starting to count characters towards
the limit; fortunately, Java has no way to stringize a literal so you only
need to obtain the exact value rather than preserve the original string.

On the other hand, since every possible double can be expressed with a
decimal string with a maximum of 24 characters (and even fewer characters
with hex-float literals in Java 1.5 syntax), only brain-dead compiler test
suites are ever likely to give you a literal with more than 256 characters :)
---------------------------------- 8< ----------------------------------
(Ref.: http://gcc.gnu.org/ml/java-patches/2005-q3/msg00218.html)

-- 
           Summary: Incorrect parsing and rounding off of large floating-
                    point literals
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rmathew at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23432


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug java/23432] Incorrect parsing and rounding off of large floating-point literals
  2005-08-17  6:12 [Bug java/23432] New: Incorrect parsing and rounding off of large floating-point literals rmathew at gcc dot gnu dot org
@ 2005-08-17  6:14 ` rmathew at gcc dot gnu dot org
  2005-08-17 12:19 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 4+ messages in thread
From: rmathew at gcc dot gnu dot org @ 2005-08-17  6:14 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From rmathew at gcc dot gnu dot org  2005-08-17 06:14 -------
Created an attachment (id=9509)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9509&action=view)
Testcase that demonstrates the problem.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23432


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug java/23432] Incorrect parsing and rounding off of large floating-point literals
  2005-08-17  6:12 [Bug java/23432] New: Incorrect parsing and rounding off of large floating-point literals rmathew at gcc dot gnu dot org
  2005-08-17  6:14 ` [Bug java/23432] " rmathew at gcc dot gnu dot org
@ 2005-08-17 12:19 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-17 12:19 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-17 12:19 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |rejects-valid
   Last reconfirmed|0000-00-00 00:00:00         |2005-08-17 12:19:30
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23432


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug java/23432] Incorrect parsing and rounding off of large floating-point literals
       [not found] <bug-23432-8271@http.gcc.gnu.org/bugzilla/>
@ 2007-02-16 21:48 ` tromey at gcc dot gnu dot org
  0 siblings, 0 replies; 4+ messages in thread
From: tromey at gcc dot gnu dot org @ 2007-02-16 21:48 UTC (permalink / raw)
  To: java-prs



------- Comment #3 from tromey at gcc dot gnu dot org  2007-02-16 21:48 -------
Fixed on svn trunk.


-- 

tromey at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at gcc dot gnu dot
                   |                            |org
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23432


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-02-16 21:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-17  6:12 [Bug java/23432] New: Incorrect parsing and rounding off of large floating-point literals rmathew at gcc dot gnu dot org
2005-08-17  6:14 ` [Bug java/23432] " rmathew at gcc dot gnu dot org
2005-08-17 12:19 ` pinskia at gcc dot gnu dot org
     [not found] <bug-23432-8271@http.gcc.gnu.org/bugzilla/>
2007-02-16 21:48 ` tromey at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).