29 #include "pico/types.h"
30 #include "../include/mass.h"
41 const double*
const fromAmount,
42 double*
const toAmount,
46 assert(fromAmount != NULL);
47 assert(toAmount != NULL);
49 if(fromUnit == toUnit) {
50 *toAmount = *fromAmount;
96 res->
ug = lhs->
ug + rhs->
ug;
110 res->
ug = lhs->
ug - rhs->
ug;
124 res->
ug = lhs->
ug * rhs->
ug;
139 if(fabs(rhs->
ug) < DBL_EPSILON) {
143 res->
ug = lhs->
ug / rhs->
ug;
151 const mass_t*
const rhs) {
157 const mass_t*
const rhs) {
163 const mass_t*
const rhs) {
169 const mass_t*
const rhs) {
175 const mass_t*
const rhs) {
181 return fabs(lhs->
ug - rhs->
ug) < DBL_EPSILON;
187 const mass_t*
const rhs) {
198 const mass_t*
const rhs) {
203 return lhs->
ug < rhs->
ug;
209 const mass_t*
const rhs) {
220 const mass_t*
const rhs) {
231 const mass_t*
const rhs) {
246 assert(buff != NULL);
251 const double f = fabs(modf(n, &i));
255 if(f >= DBL_EPSILON) {
256 d = (uint)fmax(0, ceil(1 - log10(f)));
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.
bool mass_diveq(mass_t *const self, const mass_t *const rhs)
Divide self by rhs, returns false if rhs is 0.
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".
bool mass_lteq(const mass_t *const lhs, const mass_t *const rhs)
Returns true if lhs is less than or equal to rhs.
const char *const mass_unit_to_string(const mass_unit_t u)
Returns a pointer to char with the textual representation of the unit.
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.
bool mass_gteq(const mass_t *const lhs, const mass_t *const rhs)
Returns true if lhs is greater than or equal to rhs.
void mass_subeq(mass_t *const self, const mass_t *const rhs)
Subtract rhs from self.
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.
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.
bool mass_gt(const mass_t *const lhs, const mass_t *const rhs)
Returns true if lhs is greater than rhs.
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.
bool mass_neq(const mass_t *const lhs, const mass_t *const rhs)
Returns true if lhs does not equal rhs.
void mass_muleq(mass_t *const self, const mass_t *const rhs)
Multiply self by rhs.
void mass_addeq(mass_t *const self, const mass_t *const rhs)
Add rhs to self.
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.
bool mass_eq(const mass_t *const lhs, const mass_t *const rhs)
Returns true if lhs equals rhs.
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.
bool mass_lt(const mass_t *const lhs, const mass_t *const rhs)
Returns true if lhs is less than rhs.
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.
static const double MASS_RATIOS[]
static const char *const MASS_NAMES[]
static const size_t MASS_TO_STRING_BUFF_SIZE