Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining the float 3.4028235E38F gives the error "floating point number too large" #10148

Closed
scabug opened this issue Jan 15, 2017 · 8 comments
Closed
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jan 15, 2017

When you try to define a float with the value 3.4028235E38F you get "error: floating point number too large":

scala> 3.4028235E38F
<console>:1: error: floating point number too large
3.4028235E38F
^

whereas in java everything is fine:

java> 3.4028235E38F
java.lang.Float res0 = 3.4028235E38

you can even define it in scala with java methods:

scala>  java.lang.Float.intBitsToFloat(2139095039)
res0: Float = 3.4028235E38
@scabug
Copy link
Author

scabug commented Jan 15, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10148?orig=1
Reporter: Malte Limmeroth (molty)
Affected Versions: 2.11.8, 2.12.1

@scabug
Copy link
Author

scabug commented Jan 16, 2017

@som-snytt said:
Doubles are not floats.

scala> val d = java.lang.Double.valueOf("3.4028236E38").doubleValue
d: Double = 3.4028236E38

scala> d > Float.MaxValue
res0: Boolean = true

https://github.com/scala/scala/blob/v2.12.1/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala#L980

@scabug
Copy link
Author

scabug commented Jan 16, 2017

Malte Limmeroth (molty) said (edited on Jan 16, 2017 8:33:14 AM UTC):
sure, but 3.402823 5 E38 is a float.

scala> val f = java.lang.Float.valueOf("3.4028235E38")
f: Float = 3.4028235E38

@scabug
Copy link
Author

scabug commented Jan 16, 2017

@som-snytt said (edited on Jan 16, 2017 8:42:26 AM UTC):
Sorry for the typo, I meant the scanner is wrong to treat the value as a double.

scala> Float.MaxValue
res0: Float = 3.4028235E38

scala> val d = java.lang.Double.valueOf("3.4028235E38")
d: Double = 3.4028235E38

scala> d > Float.MaxValue
res1: Boolean = true

@scabug
Copy link
Author

scabug commented Jan 17, 2017

@som-snytt said:
Doing the simple thing at scala/scala#5648

@scabug
Copy link
Author

scabug commented Jan 17, 2017

@SethTisue said:
nice catch! funny this went unreported for so long

@scabug scabug closed this as completed Feb 16, 2017
@scabug
Copy link
Author

scabug commented Feb 19, 2017

@adriaanm said:
Followup for an edge case: scala/scala#5717

@scabug
Copy link
Author

scabug commented Feb 20, 2017

@som-snytt said:
"edge case" is a nice way of saying "he messed up trying to do the simple thing."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants