Skip to content

Instantly share code, notes, and snippets.

@dbasden
Last active November 10, 2019 07:24
Show Gist options
  • Save dbasden/f4bf2e81e413f3328042b4aacb12791d to your computer and use it in GitHub Desktop.
Save dbasden/f4bf2e81e413f3328042b4aacb12791d to your computer and use it in GitHub Desktop.
hackish_atof_fix.patch
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