From e266fbd09e78faf9248be70d7b6ce7e7b4fc9dcd Mon Sep 17 00:00:00 2001 From: dzaima Date: Thu, 8 Sep 2022 23:18:47 +0300 Subject: [PATCH] basic float monadic arith loops, incl. -fno-math-errno --- makefile | 2 +- src/builtins/arithm.c | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/makefile b/makefile index c110a1b4..7d39a8e1 100644 --- a/makefile +++ b/makefile @@ -110,7 +110,7 @@ else NOWARN = -Wno-parentheses endif -ALL_CC_FLAGS = -std=gnu11 -Wall -Wno-unused-function -fms-extensions -ffp-contract=off $(CCFLAGS) $(f) $(i_f) $(NOWARN) -DSINGELI=$(i_singeli) -DFFI=$(i_FFI) $(SHARED_CCFLAGS) +ALL_CC_FLAGS = -std=gnu11 -Wall -Wno-unused-function -fms-extensions -ffp-contract=off -fno-math-errno $(CCFLAGS) $(f) $(i_f) $(NOWARN) -DSINGELI=$(i_singeli) -DFFI=$(i_FFI) $(SHARED_CCFLAGS) ALL_LD_FLAGS = $(LDFLAGS) $(lf) $(i_lf) $(i_PIE) $(i_LD_LIBS) ifneq (${manualJobs},1) diff --git a/src/builtins/arithm.c b/src/builtins/arithm.c index 9f267ab4..ddee07a6 100644 --- a/src/builtins/arithm.c +++ b/src/builtins/arithm.c @@ -63,10 +63,32 @@ GC1i("¬", not, 1-v, v<=-MAX, 1-v, { if(xe==el_bit) return bit_negate(x); }, 0) +#define GC1f(N, F, MSG) B N##_c1(B t, B x) { \ + if (isF64(x)) { f64 xv=o2fG(x); return m_f64(F); } \ + if (isArr(x)) { \ + u8 xe = TI(x,elType); \ + if (elNum(xe)) { \ + if (xe!=el_f64) x=taga(cpyF64Arr(x)); \ + u64 ia = IA(x); \ + f64* xp = f64any_ptr(x); \ + f64* rp; B r = m_f64arrc(&rp, x); \ + for (i64 i = 0; i < ia; i++) { \ + f64 xv=xp[i]; rp[i] = (F); \ + } \ + decG(x); return r; \ + } \ + SLOW1("arithm " #N, x); \ + return arith_recm(N##_c1, x); \ + } \ + thrM(MSG); \ +} + +GC1f( div, 1/xv, "÷: Getting reciprocal of non-number") +GC1f(root, sqrt(xv), "√: Getting square root of non-number") +#undef GC1f + #define P1(N) { if(isArr(x)) { SLOW1("arithm " #N, x); return arith_recm(N##_c1, x); } } -B div_c1(B t, B x) { if (isF64(x)) return m_f64( 1/x.f ); P1( div); thrM("÷: Getting reciprocal of non-number"); } B pow_c1(B t, B x) { if (isF64(x)) return m_f64( exp(x.f)); P1( pow); thrM("⋆: Getting exp of non-number"); } -B root_c1(B t, B x) { if (isF64(x)) return m_f64( sqrt(x.f)); P1( root); thrM("√: Getting root of non-number"); } B log_c1(B t, B x) { if (isF64(x)) return m_f64( log(x.f)); P1( log); thrM("⋆⁼: Getting log of non-number"); } B sin_c1(B t, B x) { if (isF64(x)) return m_f64( sin(x.f)); P1( sin); thrM("•math.Sin: Argument contained non-number"); } B cos_c1(B t, B x) { if (isF64(x)) return m_f64( cos(x.f)); P1( cos); thrM("•math.Cos: Argument contained non-number"); }