-
Notifications
You must be signed in to change notification settings - Fork 0
/
phoenixjack_math_functions.h
52 lines (51 loc) · 1.27 KB
/
phoenixjack_math_functions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h> // For strtol
long hexStringToLong(const String& hexString) {
char buffer[hexString.length() + 1];
hexString.toCharArray(buffer, sizeof(buffer));
char* endptr;
long value = strtol(buffer, &endptr, 16);
if (*endptr != '\0') {
// Handle conversion error
// For example, return a default value or indicate error
}
return value;
}
long hexCharsToLong(const char* hexString) {
char* endptr;
long value = strtol(hexString, &endptr, 16);
if (*endptr != '\0') {
// Handle conversion error
// For example, return a default value or indicate error
}
return value;
}
int getweightedavg(int* curr, int* samples, int* avg) {
int tempval = *samples * *avg;
tempval += *curr;
tempval /= (*samples + 1);
return tempval;
}
bool isNumber(const char* str) {
bool hasDecimal = false;
if (*str == '-') { // Check for negative sign
str++;
}
while (*str) {
if (!isdigit(*str) && *str != '.') {
return false;
}
if (*str == '.') {
if (hasDecimal) {
return false; // Only allow one decimal point
}
hasDecimal = true;
}
str++;
}
return true;
}
int integerpart(float* value) {
return (int)(abs(*value));
}
int decimalpart(float* value) {
}