Git Product home page Git Product logo

mixed-num's Issues

Panic when calling `mixed_acos`

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},");
    }
}

This is the backtrace:

$ 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.