Convert floating-point to fixed-point with performance warning.
- Template Parameters
-
T | Floating-point type (float, double) |
- Parameters
-
value | The value to convert |
- Returns
- Fixed-point value
Converts a floating-point value to 16.16 fixed-point format. This operation involves floating-point multiplication which is relatively expensive on Saturn hardware. The compiler will emit a warning when this function is used to help identify potential performance bottlenecks.
This is a RUNTIME conversion method. For compile-time conversion, prefer using the Fxp constructor directly with constexpr when possible.
For better performance:
- Use integral types when possible
- Perform conversions at compile time with constexpr
- Cache converted values instead of converting in tight loops
Example:
constexpr Fxp a = 3.14159;
float f = get_value();
static constexpr Fxp Convert(const T &value)
Convert integral type to fixed-point with compile-time range validation.
Definition fxp.hpp:156
- Note
- The performance warning can be disabled by defining DISABLE_PERFORMANCE_WARNINGS before including this header. This is useful for code sections where you have already considered and accepted the performance implications.
- Warning
- Converting from floating-point is a heavy operation. Avoid in performance-critical code paths.