zackradisic / aussieplusplus

Programming language from down under
aussieplusplus.vercel.app
609 stars 15 forks source link

thread 'main' panicked at 'cannot sample empty range' #41

Open bbrk24 opened 2 years ago

bbrk24 commented 2 years ago

Apparently ChuckSomeDice really doesn't like non-integers, as this code:

G'DAY MATE!
IMPOHT ME FUNC ChuckSomeDice;
ChuckSomeDice(0, 0.5);
CHEERS C***!

outputs the following error:

thread 'main' panicked at 'cannot sample empty range', /Users/zackradisic/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.8.4/src/rng.rs:134:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
bbrk24 commented 2 years ago

Actually, I think I can get a PR out for this.

dspingarn commented 2 years ago

I know there's a PR for this, but just want to add that ChuckSomeDice is basically a fancy alias for rand() which only takes integers anyway (specifically, the datatype is an i64) so you'd expect 0.5 to truncate to just 0, per integer truncating. The bug, of course, is that ChuckSomeDice(0,0) should display the proper error message, which is what ^this PR will fix, and you do reference this in the PR itself.