sarmfsw: SMFSW Toolbox (for ARM & compatible with Arduino platform) 3.7
SMFSW collection of miscellaneous functions & macros (for ARM & compatible with Arduino platform)
Loading...
Searching...
No Matches
arm_inlines_float.h File Reference

Floating point manipulation inlines. More...

#include <math.h>
Include dependency graph for arm_inlines_float.h:
This graph shows which files directly or indirectly include this file:

Data Structures

struct  sIntFrac
 Float representation on integers. More...
 

Macros

#define SPLIT_FLOAT_TO_INTS(val, nb_frac)   (SDWORD) (val), get_fp_dec((val), (nb_frac))
 <
 

Typedefs

typedef struct sIntFrac sIntFrac
 

Functions

DWORD get_fp_dec (const double f, const BYTE nb)
 Get floating point number decimal part (as absolute value)
 
void float2sIntFrac (sIntFrac *const pIntFrac, const double f, const uint8_t nb_frac)
 Convert floating point representation to sIntFrac integers representation.
 
void sIntFrac2float (double *const pFloat, const sIntFrac *const pIntFrac)
 Convert sIntFrac integers representation to floating point representation.
 

Detailed Description

Floating point manipulation inlines.

Author
SMFSW

Macro Definition Documentation

◆ SPLIT_FLOAT_TO_INTS

#define SPLIT_FLOAT_TO_INTS ( val,
nb_frac )   (SDWORD) (val), get_fp_dec((val), (nb_frac))

<

Warning
Sign does not work for values between 0 and -1 (sign is lost) Split float value val into 2 integers with nb_frac fractional part digits

Typedef Documentation

◆ sIntFrac

typedef struct sIntFrac sIntFrac

Function Documentation

◆ float2sIntFrac()

void float2sIntFrac ( sIntFrac *const pIntFrac,
const double f,
const uint8_t nb_frac )
inline

Convert floating point representation to sIntFrac integers representation.

Parameters
[in,out]pIntFrac- Pointer to result structure
[in]f- floating point value to convert
[in]nb_frac- Number of decimal to get after floating point (limited to 9 internally for proper result on 32b return type)
Here is the call graph for this function:

◆ get_fp_dec()

DWORD get_fp_dec ( const double f,
const BYTE nb )
inline

Get floating point number decimal part (as absolute value)

Note
if in need to print floats, you can add '-u _printf_float' in Linker options instead of using get_fp_dec. Otherwise, SPLIT_FLOAT_TO_INTS may be used to ease the formatting process for printf like functions.
Parameters
[in]f- floating point value
[in]nb- Number of decimal to get after floating point (limited to 9 internally for proper result on 32b return type)
Returns
nb decimal part as unsigned integer
Here is the caller graph for this function:

◆ sIntFrac2float()

void sIntFrac2float ( double *const pFloat,
const sIntFrac *const pIntFrac )
inline

Convert sIntFrac integers representation to floating point representation.

Parameters
[in,out]pFloat- Pointer to floating point result
[in]pIntFrac- Pointer to sIntFrac structure to convert