I was trying to create a lookup table to use on an embedded platform (RP2040, which does not have native float hardware), and the following code triggers a panic in the mixed_acos
function:
use fixed::traits::{LosslessTryFrom, LosslessTryInto, LossyFrom, LossyInto};
use fixed::types::{I12F20, I12F52, I9F23};
use mixed_num::traits::*;
fn main() {
for i in -2048_i16..2048 {
let i = I12F20::from_num(i);
// let i = I9F23::lossless_try_from(i / 2048).unwrap();
let v = (i / 2048).mixed_acos();
println!("{v},");
}
}
$ RUST_BACKTRACE=1 cargo run
warning: unused imports: `LosslessTryFrom`, `LosslessTryInto`, `LossyFrom`, `LossyInto`
--> src/main.rs:1:21
|
1 | use fixed::traits::{LosslessTryFrom, LosslessTryInto, LossyFrom, LossyInto};
| ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused imports: `I12F52`, `I9F23`
--> src/main.rs:2:28
|
2 | use fixed::types::{I12F20, I12F52, I9F23};
| ^^^^^^ ^^^^^
warning: `tester` (bin "tester") generated 2 warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/tester`
thread 'main' panicked at 'attempt to shift right with overflow', /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/ops/bit.rs:627:1
stack backtrace:
0: rust_begin_unwind
at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:575:5
1: core::panicking::panic_fmt
at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/panicking.rs:65:14
2: core::panicking::panic
at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/panicking.rs:115:5
3: <i32 as core::ops::bit::Shr<u8>>::shr
at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/ops/bit.rs:601:17
4: fixed::arith::<impl core::ops::bit::Shr<u8> for fixed::FixedI32<Frac>>::shr
at /home/pfaria/.cargo/registry/src/github.com-1ecc6299db9ec823/fixed-1.21.0/src/arith.rs:164:35
5: cordic::asin
at /home/pfaria/.cargo/registry/src/github.com-1ecc6299db9ec823/cordic-0.1.5/src/lib.rs:108:21
6: cordic::acos
at /home/pfaria/.cargo/registry/src/github.com-1ecc6299db9ec823/cordic-0.1.5/src/lib.rs:116:22
7: mixed_num::fixed_impl::<impl mixed_num::traits::math_traits::MixedCos for fixed::FixedI32<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm,typenum::bit::B1>,typenum::bit::B0>,typenum::bit::B1>,typenum::bit::B0>,typenum::bit::B0>>>::mixed_acos
at /home/pfaria/.cargo/registry/src/github.com-1ecc6299db9ec823/mixed-num-0.5.5/src/fixed_impl.rs:291:24
8: tester::main
at ./src/main.rs:9:17
9: core::ops::function::FnOnce::call_once
at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/ops/function.rs:251:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.