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
use num_rational::Rational64;fnmain(){let a = Rational64::new(1,3000000000);let b = Rational64::from_integer(3080000000);println!("{}", a / b);}
panics with
thread 'main' panicked at 'attempt to multiply with overflow', /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/arith.rs:352:1
stack backtrace:
0: rust_begin_unwind
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
1: core::panicking::panic_fmt
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
2: core::panicking::panic
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:117:5
3: <i64 as core::ops::arith::Mul>::mul
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/arith.rs:345:45
4: <num_rational::Ratio<T> as core::ops::arith::Div>::div
at /home/shark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/num-rational-0.4.1/src/lib.rs:738:13
5: t::main
at ./src/main.rs:6:20
6: core::ops::function::FnOnce::call_once
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
Both large integers are far from i64::MAX — but their product overflows the 64-bit boundary. Is the panic expected in this case?
Yes, this is expected. The correct fully-reduced result would be "1 / 9223372036854775808", and that denominator is too large for i64. You can use CheckedDiv to guard against the panic though.
The following program
panics with
in this line:
num-rational/src/lib.rs
Line 737 in d89ce12
Both large integers are far from
i64::MAX
— but their product overflows the 64-bit boundary. Is the panic expected in this case?This looks similar to #6 because it also happens in division, but I think it's a separate issue.
The text was updated successfully, but these errors were encountered: