pico-scale
|
#include <assert.h>
#include <float.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include "pico/types.h"
#include "../include/mass.h"
Go to the source code of this file.
Functions | |
const char *const | mass_unit_to_string (const mass_unit_t u) |
Returns a pointer to char with the textual representation of the unit. More... | |
const double *const | mass_unit_to_ratio (const mass_unit_t u) |
Returns a pointer to a double with the number of micrograms per unit. More... | |
void | mass_convert (const double *const fromAmount, double *const toAmount, const mass_unit_t fromUnit, const mass_unit_t toUnit) |
Converts a floating point value from one unit to another. More... | |
void | mass_init (mass_t *const m, const mass_unit_t unit, const double val) |
Initialises a mass_t with the given unit and value. More... | |
void | mass_get_value (const mass_t *const m, double *const val) |
Sets val to the value representing the mass_t according to its unt. More... | |
void | mass_add (const mass_t *const lhs, const mass_t *const rhs, mass_t *const res) |
Add lhs to rhs and store result in res. More... | |
void | mass_sub (const mass_t *const lhs, const mass_t *const rhs, mass_t *const res) |
Substract rhs from lhs and store result in res. More... | |
void | mass_mul (const mass_t *const lhs, const mass_t *const rhs, mass_t *const res) |
Multiply lhs by rhs and store result in res. More... | |
bool | mass_div (const mass_t *const lhs, const mass_t *const rhs, mass_t *const res) |
Divide lhs by rhs and store result in res, returns false if rhs is 0. More... | |
void | mass_addeq (mass_t *const self, const mass_t *const rhs) |
Add rhs to self. More... | |
void | mass_subeq (mass_t *const self, const mass_t *const rhs) |
Subtract rhs from self. More... | |
void | mass_muleq (mass_t *const self, const mass_t *const rhs) |
Multiply self by rhs. More... | |
bool | mass_diveq (mass_t *const self, const mass_t *const rhs) |
Divide self by rhs, returns false if rhs is 0. More... | |
bool | mass_eq (const mass_t *const lhs, const mass_t *const rhs) |
Returns true if lhs equals rhs. More... | |
bool | mass_neq (const mass_t *const lhs, const mass_t *const rhs) |
Returns true if lhs does not equal rhs. More... | |
bool | mass_lt (const mass_t *const lhs, const mass_t *const rhs) |
Returns true if lhs is less than rhs. More... | |
bool | mass_gt (const mass_t *const lhs, const mass_t *const rhs) |
Returns true if lhs is greater than rhs. More... | |
bool | mass_lteq (const mass_t *const lhs, const mass_t *const rhs) |
Returns true if lhs is less than or equal to rhs. More... | |
bool | mass_gteq (const mass_t *const lhs, const mass_t *const rhs) |
Returns true if lhs is greater than or equal to rhs. More... | |
int | mass_to_string (const mass_t *const m, char *const buff) |
Fills buff with the string representation of the mass_t. eg. "32.4762 mg". More... | |
Add lhs to rhs and store result in res.
lhs | |
rhs | |
res |
Definition at line 87 of file mass.c.
References mass_t::ug, and mass_t::unit.
Referenced by mass_addeq().
void mass_convert | ( | const double *const | fromAmount, |
double *const | toAmount, | ||
const mass_unit_t | fromUnit, | ||
const mass_unit_t | toUnit | ||
) |
Converts a floating point value from one unit to another.
fromAmount | |
toAmount | |
fromUnit | |
toUnit |
Definition at line 40 of file mass.c.
References mass_convert(), mass_ug, and mass_unit_to_ratio().
Referenced by mass_convert(), mass_get_value(), and mass_init().
Divide lhs by rhs and store result in res, returns false if rhs is 0.
lhs | |
rhs | |
res |
Definition at line 129 of file mass.c.
References mass_t::ug, and mass_t::unit.
Referenced by mass_diveq().
Divide self by rhs, returns false if rhs is 0.
self | |
rhs |
Definition at line 167 of file mass.c.
References mass_div().
Returns true if lhs equals rhs.
lhs | |
rhs |
Definition at line 173 of file mass.c.
References mass_t::ug.
Referenced by mass_neq().
void mass_get_value | ( | const mass_t *const | m, |
double *const | val | ||
) |
Sets val to the value representing the mass_t according to its unt.
m | |
val |
Definition at line 76 of file mass.c.
References mass_convert(), mass_ug, mass_t::ug, and mass_t::unit.
Referenced by mass_to_string().
Returns true if lhs is greater than rhs.
lhs | |
rhs |
Definition at line 207 of file mass.c.
References mass_lt().
Referenced by mass_lteq().
void mass_init | ( | mass_t *const | m, |
const mass_unit_t | unit, | ||
const double | val | ||
) |
Initialises a mass_t with the given unit and value.
m | |
unit | |
val |
Definition at line 64 of file mass.c.
References mass_convert(), mass_ug, mass_t::ug, and mass_t::unit.
Referenced by scale_weight().
Returns true if lhs is less than rhs.
lhs | |
rhs |
Definition at line 196 of file mass.c.
References mass_t::ug.
Referenced by mass_gt(), and mass_gteq().
Returns true if lhs is less than or equal to rhs.
lhs | |
rhs |
Definition at line 218 of file mass.c.
References mass_gt().
Multiply lhs by rhs and store result in res.
lhs | |
rhs | |
res |
Definition at line 115 of file mass.c.
References mass_t::ug, and mass_t::unit.
Referenced by mass_muleq().
Multiply self by rhs.
self | |
rhs |
Definition at line 161 of file mass.c.
References mass_mul().
Returns true if lhs does not equal rhs.
lhs | |
rhs |
Definition at line 185 of file mass.c.
References mass_eq().
Substract rhs from lhs and store result in res.
lhs | |
rhs | |
res |
Definition at line 101 of file mass.c.
References mass_t::ug, and mass_t::unit.
Referenced by mass_subeq().
Subtract rhs from self.
self | |
rhs |
Definition at line 155 of file mass.c.
References mass_sub().
int mass_to_string | ( | const mass_t *const | m, |
char *const | buff | ||
) |
Fills buff with the string representation of the mass_t. eg. "32.4762 mg".
m | |
buff | Must be at least MASS_TO_STRING_BUFF_SIZE in length |
Definition at line 241 of file mass.c.
References mass_get_value(), MASS_TO_STRING_BUFF_SIZE, mass_unit_to_string(), and mass_t::unit.
const double* const mass_unit_to_ratio | ( | const mass_unit_t | u | ) |
Returns a pointer to a double with the number of micrograms per unit.
u |
Definition at line 36 of file mass.c.
References MASS_RATIOS.
Referenced by mass_convert().
const char* const mass_unit_to_string | ( | const mass_unit_t | u | ) |
Returns a pointer to char with the textual representation of the unit.
u |
Definition at line 32 of file mass.c.
References MASS_NAMES.
Referenced by mass_to_string().