SaturnRingLibrary 0.9.1
SGL wrapper
 
Loading...
Searching...
No Matches

◆ Convert() [2/2]

template<std::floating_point T>
static Fxp SRL::Math::Types::Fxp::Convert ( const T & value)
inlinestatic

Convert floating-point to fixed-point with performance warning.

Template Parameters
TFloating-point type (float, double)
Parameters
valueThe 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:

// Preferred: Compile-time conversion
constexpr Fxp a = 3.14159; // Conversion done at compile time
// Runtime conversion (will trigger warning)
float f = get_value();
Fxp b = Fxp::Convert(f); // Warning: heavy operation
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.