Comment on page
fxpt
Library for doing arithmetic with fixed point numbers and converting them from/to floating point numbers.
A fixed point value
using fixed = s128;
Converts a fixed point value into a floating point value
fxt
: The fixed point value to convertprecision
: The bits of precision the new value should havereturn
: The floating point representation of fxt
fn to_float(std::fxpt::fixed fxt, u32 precision);
Converts a floating point value into a fixed point value
flt
: The floating point value to convertprecision
: The bits of precision the new value should havereturn
: The fixed point representation of flt
fn to_fixed(double flt, u32 precision);
Changes the number of bits used to represent the decimal part of the given fixed point number
value
: The fixed point value to convertstart_precision
: The current number of bits usedend_precision
: The new number of bits usedreturn
:value
as a new fixed point number withend_precision
bits of precision
fn change_precision(std::fxpt::fixed value, u32 start_precision, u32 end_precision);
Adds two fixed point numbers with a given precision together
a
: First fixed point numberb
: Second fixed point numberprecision
: The precision ofa
andb
return
: Result of the addition ofa
andb
fn add(std::fxpt::fixed a, std::fxpt::fixed b, u32 precision);
Subtracts two fixed point numbers with a given precision together
a
: First fixed point numberb
: Second fixed point numberprecision
: The precision ofa
andb
return
: Result of the subtraction ofa
andb
fn subtract(std::fxpt::fixed a, std::fxpt::fixed b, u32 precision);
Multiplies two fixed point numbers with a given precision together
a
: First fixed point numberb
: Second fixed point numberprecision
: The precision ofa
andb
return
: Result of the multiplication ofa
andb
fn multiply(std::fxpt::fixed a, std::fxpt::fixed b, u32 precision);
Divides two fixed point numbers with a given precision together
a
: First fixed point numberb
: Second fixed point numberprecision
: The precision ofa
andb
return
: Result of the division ofa
andb
fn divide(std::fxpt::fixed a, std::fxpt::fixed b, u32 precision);
Last modified 8mo ago