[Nickle] nickle: Branch 'master' - 2 commits
Keith Packard
keithp at keithp.com
Wed Nov 9 09:49:53 PST 2022
configure.ac | 7 +++++++
float.c | 4 ++++
lex.l | 37 +++++++++++++++++++++++++------------
3 files changed, 36 insertions(+), 12 deletions(-)
New commits:
commit 90430fcf2f2d8abf8987e3c364bba449da60f071
Author: Keith Packard <keithp at keithp.com>
Date: Wed Nov 9 09:35:55 2022 -0800
Autodetect 'significand' function
This is a non-standard GNU extension which can be replaced with
scalbn (at some performance cost). Provide that replacement along
with autodetection code in the configure script.
Signed-off-by: Keith Packard <keithp at keithp.com>
diff --git a/configure.ac b/configure.ac
index 2607ba3..6691cf5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -97,6 +97,13 @@ AC_FUNC_VPRINTF
AC_CHECK_FUNCS(unsetenv setenv putenv gettimeofday hstrerror select)
AC_CHECK_FUNCS(sigaction sigrelse sigignore setrlimit getrlimit)
AC_CHECK_FUNCS(dlopen dlsym dlerror dlclose)
+AC_CHECK_FUNC(significand,,AC_CHECK_LIB(m, significand))
+
+case "$ac_cv_func_significand""$ac_cv_lib_m_significand" in
+ *yes*)
+ AC_DEFINE(HAVE_SIGNIFICAND,1,[Has significand function])
+ ;;
+esac
AC_PATH_PROGS([ASCIIDOCTORPDF],[asciidoctor-pdf])
diff --git a/float.c b/float.c
index 30b7c9f..833af76 100644
--- a/float.c
+++ b/float.c
@@ -1122,7 +1122,11 @@ NewDoubleFloat (double d)
double_digit dd;
if (d == 0.0) RETURN (Zero);
e = ilogb (d);
+#ifdef HAVE_SIGNIFICAND
m = significand (d);
+#else
+ m = scalbn(d, -e);
+#endif
ms = Positive;
if (m < 0)
{
commit 1667ba32d605d7a1d227fcc6364980e0175980e5
Author: Keith Packard <keithp at keithp.com>
Date: Fri Feb 25 01:19:05 2022 -0800
Use base-10 for all float exponents. Use base 2 for base 2/8/16 powers
This makes base 16 float input compatible with C, which is pretty useful, and
makes base 2 and base 8 just different representations of the significand.
Signed-off-by: Keith Packard <keithp at keithp.com>
diff --git a/lex.l b/lex.l
index 98e48af..7c8e53b 100644
--- a/lex.l
+++ b/lex.l
@@ -581,7 +581,7 @@ has_member { yylval.ints = HASMEMBER; return HASMEMBER; }
yylval.value = atov(yytext+2, 8);
return OCTAL_NUM;
}
-0o(([0-7_]+((\.[0-7_]*(\{[0-7_]+\})?)?))|(\.[0-7_]+)|(\.[0-7_]*\{[0-7_]+\}))(([Ee][-+]?[0-7_]+)?) {
+0o(([0-7_]+((\.[0-7_]*(\{[0-7_]+\})?)?))|(\.[0-7_]+)|(\.[0-7_]*\{[0-7_]+\}))(([Ee][-+]?[0-9_]+)?) {
yylval.value = aetov (yytext+2, 8);
return OCTAL_FLOAT;
}
@@ -597,7 +597,7 @@ has_member { yylval.ints = HASMEMBER; return HASMEMBER; }
yylval.value = atov(yytext+2, 2);
return BINARY_NUM;
}
-0b(([01_]+((\.[01_]*(\{[01_]+\})?)?))|(\.[01_]+)|(\.[01_]*\{[01_]+\}))(([Ee][-+]?[01_]+)?) {
+0b(([01_]+((\.[01_]*(\{[01_]+\})?)?))|(\.[01_]+)|(\.[01_]*\{[01_]+\}))(([Ee][-+]?[0-9_]+)?) {
yylval.value = aetov (yytext+2, 2);
return BINARY_FLOAT;
}
@@ -613,7 +613,7 @@ has_member { yylval.ints = HASMEMBER; return HASMEMBER; }
yylval.value = atov(yytext+2, 16);
return HEX_NUM;
}
-0x(([0-9a-fA-F_]+((\.[0-9a-fA-F_]*(\{[0-9a-fA-F_]+\})?)?))|(\.[0-9a-fA-F_]+)|(\.[0-9a-fA-F_]*\{[0-9a-fA-F_]+\}))(([Pp][-+]?[0-9a-fA-F_]+)?) {
+0x(([0-9a-fA-F_]+((\.[0-9a-fA-F_]*(\{[0-9a-fA-F_]+\})?)?))|(\.[0-9a-fA-F_]+)|(\.[0-9a-fA-F_]*\{[0-9a-fA-F_]+\}))(([Pp][-+]?[0-9_]+)?) {
yylval.value = aetov (yytext+2, 16);
return HEX_FLOAT;
}
@@ -840,9 +840,29 @@ aetov (char *s, int base)
ENTER ();
char *int_part, *frac_part, *rep_part, *exp_part, *next;
int sign, int_len = -1, frac_len = -1, rep_len = -1, exp_frac_len = -1, esign;
- int exp_base = 10;
Value v, sv;
+ char exp_char;
+ int exp_base;
+ switch (base) {
+ case 2:
+ exp_char = 'e';
+ exp_base = 2;
+ break;
+ case 8:
+ exp_char = 'e';
+ exp_base = 2;
+ break;
+ case 10:
+ default:
+ exp_char = 'e';
+ exp_base = 10;
+ break;
+ case 16:
+ exp_char = 'p';
+ exp_base = 2;
+ break;
+ }
int_part = s;
sign = 1;
if (*int_part == '+')
@@ -870,14 +890,7 @@ aetov (char *s, int base)
RETURN(Void); /* can't happen */
}
}
- exp_part = NULL;
- if (base == 10) {
- exp_part = scan_number(next, 'e', &exp_frac_len);
- exp_base = 10;
- } else if (base == 16) {
- exp_part = scan_number(next, 'p', &exp_frac_len);
- exp_base = 2;
- }
+ exp_part = scan_number(next, exp_char, &exp_frac_len);
if (exp_part) {
if (frac_len < 0)
frac_len = exp_frac_len;
More information about the Nickle
mailing list