fxpt
Library for doing arithmetic with fixed point numbers and converting them from/to floating point numbers.
Types
std::fxpt::fixed
std::fxpt::fixedA fixed point value
using fixed = s128;Functions
std::fxpt::to_float
std::fxpt::to_floatConverts a fixed point value into a floating point value
- fxt: The fixed point value to convert
- precision: The bits of precision the new value should have
- return: The floating point representation of fxt
fn to_float(std::fxpt::fixed fxt, u32 precision);std::fxpt::to_fixed
std::fxpt::to_fixedConverts a floating point value into a fixed point value
- flt: The floating point value to convert
- precision: The bits of precision the new value should have
- return: The fixed point representation of flt
fn to_fixed(double flt, u32 precision);std::fxpt::change_precision
std::fxpt::change_precisionChanges the number of bits used to represent the decimal part of the given fixed point number
- value: The fixed point value to convert
- start_precision: The current number of bits used
- end_precision: The new number of bits used
- return:- valueas a new fixed point number with- end_precisionbits of precision
fn change_precision(std::fxpt::fixed value, u32 start_precision, u32 end_precision);std::fxpt::add
std::fxpt::addAdds two fixed point numbers with a given precision together
- a: First fixed point number
- b: Second fixed point number
- precision: The precision of- aand- b
- return: Result of the addition of- aand- b
fn add(std::fxpt::fixed a, std::fxpt::fixed b, u32 precision);std::fxpt::subtract
std::fxpt::subtractSubtracts two fixed point numbers with a given precision together
- a: First fixed point number
- b: Second fixed point number
- precision: The precision of- aand- b
- return: Result of the subtraction of- aand- b
fn subtract(std::fxpt::fixed a, std::fxpt::fixed b, u32 precision);std::fxpt::multiply
std::fxpt::multiplyMultiplies two fixed point numbers with a given precision together
- a: First fixed point number
- b: Second fixed point number
- precision: The precision of- aand- b
- return: Result of the multiplication of- aand- b
fn multiply(std::fxpt::fixed a, std::fxpt::fixed b, u32 precision);std::fxpt::divide
std::fxpt::divideDivides two fixed point numbers with a given precision together
- a: First fixed point number
- b: Second fixed point number
- precision: The precision of- aand- b
- return: Result of the division of- aand- b
fn divide(std::fxpt::fixed a, std::fxpt::fixed b, u32 precision);Last updated
Was this helpful?