erikbuer / mixed-num Goto Github PK
View Code? Open in Web Editor NEWNo-STD abstraction layer enabling numerical functions to be implemented once, and simultaneously support both fixed and floating point types.
License: Other
No-STD abstraction layer enabling numerical functions to be implemented once, and simultaneously support both fixed and floating point types.
License: Other
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.