rust-num / num-rational

Generic Rational numbers for Rust
Apache License 2.0
144 stars 51 forks source link

Integers not correctly handled in `num::rational` #7

Open cuviper opened 6 years ago

cuviper commented 6 years ago

From @rust-highfive on September 28, 2014 22:43

Issue by tbu- Saturday Aug 09, 2014 at 13:25 GMT

For earlier discussion, see https://github.com/rust-lang/rust/issues/16386

This issue was labelled with: in the Rust repository


There are also some issues regarding overflows, it seems the module just hopes that they won't happen at all – except for wrong results, this could also raise a fail!()ure, when e.g. 1/sqrt(max_int) is multiplied with itself, yielding 1/0.

This might mean that Rust needs some general guideline on how to treat integer overflow.

Copied from original issue: rust-num/num#11

vks commented 3 years ago

self.denom is compared to Zero::zero instead of calling is_zero().

This is fixed.

This might mean that Rust needs some general guideline on how to treat integer overflow.

I think we should adopt the same behavior as for the primitive integer types: Panic in debug mode, silently fail in release mode. This would mean that this issue and #11 can be just closed, because all remaining cases already panic in debug mode.

We could add debug_asserts, but I don't think it adds much.