ref: 74761f99b3ab80b2df581c1c141d28f9681f6c3d
parent: 83aa7a0b13d28c259531b29d6ca889f91f144743
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Nov 13 01:25:16 EST 2024
math: always use doubles; add log10 and pow
--- a/builtins.c
+++ b/builtins.c
@@ -432,12 +432,6 @@
BUILTIN(lname, cname) \
{ \
argcount(nargs, 1); \
- if(iscprim(args[0])){ \
- cprim_t *cp = (cprim_t*)ptr(args[0]); \
- numerictype_t nt = cp_numtype(cp); \
- if(nt == T_FLOAT) \
- return mk_float(cname##f(*(float*)cp_data(cp))); \
- } \
return mk_double(cname(todouble(args[0]))); \
}
@@ -444,6 +438,7 @@
BUILTIN_("sqrt", sqrt)
BUILTIN_("exp", exp)
BUILTIN_("log", log)
+BUILTIN_("log10", log10)
BUILTIN_("sin", sin)
BUILTIN_("cos", cos)
BUILTIN_("tan", tan)
@@ -450,3 +445,13 @@
BUILTIN_("asin", asin)
BUILTIN_("acos", acos)
BUILTIN_("atan", atan)
+
+#undef BUILTIN_
+#define BUILTIN_(lname, cname) \
+ BUILTIN(lname, cname) \
+ { \
+ argcount(nargs, 2); \
+ return mk_double(cname(todouble(args[0]), todouble(args[1]))); \
+ }
+
+BUILTIN_("pow", pow)
--- a/plan9/platform.h
+++ b/plan9/platform.h
@@ -31,15 +31,6 @@
#define towupper toupperrune
#define towlower tolowerrune
#define iswalpha isalpharune
-#define sqrtf sqrt
-#define expf exp
-#define logf log
-#define sinf sin
-#define cosf cos
-#define tanf tan
-#define asinf asin
-#define acosf acos
-#define atanf atan
#define signbit(r) ((*(uint64_t*)&(r)) & BIT63)
#define isfinite(d) (((*(uint64_t*)&(d))&0x7ff0000000000000ULL) != 0x7ff0000000000000ULL)