Scala Programming Language
  1. Scala Programming Language
  2. SI-4540

BigInt.isValidInt gives an incorrect result for large numbers

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0-M2
    • Component/s: Misc Library
    • Labels:
      None

      Description

      === What steps will reproduce the problem (please be specific and use wikiformatting)? ===

      scala> BigInt("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").isValidInt
      

      === What is the expected behavior? ===

      res1: Boolean = false
      

      === What do you see instead? ===

      res1: Boolean = true
      

      === Additional information ===

      From what I understood, the problematic code is in `ScalaNumericConversions.scala`:

      def isValidInt = isWhole && (toInt == toLong)
      

      which won't work for numbers larger than 64 bits.

      === What versions of the following are you using? ===

      • Scala: 2.8.1.r0-b20110222191246
      • Java: 1.6.0_18
      • Operating system: GNU/Linux

        Activity

        Hide
        Iulian Dragos added a comment -

        Paul, since it looks like you worked on these methods, can you please have a look?

        Show
        Iulian Dragos added a comment - Paul, since it looks like you worked on these methods, can you please have a look?
        Hide
        Paul Phillips added a comment -

        (In r24891) Makes BigInt's isValidThing methods make some kind of sense.
        I wish I hadn't written so much code for the numerical classes
        which languishes in git tributaries. Closes SI-4540, no review.

        Show
        Paul Phillips added a comment - (In r24891) Makes BigInt's isValidThing methods make some kind of sense. I wish I hadn't written so much code for the numerical classes which languishes in git tributaries. Closes SI-4540 , no review.
        Hide
        Dmitry Nadezhin added a comment -

        There are still other failures of ScalaNumericConversions.isValidXXX functions.

        def testDoubleIsValidByte() {
            assert((0.0).isValidByte)
        }
        def testLongIsValidByte() {
          assert(!(1L << 32).isValidByte)
        }
        

        The expected behaviour - these tests should pass.
        They fail in the master.

        Preparing a pull request...

        Show
        Dmitry Nadezhin added a comment - There are still other failures of ScalaNumericConversions.isValidXXX functions. def testDoubleIsValidByte() { assert((0.0).isValidByte) } def testLongIsValidByte() { assert(!(1L << 32).isValidByte) } The expected behaviour - these tests should pass. They fail in the master. Preparing a pull request...
        Hide
        Dmitry Nadezhin added a comment -

        Pull request #363
        https://github.com/scala/scala/pull/363
        fixes [RichDouble|RichFloat|RichLong].isValid[Byte|Short|Char|Int].

        Show
        Dmitry Nadezhin added a comment - Pull request #363 https://github.com/scala/scala/pull/363 fixes [RichDouble|RichFloat|RichLong] .isValid [Byte|Short|Char|Int] .

          People

          • Assignee:
            Paul Phillips
            Reporter:
            svasey
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development