PebbleOS
Loading...
Searching...
No Matches
Macros | Functions

Real numbers in [0, 1] stored as scaled integers. More...

Macros

#define PBL_RATIO32_MAX   65535
 Scale of a ratio32, a uint32_t holding a real number in [0, 1].
 

Functions

static uint32_t pbl_ratio32_to_percent (uint32_t ratio)
 Convert a ratio32 to a percentage.
 
static uint32_t pbl_ratio32_from_percent (uint32_t percent)
 Convert a percentage to a ratio32.
 

Detailed Description

Real numbers in [0, 1] stored as scaled integers.

Macro Definition Documentation

◆ PBL_RATIO32_MAX

#define PBL_RATIO32_MAX   65535

Scale of a ratio32, a uint32_t holding a real number in [0, 1].

Function Documentation

◆ pbl_ratio32_from_percent()

static uint32_t pbl_ratio32_from_percent ( uint32_t  percent)
inlinestatic

Convert a percentage to a ratio32.

The result is one more than the truncated value, so it converts back to percent; 100 gives PBL_RATIO32_MAX + 1.

Parameters
percentPercentage, 0 to 100.
Returns
Ratio32.

References PBL_RATIO32_MAX.

◆ pbl_ratio32_to_percent()

static uint32_t pbl_ratio32_to_percent ( uint32_t  ratio)
inlinestatic

Convert a ratio32 to a percentage.

Parameters
ratioRatio32, 0 to PBL_RATIO32_MAX.
Returns
Percentage, 0 to 100, truncated.

References PBL_RATIO32_MAX.