[Nickle] nickle: Branch 'master' - 3 commits

Keith Packard keithp at keithp.com
Wed Nov 27 15:38:32 PST 2024


 autogen.sh          |    7 ++++---
 configure.ac        |   18 +++++++++++++++++-
 float.c             |    7 +++----
 test/Makefile.am    |    2 +-
 test/math-tables.sh |   13 +++++++++++--
 test/meson.build    |   15 +++++++++++++--
 6 files changed, 49 insertions(+), 13 deletions(-)

New commits:
commit 75f4871cd7fe9b89936997a30fcae53053a4f051
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Nov 27 15:36:52 2024 -0800

    float: Recompute exponent when rounding value in print
    
    Avoid needing to check for overflow past base by simply restarting
    the whole computation from the top after rounding the value.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/float.c b/float.c
index 82be9f7..8fd9055 100644
--- a/float.c
+++ b/float.c
@@ -807,6 +807,7 @@ FloatPrint (Value f, Value fv, char format, int base, int width, int prec, int f
     m = NewInteger (Positive, a->mant->mag);
     
     m = Times (m, fratio);
+try_again:
     if (True (Less (m, One)))
     {
 	m = Times (m, NewInt (base));
@@ -872,8 +873,7 @@ FloatPrint (Value f, Value fv, char format, int base, int width, int prec, int f
     
     int_part = Floor (m);
     frac_part = Minus (m, int_part);
-	
-try_again:	
+
     if (ValueIsInteger(int_part))
 	int_n = IntegerMag(int_part);
     else
@@ -954,10 +954,9 @@ try_again:
 	 */
 	if (GreaterEqual (frac_part, One) == TrueVal)
 	{
-	    frac_part = Minus (frac_part, One);
-	    int_part = Plus (int_part, One);
 	    rounded = True;
 	    free (int_buffer);
+	    m = Plus(int_part, frac_part);
 	    goto try_again;
 	}
     }
commit 32afcf38a09b8b93adcfbc5dbf870ecf4fea92af
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Nov 27 15:35:57 2024 -0800

    Clean up test/math-tables.sh
    
    Find all progs at configure time.
    Add '-o' option to avoid needing to capture output.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index e761967..620a300 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,7 +26,23 @@ AC_CHECK_PROGS([YACC], byacc yacc bison, yacc)
 case "$YACC" in
 *bison)	YACC="$YACC -y"	;;
 esac
-
+AC_PATH_PROG(BC, bc, yes, no)
+if test "$BC" = "no"; then
+    AC_MSG_ERROR([Missing bc])
+fi
+AC_PATH_PROG(FMT, fmt, yes, no)
+if test "$FMT" = "no"; then
+    AC_MSG_ERROR([Missing fmt])
+fi
+AC_PATH_PROG(TR, tr, yes, no)
+if test "$TR" = "no"; then
+    AC_MSG_ERROR([Missing tr])
+fi
+AC_PATH_PROG(EXPR, expr, yes, no)
+if test "$EXPR" = "no"; then
+    AC_MSG_ERROR([Missing expr])
+fi
+	
 dnl Checks for libraries.
 AC_CHECK_FUNC(log,,AC_CHECK_LIB(m, log))
 AC_CHECK_FUNC(gethostbyname,,AC_CHECK_LIB(nsl, gethostbyname))
diff --git a/test/Makefile.am b/test/Makefile.am
index 598cfcb..7748aab 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -37,6 +37,6 @@ EXTRA_DIST=$(check_SCRIPTS) math-tables.sh math-funcs.bc
 math.5c: $(TABLES)
 
 $(TABLES): math-tables.sh math-funcs.bc
-	$(srcdir)/math-tables.sh > $(TABLES)
+	$(srcdir)/math-tables.sh -o $(TABLES)
 
 CLEANFILES=$(TABLES)
diff --git a/test/math-tables.sh b/test/math-tables.sh
index cfc60a4..e252d41 100755
--- a/test/math-tables.sh
+++ b/test/math-tables.sh
@@ -1,5 +1,14 @@
 #!/bin/sh
 
+case "$1" in
+    "-o")
+	shift
+	output="$1"
+	shift
+	exec > $output
+	;;
+esac
+
 dir=`dirname $0`
 
 # Which tables to generate
@@ -42,11 +51,11 @@ if [ $# -gt 0 ]; then
     done
 fi
 
-# sine and cosine table
-
 inc=1
 ainc=1
 
+# sine and cosine table
+
 echo "typedef struct { real angle, sin, cos; } sin_cos_t;"
 echo "sin_cos_t[] sin_cos_table = {"
 
diff --git a/test/meson.build b/test/meson.build
index 5c402bf..04e32b6 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -28,10 +28,21 @@ tests = [
 ]
 
 prog_math_tables = find_program('math-tables.sh', required: true)
+prog_bc = find_program('bc', required: true)
+prog_fmt = find_program('fmt', required: true)
+prog_tr = find_program('tr', required: true)
+prog_expr = find_program('expr', required: true)
+
 math_tables_dep = custom_target('math-tables.5c',
-				capture: true,
-				command: prog_math_tables,
+				command: [prog_math_tables, '-o', '@OUTPUT@'],
 				output: 'math-tables.5c',
+				env: {
+				       'BC': prog_bc.full_path(),
+				       'EXPR': prog_expr.full_path(),
+				       'FMT': prog_fmt.full_path(),
+				       'TR': prog_tr.full_path()
+				     },
+				depend_files: 'math-funcs.bc',
 				install: true,
 				install_dir: nickle_testdir
 			       )
commit 816ee6f7a8011e4bd79e529a431ab1c457ff9906
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Nov 27 15:34:47 2024 -0800

    autogen: Support building in subdir
    
    Use the path to autogen.sh to find the top source dir
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/autogen.sh b/autogen.sh
index 85694fc..d658275 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -5,6 +5,7 @@
 # runs autotools to create ./configure and friends
 #
 # configure depends on version.m4, but autoreconf does not realize this
-rm configure
-autoreconf -Wall -v --install || exit 1
-./configure "$@"
+dir=`dirname $0`
+rm $dir/configure
+(cd $dir && autoreconf -Wall -v --install) || exit 1
+$dir/configure "$@"


More information about the Nickle mailing list