Why does Scala 2.11.2 give me compilation error for floating point number in scientific notation?
Asked Answered
L

1

10

I've just recently updated a Scala project from 2.10 to 2.11.2.

For the following code:

 if( x < 1.e-150 ) // conditional ops... 

I'm getting the error

e is not a member of Int

Previously scientific notion has worked ok. I suspect it is not a 2.11 thing but more likely some weirdness with the upgrade which was for most part just a case of updating the sbt file to have:

scalaVersion := "2.11.2"

where it was previously:

scalaVersion := "2.10.3"

I can't think of what might be causing this. All I know is that it was working fine under 2.10.

Has anyone seen this issue before or can suggest a fix? ( or new line of enquiry!)

I'm using JDK 1.7.0_21 and sbt.version=0.13.5.

Any help or ideas appreciated.

Lubric answered 12/9, 2014 at 10:26 Comment(0)
B
18

The syntax for scientific notation is Scala is a floating point number followed by e (or E) and the exponent. The issue you're seeing is a change in what counts as a floating point number, and doesn't properly have anything to do with the syntax for scientific notation (although that does contribute to the confusingness of the error message).

You can confirm this by firing up a 2.10.4 REPL with -deprecation turned on:

scala> val x = 1.
<console>:1: warning: This lexical syntax is deprecated.  From scala 2.11, a dot
         will only be considered part of a number if it is immediately followed
         by a digit.
       val x = 1.
               ^

And sure enough, in 2.11 this just won't compile at all.

You can accomplish exactly the same thing by writing either 1e-150 or 1.0e-150, both of which will work in either 2.10 or 2.11.

Bruiser answered 12/9, 2014 at 10:40 Comment(2)
16 votes for a duplicate, or ... 16 votes for Travis?Palladin
@som-snytt: Is this a duplicate? If it's "votes for Travis" I'd also like some more attention for my Shapeless question last night please.Bruiser

© 2022 - 2024 — McMap. All rights reserved.