A Zero-Overhead Macro for Unified Management of Floating-Point/Fixed-Point Resolution
104reads
Synopsis
The text discusses the challenges in converting floating-point to fixed-point in applications, especially with resolution conversion. It introduces macro methods for handling scaling relationships like multiplication and division, and mentions helper functions to address rounding issues during the conversion process. An application example is referenced.
A Zero-Overhead Macro for Unified Management of Floating-Point/Fixed-Point Resolution
In applications where floating-point and fixed-point values need to coexist, resolution conversion can be a real headache, so here is a macro-based approach.
The mapping looks like
2--0.01--100, covering the numeric relationships for both multiplying and dividing by a scale factor.Usage is like this:
Helper Functions
Even with a scale factor, converting a floating-point value to a fixed-point integer still runs into the small rounding issue. This can be handled by combining the macros with the function below.
A usage example: