This page is no longer maintained — Please continue to the home page at www.scala-lang.org

NaN toLong : Compiler bug?

3 replies
Lg
Joined: 2011-03-09,
User offline. Last seen 42 years 45 weeks ago.

scala> val d = Double.NaN
d: Double = NaN

scala> d toLong
res1: Long = 0

Would be better is this raised an exception instead of silently
returning 0.

Best,
Lal

Tom Switzer
Joined: 2011-07-19,
User offline. Last seen 42 years 45 weeks ago.
Re: NaN toLong : Compiler bug?
Much like the other discussion, this is consistent with Java and is what the JVM does. What I got from the other discussions (eg. the Unsigned Arithmetic one) was that Scala does what Java/the JVM do when it comes to primitive types and arithmetic and conversions. I'd assume the same arguments there would apply here.

On Mon, Nov 7, 2011 at 10:53 AM, Lg <lal [dot] george [at] gmail [dot] com> wrote:
scala> val d = Double.NaN
d: Double = NaN

scala> d toLong
res1: Long = 0

Would be better is this raised an  exception instead of silently
returning 0.

Best,
   Lal


Tom Switzer
Joined: 2011-07-19,
User offline. Last seen 42 years 45 weeks ago.
Re: NaN toLong : Compiler bug?
Also, I think someone mentioned in another thread that they thought Scala's documentation focused too much on easing Java users into Scala. So, while these types of problems (unsigned arithmetic, upconverting to int, NaN -> 0, etc) make sense to a Java user, they are clearly surprising to many other people. Perhaps this is yet another symptom of the problem of catering to Java converts and there should be more mention of this kind of obvious-if-your-a-java-programmer-not-so-obvious-otherwise behaviour in the documentation.
heathermiller
Joined: 2011-04-27,
User offline. Last seen 22 weeks 12 hours ago.
Re: NaN toLong : Compiler bug?

Hi Tom,

Thanks for sharing your thoughts on the flavor of Scala's documentation. We'd actually like to produce more documentation catered to users from Python/Ruby/C/C++, etc, but currently the vast majority of people producing documentation come from Java.

…It'd be helpful if more non-Java people stepped up to help out in pointing out these types of things that cause confusion by dropping these kinds of helpful hints into the API documentation. I'd immediately pull in this type of doc contribution if you (or others) were to submit such a thing as a pull request.

Cheers,
Heather

On Nov 7, 2011, at 5:09 PM, Tom Switzer wrote:

> Also, I think someone mentioned in another thread that they thought Scala's documentation focused too much on easing Java users into Scala. So, while these types of problems (unsigned arithmetic, upconverting to int, NaN -> 0, etc) make sense to a Java user, they are clearly surprising to many other people. Perhaps this is yet another symptom of the problem of catering to Java converts and there should be more mention of this kind of obvious-if-your-a-java-programmer-not-so-obvious-otherwise behaviour in the documentation.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland