You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dice.probabilities crashes if there are too many dice.
To Reproduce:
letdice=Dice(.d100, count:5)
dice.probabilities
Expected behavior:
This should actually return the probabilities.
Stack trace:
I don't have a stack trace, because I'm reporting this bug way after I encountered it, but I know that the problem is an overflow when multiplying Chances together (multiplying the two denominators overflows).
Implementation Details:
Development OS: macOS 11.0.1 (irrelevant)
Target OS: iOS 13.6 (irrelevant)
DiceKit Version: 0.24.1
Additional context:
I believe I had already started working on this problem in the bigint branch, but didn't make a PR because it made small calculations very slow. I'm not sure how to have a "dynamic" conversion between Swift.Int and BigInt, which would make this a lot easier.
The text was updated successfully, but these errors were encountered:
Ah! Int has a static method func multipliedReportingOverflow(by other: Int) -> (partialValue: Int, overflow: Bool) (link to Apple docs). This will let us try to do the multiplication, but catch an overflow and either fail in a controlled way or switch to BigInt.
Alright, so apparently what e05a269 (now decfaae, since I rebased) did was prevent crashes by approximating whenever the previous version would crash. This also has the advantage of not slowing down when large calculations would otherwise be performed (as would be the case if it automatically switched to using BigInt). I'm not sure which option we want to go with
Describe the bug:
Dice.probabilities
crashes if there are too many dice.To Reproduce:
Expected behavior:
This should actually return the probabilities.
Stack trace:
I don't have a stack trace, because I'm reporting this bug way after I encountered it, but I know that the problem is an overflow when multiplying
Chance
s together (multiplying the two denominators overflows).Implementation Details:
Additional context:
I believe I had already started working on this problem in the
bigint
branch, but didn't make a PR because it made small calculations very slow. I'm not sure how to have a "dynamic" conversion betweenSwift.Int
andBigInt
, which would make this a lot easier.The text was updated successfully, but these errors were encountered: