[WIP] Implement RFC 41: lib.fixed
#1578
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
lib.fixed
while the associated RFC is being worked on. It started as a fork of @zyp's early implementation of the RFC here, however a few things have changed since then.fixed.Value
-.saturate()
and.clamp()
- these are commonly needed in my DSP codebase, but it may make sense to punt these new methods to a future RFC..truncate()
is added as an alias for.reshape()
, the only difference being that it verifies there was a reduction off_bits
requested.numerator()
method is dropped, as I found a way to combine it withas_value()
reliably.lib.fixed
in this Tiliqua PR and tested it underneath my library of DSP cores, and will continue to use the learnings there in order to guide the RFC.Simple example
Consider the implementation of a simple Low-pass filter, where we wish to compute the difference equation
y = y[n-1] * beta + x * (1 - beta)
using fixed point representation: