Commits

Anonymous committed f0b8359

Added support for integer/float additions, subtractions etc. Also the repr precision was lowered so that commas are rounded to something human readable.

  • Participants
  • Parent commits a70aab1

Comments (0)

Files changed (3)

 arana_float_add(AR_SIG, AR self, AR args)
 {
     AR other;
-    AR_PARSE(args, "F::add", &other);
+    AR_PARSE(args, "N::add", &other);
+    if (AR_IS_INTEGER(other))
+        return AR_FLOAT(AR_AS_DOUBLE(self) + AR_AS_LONG(other));
     return AR_FLOAT(AR_AS_DOUBLE(self) + AR_AS_DOUBLE(other));
 }
 
 arana_float_sub(AR_SIG, AR self, AR args)
 {
     AR other;
-    AR_PARSE(args, "F::sub", &other);
+    AR_PARSE(args, "N::sub", &other);
+    if (AR_IS_INTEGER(other))
+        return AR_FLOAT(AR_AS_DOUBLE(self) - AR_AS_LONG(other));
     return AR_FLOAT(AR_AS_DOUBLE(self) - AR_AS_DOUBLE(other));
 }
 
 arana_float_mul(AR_SIG, AR self, AR args)
 {
     AR other;
-    AR_PARSE(args, "F::mul", &other);
+    AR_PARSE(args, "N::mul", &other);
+    if (AR_IS_INTEGER(other))
+        return AR_FLOAT(AR_AS_DOUBLE(self) * AR_AS_LONG(other));
     return AR_FLOAT(AR_AS_DOUBLE(self) * AR_AS_DOUBLE(other));
 }
 
 arana_float_div(AR_SIG, AR self, AR args)
 {
     AR other;
-    AR_PARSE(args, "F::div", &other);
+    AR_PARSE(args, "N::div", &other);
+    if (AR_IS_INTEGER(other))
+        return AR_FLOAT(AR_AS_DOUBLE(self) / (Ar_float)AR_AS_LONG(other));
     return AR_FLOAT(AR_AS_DOUBLE(self) / AR_AS_DOUBLE(other));
 }
 
 #define PREC_STR  12
-#define PREC_REPR 17
+#define PREC_REPR 16
 
 static void
 _arana_format_float(ArFloat *value, char *buf, int buflen, int precision)

arana/parse_args.c

                 UNEXPECTED("Float");
             }
             goto setarg;
+        case 'N':
+            if (!(AR_IS_INTEGER(obj) || AR_IS_FLOAT(obj))) {
+                UNEXPECTED("Integer or Float");
+            }
+            goto setarg;
         case 'O':
         setarg:
             if (obj)

arana/primitives.c

 arana_integer_add(AR_SIG, AR self, AR args)
 {
     AR other;
-    AR_PARSE(args, "I::add", &other);
+    AR_PARSE(args, "N::add", &other);
+    if (AR_IS_FLOAT(other))
+        return AR_FLOAT(AR_AS_LONG(self) + AR_AS_DOUBLE(other));
     return AR_INTEGER(AR_AS_LONG(self) + AR_AS_LONG(other));
 }
 
 arana_integer_sub(AR_SIG, AR self, AR args)
 {
     AR other;
-    AR_PARSE(args, "I::sub", &other);
+    AR_PARSE(args, "N::sub", &other);
+    if (AR_IS_FLOAT(other))
+        return AR_FLOAT(AR_AS_LONG(self) - AR_AS_DOUBLE(other));
     return AR_INTEGER(AR_AS_LONG(self) - AR_AS_LONG(other));
 }
 
 arana_integer_mul(AR_SIG, AR self, AR args)
 {
     AR other;
-    AR_PARSE(args, "I::mul", &other);
+    AR_PARSE(args, "N::mul", &other);
+    if (AR_IS_FLOAT(other))
+        return AR_FLOAT(AR_AS_LONG(self) * AR_AS_DOUBLE(other));
     return AR_INTEGER(AR_AS_LONG(self) * AR_AS_LONG(other));
 }
 
 arana_integer_div(AR_SIG, AR self, AR args)
 {
     AR other;
-    AR_PARSE(args, "I::div", &other);
-    return AR_FLOAT((Ar_float)AR_AS_LONG(self) /
-                    (Ar_float)AR_AS_LONG(other));
+    AR_PARSE(args, "N::div", &other);
+    if (AR_IS_FLOAT(other))
+        return AR_FLOAT((Ar_float)AR_AS_LONG(self) / AR_AS_DOUBLE(other));
+    return AR_FLOAT((Ar_float)AR_AS_LONG(self) / (Ar_float)AR_AS_LONG(other));
 }
 
 static AR