fixed_math

Subtraction in FixedMath

The FixedMath library precisely manages the subtraction of fixed-point numbers (fixed_t), ensuring accuracy and robustness across various operations. This includes support for mixed-type arithmetic involving fixed_t, integers, and floating-point numbers.

Core Subtraction Functionality

Type Promotion and Arithmetic

Subtraction Operator Overloads

Specialized Subtraction Functions

Safety and Precision

Subtraction operations in the FixedMath library are crafted with a focus on safety, ensuring that conditions like potential overflows or underflows are managed adeptly, returning NaN in situations where accurate results cannot be guaranteed.

Usage Example

fixed_t a = ...; // Initialize with some value
fixed_t b = ...; // Another fixed_t value
fixed_t result = a - b; // Subtraction of two fixed_t values

int scalar = 5;
fixed_t result2 = a - scalar; // Subtraction with an integer scalar

double d = 2.0;
auto result3 = a - d; // Subtraction with a double, result is promoted to double