diff options
-rw-r--r-- | ChangeLog | 20 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | arith.c | 28 | ||||
-rwxr-xr-x | configure | 20 | ||||
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 6 |
7 files changed, 76 insertions, 4 deletions
@@ -1,3 +1,23 @@ +2014-07-18 Kaz Kylheku <kaz@kylheku.com> + + * Makefile (conftest, conftest2): Link math + library so we can test for math functions. + + * arith.c (log2_init): New static function. + (log2, logtwo): New functions. + (l2): New static variable. + (arith_init): Call log2_init. + + * configure (lang_flags): Switching _XOPEN_SOURCE + from 500 to 600 to reveal log2. + Adding test for log2. + + * eval.c (eval_init): Register log2 intrinsic. + + * lib.h (logtwo): Declared. + + * txr.1: Documented log2. + 2014-07-15 Kaz Kylheku <kaz@kylheku.com> * match.c (v_do, v_require): Set up and tear down environment frame, @@ -218,10 +218,10 @@ config.make config.h: # conftest: conftest.c - $(CC) $(CFLAGS) -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ -lm conftest2: conftest1.c conftest2.c - $(CC) $(CFLAGS) -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ -lm conftest.syms: conftest.o $(NM) -n -t o -P $^ > $@ @@ -1444,6 +1444,33 @@ val logten(val num) return flo(log10(c_flo(to_float(lit("log"), num)))); } +#if HAVE_LOG2 + +static void log2_init(void) +{ +} + +#else + +static double l2; + +static void log2_init(void) +{ + l2 = log(2.0); +} + +double log2(double x) +{ + return log(x)/l2; +} + +#endif + +val logtwo(val num) +{ + return flo(log2(c_flo(to_float(lit("log"), num)))); +} + val expo(val num) { return flo(exp(c_flo(to_float(lit("exp"), num)))); @@ -2038,4 +2065,5 @@ void arith_init(void) mp_set_intptr(&NUM_MAX_MP, NUM_MAX); mp_init(&INT_PTR_MAX_MP); mp_set_intptr(&INT_PTR_MAX_MP, INT_PTR_MAX); + log2_init(); } @@ -97,7 +97,7 @@ yacc='$(cross)$(tool_prefix)$(yaccname)' yacc_given= nm='$(cross)$(tool_prefix)nm' opt_flags=-O2 -lang_flags='-ansi -D_XOPEN_SOURCE=500' +lang_flags='-ansi -D_XOPEN_SOURCE=600' diag_flags='-Wall -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=strict-prototypes' debug_flags=-g inline= @@ -1809,6 +1809,24 @@ else printf "no\n" fi +printf "Checking for log2 ... " + +cat > conftest.c <<! +#include <math.h> + +int main(void) +{ + double x = log2(42.0); + return 0; +} +! +if conftest ; then + printf "yes\n" + printf "#define HAVE_LOG2 1\n" >> config.h +else + printf "no\n" +fi + # # Dependent variables # @@ -3585,6 +3585,7 @@ void eval_init(void) reg_fun(intern(lit("atan2"), user_package), func_n2(atang2)); reg_fun(intern(lit("log"), user_package), func_n1(loga)); reg_fun(intern(lit("log10"), user_package), func_n1(logten)); + reg_fun(intern(lit("log2"), user_package), func_n1(logtwo)); reg_fun(intern(lit("exp"), user_package), func_n1(expo)); reg_fun(intern(lit("sqrt"), user_package), func_n1(sqroot)); reg_fun(intern(lit("cum-norm-dist"), user_package), func_n1(cum_norm_dist)); @@ -544,6 +544,7 @@ val atang(val); val atang2(val, val); val loga(val); val logten(val num); +val logtwo(val num); val expo(val); val logand(val, val); val logior(val, val); @@ -10871,7 +10871,7 @@ functions. The <num> argument to asin and acos must be in the range -1.0 to 1.0. The atan2 function converts the rectilinear coordinates <x> and <y> to an angle in polar coordinates in the range [0, 2pi). -.SS Functions exp, log, log10 +.SS Functions exp, log, log10 and log2 .TP Syntax: @@ -10879,6 +10879,7 @@ Syntax: (exp <number>) (log <number>) (log10 <number>) + (log2 <number>) .TP Description: @@ -10892,6 +10893,9 @@ be a positive value. The log10 function calculates the base 10 logarithm of its argument, which must be a positive value. +The log2 function calculates the base 2 logarithm of its argument, which must +be a positive value. + Integer arguments are converted to floats. .SS Functions expt, sqrt, isqrt |