-
Notifications
You must be signed in to change notification settings - Fork 21
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
Boundary issue in Range #2535
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2535?orig=1
|
Trenton Lipscomb (trenton) said: |
@dcsobral said: Since we are subtracting from a positive or adding to a negative, we know there won't be an overflow. |
@dcsobral said: The patch is based on the idea of computing and keeping an Option of last. This means going through or testing for Option, which may introduce a small overhead on a few methods. On the other hand, it removes an "if" statement from foreach (byOne ranges not-affected) which might well make them faster. A possible optimization that was not pursued here might see the Range factory checking whether a Range has a "last" or not, and overriding the few methods affected by this with versions that make no checking at all. I'll do some benchmarking later, and update this ticket with the results, unless some kind soul beat me to it. :-) |
@dcsobral said: |
@dcsobral said: |
@dcsobral said: def testRange(i: Int, j: Int, k: Int) = {
var count = 0
for {
vi <- 0 to i
vj <- 0 to j
vk <- 0 to k
} { count += 1 }
} Then timed it with the following two settings: testRange(10, 1000, 10000)
testRange(10000, 1000, 10) Naturally, the former stresses |
@dcsobral said: |
@SethTisue said: |
@odersky said: |
@dcsobral said: final override def reverse: Range = if (length > 0) new Range.Inclusive(last, start, -step) else this I don't think there's any performance gain to be had by not creating the reverse of a zero-length range, so why change it from the original code that inverted end, start and negated step? |
@axel22 said: scala> import collection.immutable.Range
import collection.immutable.Range
scala> import collection.immutable.Range._
import collection.immutable.Range._
scala> new Range(0, 0, 5)
res0: scala.collection.immutable.Range = Range()
scala> new Range.Inclusive(0, 0, -5)
res1: Range.Inclusive = Range(0)
|
@paulp said: scala> (1 to 1 drop 1) == (1 to 1) It was introduced in r21349 which was to fix #2535, but led to #3529. |
@dcsobral said: I'm disgusted (with myself) to find I did not test "drop" in the scalacheck tests. It was my intention to test all methods that were directly affected by the change, but somehow I missed drop. |
The script
returns 0 where as
returns 4294967293. A helpful community member looked in Range and identified this
as the defect. We've reproduced it on Scala 2.7 and 2.8. Additional commentary is available at http://stackoverflow.com/questions/1635094
The text was updated successfully, but these errors were encountered: