arduino/firmware/libs/wkfn/numbers.h
2024-09-17 13:18:18 +02:00

85 lines
1.5 KiB
C

unsigned int f_2uint_int1(float float_number) { // split the float and return first unsigned integer
union f_2uint {
float f;
uint16_t i[2];
};
union f_2uint f_number;
f_number.f = float_number;
return f_number.i[0];
}
unsigned int f_2uint_int2(float float_number) { // split the float and return first unsigned integer
union f_2uint {
float f;
uint16_t i[2];
};
union f_2uint f_number;
f_number.f = float_number;
return f_number.i[1];
}
float f_2uint_float(unsigned int uint1, unsigned int uint2) { // reconstruct the float from 2 unsigned integers
union f_2uint {
float f;
uint16_t i[2];
};
union f_2uint f_number;
f_number.i[0] = uint1;
f_number.i[1] = uint2;
return f_number.f;
}
unsigned int l_2uint_int1(long long_number) { // split the long and return first unsigned integer
union l_2uint {
long l;
uint16_t i[2];
};
union l_2uint l_number;
l_number.l = long_number;
return l_number.i[0];
}
unsigned int l_2uint_int2(long long_number) { // split the long and return first unsigned integer
union l_2uint {
long l;
uint16_t i[2];
};
union l_2uint l_number;
l_number.l = long_number;
return l_number.i[1];
}
long l_2uint_long(unsigned int uint1, unsigned int uint2) { // reconstruct the long from 2 unsigned integers
union l_2uint {
long l;
uint16_t i[2];
};
union l_2uint l_number;
l_number.i[0] = uint1;
l_number.i[1] = uint2;
return l_number.l;
}