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

Support fixed-point storage type(s) #474

Open
kleinesfilmroellchen opened this issue May 13, 2024 · 0 comments
Open

Support fixed-point storage type(s) #474

kleinesfilmroellchen opened this issue May 13, 2024 · 0 comments

Comments

@kleinesfilmroellchen
Copy link

I want to utilize fixed-point arithmetic in unit-safe code for a few reasons:

  • The code runs on microcontrollers which don't have floating-point hardware
  • I need to guarantee a certain minimum precision across a specific, limited range of values
  • Fixed-point is associative and free of accumulating errors, unlike floating point

(All of these relate to my use of mostly length and velocity quantities in CNC firmware and G-Code parsing, to provide some context)

I would like to use the popular fixed crate for fixed-point arithmetic. On a feature level, the types in this crate obviously support enough arithmetic for uom to work, but as noted elsewhere, due to the Conversion<V> implementation requirement it is extremely cumbersome to implement.

Note that resolving #122 would also solve this issue, since then it would be more feasible for me to implement the custom storage type myself.

The best current workaround is to use ISQ! with SI quantities, integer units of sufficient size, and SI prefixed units to increase the precision of the system. For instance, while in my case I would want to use 22.10 signed fixed point (32-bit values and a precision of ~100μm when using SI base units), I can emulate a close-enough precision by using micrometers and i32 storage type.

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

1 participant