-
Notifications
You must be signed in to change notification settings - Fork 21
'(BigDecimal(1) to BigDecimal(s"1.${"0" * 32}1") by BigDecimal(s"0.${"0" * 33}1")).toList' cause infinite loop in Scala 2.13.0-M5 #11152
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
Comments
I forgot .linesIterator was removed entirely in 2.13 and won't return until 2.13.0-RC1
it's been a long day. I seem to have pushed a number of commits to various repos referencing "11152" (this bug) that should have referenced #11125. sigh |
This reverts commit ace11c0. We did the same thing before in 3a1332c to avoid problems such as scala/bug#4981 (back then) and scala/bug#11152 (now).
The issues surrounding
The previous solution to these issues was to use the However, the fix #6882 also isn't a great solution as evidenced by this bug, which is that ranges no longer work as expected. To craft a solution, we need to return to the problematic points again and see what we can do to mitigate as many of them as possible. My suggestion involves thinking more deeply about what the difference is between runaway multiplication, which motivates a fixed In general, if you can afford M bytes of memory for a number, you can probably also afford 2M, so long as you don't keep doubling with each extra operation. That is, after n operations, you still want the memory to be O(M), not O(2n M). You also don't want the memory usage to be randomly gigantic if you're adding numbers of vastly different scales. So this suggests to me that the following behavior may be a reasonable compromise:
There are ways in which this could go wrong--large trees of mixed addition and multiplication could yield numbers that gradually increase and decrease in size, extending precision without bound. However, if you're doing this peculiar operation, you may well want the representation to grow without bound to try to capture the actual value. Another aspect to consider is whether an explicit
This suggests that perhaps an explicit I haven't looked into whether the operations described here can be computed efficiently so as to not substantially slow down Alternatively, there are two simpler solutions that we could try:
I can, if desired, implement any of these things, or perhaps others can. I'd also like some second opinions from people who do this sort of thing more frequently (e.g. @non - you came up with the original compromise; what do you think now?; @NthPortal and @plokhotnyuk and anyone else?). |
IMO more practical would be depreciation for usage of floating point ranges and make them throwing exception when incremented value is equal to the previous one. |
Another possibility is to leave the current behavior alone, but add another set of operations for unbounded addition and subtraction, e.g. |
@plokhotnyuk - We already got rid of IEEE754 because there's no way to do ranges properly; but with The test for whether any incrementing is happening is not entirely trivial, but I guess it could check that it works for the two endpoints. I agree that this would be another way to do it. |
@Ichoran it would be great if you could take care of this one, time permitting |
@plokhotnyuk - Are you willing to create a PR that checks Note that the case of partial truncation needs to be considered also. For instance, 1 to 2 by 0.25 gives five values at full precision, but either 6 or 4 with only 2 digits of precision, depending on whether 0.25 is rounded down to 0.2 or up to 0.3. |
@Ichoran sorry, my shallow understanding of Scala library is not giving me any chance do to it in time for upcoming 2.13.0-RC1 |
All right, I'll take care of it. |
Spire unit testing also happens to trip on this. typelevel/spire#759 |
fixed by scala/scala#7670 |
I think there are two reasons.
not infinite loop when
toArray
becausetoArray
does not useNumericRange#iterator
.toArray
result different from Scala 2.12.x due to MathContext changesBigDecimal#+
difference Scala 2.12 <=> 2.13DECIMAL128
is default MathContext inscala.BigDecimal
https://github.com/scala/scala/blob/v2.12.6/src/library/scala/math/BigDecimal.scala#L30scala.BigDecimal#equals
usejava.math.BigDecimal#compareTo
notjava.math.BigDecimal#equals
The text was updated successfully, but these errors were encountered: