Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lcm on i64 falls victim to overflow checking #166

Closed
pnkfelix opened this issue Feb 17, 2016 · 2 comments
Closed

lcm on i64 falls victim to overflow checking #166

pnkfelix opened this issue Feb 17, 2016 · 2 comments

Comments

@pnkfelix
Copy link
Contributor

#[test]
fn demo_i64_lcm_problem() {
    use num::integer::Integer;
    let x: i64 = 46656000000000000;
    let y: i64 = 600;
    let l = x.lcm(&y);
    println!("x: {} y: {} l: {}", x, y, l);
}

This signals overflow for me when run in a debug build:

% RUST_BACKTRACE=1 cargo test demo_i64_lcm
   Compiling qcon-london2016 v0.1.0 (file:///Users/fklock/Dev/Mozilla/pnk-presents/qcon-london2016)
     Running target/debug/lib-d106592ea2cd2eeb

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

     Running target/debug/mandelbrot-6ba1a3372be98e2a

running 1 test
test demo_i64_lcm_problem ... FAILED

failures:

---- demo_i64_lcm_problem stdout ----
    thread 'demo_i64_lcm_problem' panicked at 'arithmetic operation overflowed', /Users/fklock/.multirust/toolchains/nightly/cargo/registry/src/github.com-88ac128001ac3a9a/num-0.1.30/src/integer.rs:262
stack backtrace:
   1:        0x10dc18e58 - sys::backtrace::tracing::imp::write::h6de1146e783ad759jcu
   2:        0x10dc1a915 - panicking::default_handler::_$u7b$$u7b$closure$u7d$$u7d$::closure.42839
   3:        0x10dc1a477 - panicking::default_handler::hcdc388abac3dab00txy
   4:        0x10dc0ee26 - sys_common::unwind::begin_unwind_inner::h92bb9fa816635994Bbt
   5:        0x10dc0f29e - sys_common::unwind::begin_unwind_fmt::h74474f4da0682187Hat
   6:        0x10dc182f7 - rust_begin_unwind
   7:        0x10dc3c860 - panicking::panic_fmt::hd3ab350bce4886e96YL
   8:        0x10dc3cb5c - panicking::panic::he1e34a74b1285647DXL
   9:        0x10dbb0f85 - integer::i64.Integer::lcm::h95d9e21688ecbb32EKf
  10:        0x10dbb0dbd - demo_i64_lcm_problem::h91d8aeddf6ee4d34tdc
  11:        0x10dbf1d5b - boxed::F.FnBox<A>::call_box::h14880339069920088140
  12:        0x10dbf41cd - sys_common::unwind::try::try_fn::h15106091318301828466
  13:        0x10dc1828b - __rust_try
  14:        0x10dc15f63 - sys_common::unwind::inner_try::he3a51540743a3631D8s
  15:        0x10dbf45b4 - boxed::F.FnBox<A>::call_box::h1300029706881708100
  16:        0x10dc19b9f - sys::thread::Thread::new::thread_start::h26f0f802585e3c80ULx
  17:     0x7fff91138c12 - _pthread_body
  18:     0x7fff91138b8f - _pthread_start


failures:
    demo_i64_lcm_problem

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured

%
@cuviper
Copy link
Member

cuviper commented Feb 17, 2016 via email

@pnkfelix
Copy link
Contributor Author

Oh yes, the gcd should indeed divide either one. Okay I'll try that.

pnkfelix added a commit to pnkfelix/num that referenced this issue Feb 17, 2016
pnkfelix added a commit to pnkfelix/num that referenced this issue Feb 18, 2016
@homu homu closed this as completed in #167 Feb 18, 2016
homu added a commit that referenced this issue Feb 18, 2016
Reorder ops in LCM to avoid overflow.

Reorder ops in LCM to avoid overflow.

Fix #166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants