yarf 0.1
Yet Another RepRap Firmware
|
Fixed point number representation and basic math routines. The fixed point numbers are unsigned and occupy 32 bits, of which 16 for the whole part and 16 for the fractional part. More...
#include <stdint.h>
Go to the source code of this file.
Defines | |
#define | NB_FRACTIONAL_BITS 16 |
The number of fractional bits in the fixed point representation. | |
#define | FRACTIONAL_MULTIPLIER 65536.0f |
2 ^ (NB_FRACTIONAL_BITS) | |
#define | FXP_16U16_MAX UINT32_MAX |
The largest representable fixed point 16u16 number. | |
#define | FXP_16U16_ZERO 0 |
The number 0 represented as a fixed point 16u16. | |
#define | FXP_16U16_ONE ((fxp16u16_t)1 << NB_FRACTIONAL_BITS) |
The number 1 represented as a fixed point 16u16. | |
#define | FXP_16U16_ONE_HALF (FXP_16U16_ONE >> 1) |
The number 0.5 represented as a fixed point 16u16. | |
Typedefs | |
typedef uint32_t | fxp16u16_t |
Fixed point 16u16 are internally represented as 32-bit unsigned integers. | |
Functions | |
uint16_t | fxp16u16_to_uint16 (fxp16u16_t x) |
Converts a fixed point 16u16 number into an unsigned 16-bit integer, by rounding to the nearest integer. | |
float | fxp16u16_to_float (fxp16u16_t x) |
Converts a fixed point 16u16 number into a float. | |
fxp16u16_t | fxp16u16_from_uint16 (uint16_t x) |
Converts an unsigned 16-bit integer into a fixed point 16u16 number. | |
fxp16u16_t | fxp16u16_from_float (float x) |
Converts a float into a fixed point 16u16 number. | |
fxp16u16_t | fxp16u16_from_float_s (float x) |
Converts a float into a fixed point 16u16 number, using saturated arithmetic. | |
fxp16u16_t | fxp16u16_mul (fxp16u16_t x, fxp16u16_t y) |
Returns the product of two fixed point 16u16 numbers, if that product is within the range of representable fixed point 16u16 numbers. | |
fxp16u16_t | fxp16u16_div (fxp16u16_t x, fxp16u16_t y) |
Returns the quotient of two fixed point 16u16 numbers. | |
fxp16u16_t | fxp16u16_div_uint16 (fxp16u16_t x, uint16_t y) |
Returns the quotient of a fixed point 16u16 number divided by an unsigned 16-bit integer. | |
fxp16u16_t | fxp16u16_square (fxp16u16_t x) |
Returns the square of a fixed point 16u16 number. |
Fixed point number representation and basic math routines. The fixed point numbers are unsigned and occupy 32 bits, of which 16 for the whole part and 16 for the fractional part.
Definition in file fixed_point.h.
fxp16u16_t fxp16u16_div | ( | fxp16u16_t | x, |
fxp16u16_t | y | ||
) | [inline] |
Returns the quotient of two fixed point 16u16 numbers.
x | the dividend |
y | the divisor |
Definition at line 176 of file fixed_point.h.
fxp16u16_t fxp16u16_div_uint16 | ( | fxp16u16_t | x, |
uint16_t | y | ||
) | [inline] |
Returns the quotient of a fixed point 16u16 number divided by an unsigned 16-bit integer.
x | the dividend |
y | the divisor |
Definition at line 192 of file fixed_point.h.
fxp16u16_t fxp16u16_from_float | ( | float | x | ) | [inline] |
Converts a float into a fixed point 16u16 number.
x | the float to convert |
Definition at line 121 of file fixed_point.h.
fxp16u16_t fxp16u16_from_float_s | ( | float | x | ) | [inline] |
Converts a float into a fixed point 16u16 number, using saturated arithmetic.
x | the float to convert |
Definition at line 139 of file fixed_point.h.
fxp16u16_t fxp16u16_from_uint16 | ( | uint16_t | x | ) | [inline] |
Converts an unsigned 16-bit integer into a fixed point 16u16 number.
x | the 16-bit integer to convert |
Definition at line 107 of file fixed_point.h.
fxp16u16_t fxp16u16_mul | ( | fxp16u16_t | x, |
fxp16u16_t | y | ||
) | [inline] |
Returns the product of two fixed point 16u16 numbers, if that product is within the range of representable fixed point 16u16 numbers.
x | the first factor of the product |
y | the second factor of the product |
Definition at line 161 of file fixed_point.h.
fxp16u16_t fxp16u16_square | ( | fxp16u16_t | x | ) | [inline] |
Returns the square of a fixed point 16u16 number.
x | the number of which to return the square |
Definition at line 206 of file fixed_point.h.
float fxp16u16_to_float | ( | fxp16u16_t | x | ) | [inline] |
Converts a fixed point 16u16 number into a float.
x | the fixed point number to convert |
Definition at line 94 of file fixed_point.h.
uint16_t fxp16u16_to_uint16 | ( | fxp16u16_t | x | ) | [inline] |
Converts a fixed point 16u16 number into an unsigned 16-bit integer, by rounding to the nearest integer.
x | the fixed point number to convert |
Definition at line 82 of file fixed_point.h.