`pi` crashes for small u32 inputs due to subtraction overflow
Closed this issue · 1 comments
aschoettler commented
I added these tests to my lib.rs
:
#[test]
fn primepi_small_u32() {
for i in (1u32..9) {
i.pi();
}
assert_eq!(9u32.pi(), 4);
}
#[test]
fn primepi_ok_u32() {
assert_eq!(9u32.pi(), 4);
}
The console output says
thread 'primepi_small_u32' panicked at 'attempt to subtract with overflow'
and points to the file sieve.rs:2:18
JASory commented
Temporarily fixed by treeing it down to 16-bit evaluation. Currently there are a fair amount of issues with handling very small integers as I haven't finished optimizing and treeing down the evaluations for very small integers. (Usually 0 and 1 are the failure points {due to definition of the factor function}, so watch out). I'll be working on this in the next week so most of those issues will be resolved.