Last active
November 10, 2019 07:24
-
-
Save dbasden/f4bf2e81e413f3328042b4aacb12791d to your computer and use it in GitHub Desktop.
hackish_atof_fix.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/ui.c b/ui.c | |
| index 27519aa..d265d74 100644 | |
| --- a/ui.c | |
| +++ b/ui.c | |
| @@ -24,6 +24,7 @@ | |
| #include "nanovna.h" | |
| #include <stdlib.h> | |
| #include <string.h> | |
| +#include <ctype.h> | |
| uistat_t uistat = { | |
| @@ -1678,6 +1679,42 @@ static void ui_process_menu(void) | |
| } | |
| } | |
| +static inline double my_atod(const char *p) | |
| +{ | |
| + int neg = FALSE; | |
| + if (*p == '-') | |
| + neg = TRUE; | |
| + if (*p == '-' || *p == '+') | |
| + p++; | |
| + double x = atoi(p); | |
| + while (isdigit((int)*p)) | |
| + p++; | |
| + if (*p == '.') { | |
| + double d = 1.0f; | |
| + p++; | |
| + while (isdigit((int)*p)) { | |
| + d /= 10; | |
| + x += d * (*p - '0'); | |
| + p++; | |
| + } | |
| + } | |
| + if (*p == 'e' || *p == 'E') { | |
| + p++; | |
| + int exp = atoi(p); | |
| + while (exp > 0) { | |
| + x *= 10; | |
| + exp--; | |
| + } | |
| + while (exp < 0) { | |
| + x /= 10; | |
| + exp++; | |
| + } | |
| + } | |
| + if (neg) | |
| + x = -x; | |
| + return x; | |
| +} | |
| + | |
| static int keypad_click(int key) | |
| { | |
| int c = keypads[key].c; | |
| @@ -1691,7 +1728,7 @@ static int keypad_click(int key) | |
| scale *= 1000; | |
| } | |
| /* numeric input done */ | |
| - double value = atof(kp_buf) * scale; | |
| + double value = my_atod(kp_buf) * scale; | |
| switch (keypad_mode) { | |
| case KM_START: | |
| set_sweep_frequency(ST_START, (int32_t)value); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment