OSDN Git Service

Support for inline elements
[liveml/LiveML.git] / src / fixed_float.c
index dca1549..d1543d9 100644 (file)
@@ -75,3 +75,54 @@ fixed_float fixed_float_div(fixed_float x, fixed_float y)
 
   return result;
 }
+
+fixed_float str_to_fixed_float(const char* text)
+{
+  fixed_float v;
+  int float_point = 0;
+  int iv = 0;
+  float fv = 0;
+
+  while ((*text >= '0' && *text <= '9') || *text == '.')
+  {
+    char num;
+    if (*text == '.')
+    {
+      float_point = 10;
+      text++;
+      continue;
+    }
+
+    num = *text++ - '0';
+    if (float_point)
+    {
+      fv += (float)num / float_point;
+      float_point *= 10;
+    }
+    else
+    {
+      if (iv) iv *= 10;
+      iv += num;
+    }
+  }
+  v = int_to_fixed_float(iv);
+  if (fv) v += float_to_fixed_float(fv);
+
+  return v;
+}
+
+int str_to_int(const char* text)
+{
+  int v = 0;
+
+  while (*text >= '0' && *text <= '9')
+  {
+    char num;
+
+    num = *text++ - '0';
+    if (v) v *= 10;
+    v += num;
+  }
+
+  return v;
+}
\ No newline at end of file