Compare commits

..

7 Commits

Author SHA1 Message Date
Landon Curt Noll
4bec694df3 Release calc version 2.12.7.0
The following are the changes from calc version 2.12.7.0 to date:

    Added a patch to replaces the manual search for include files
    in $(INCDIR) in the have_*.h targets with compiler invocations.
    Thanks goes to Helmut Grohne (helmut at subdivi dot de) who
    implemented the patch and posted it to the Debian bug tracker
    and Martin Buck (m at rtin-buck dor de) for forwarding it to us.

    The check_include make rule was fixed to not assume /usr/include.

    The qprintnum() function now takes outdigits as a 3rd argument.
    Most of the time, this 3rd argument is just conf->outdigits.
    But when it comes to the experimental '%g', this value can
    change.  This avoids having to modify conf->outdigits.

    Fixed a problem where gcc complains about E_FUNC not being defined
    for Linux systems as reported by Martin Buck (m at rtin-buck dor de).

    Updated the help files help/config, help/display, help/epsilon,
    help/fprint, help/printf, and help/strprintf to give more
    examples of how display digits and epsilon precision interact
    with displaying values.

    Added more information about %g in the help file help/printf.

    The '\a' is now recognized in a printf format string as the
    single byte audible bell character (byte 0x07 in ASCII encoding).

    The following is a partial list of escape sequences recognized
    in strings and in printf formats:

        \a      audible bell    byte 0x07 in ASCII encoding
        \b      backspace       byte 0x08 in ASCII encoding
        \f      form feed       byte 0x0c in ASCII encoding
        \n      newline         byte 0x0b in ASCII encoding
        \r      return          byte 0x0a in ASCII encoding
        \t      tab             byte 0x0d in ASCII encoding
        \v      vertical tab    byte 0x09 in ASCII encoding
2018-11-04 17:11:31 -08:00
Landon Curt Noll
4870a7a164 Sync check_include rule with Makefile.ship 2018-11-04 17:10:46 -08:00
Landon Curt Noll
84ccb37bc3 Regualrize escape characters
Regularized the case statements in qio.c, str.c, and token.c
that relate to escape characters.

The '\a' is now recognized in a printf format string as the
single byte audible bell character (byte 0x07 in ASCII encoding).

The following is a partial list of escape sequences recognized
in strings and in printf formats:

    \a      audible bell    byte 0x07 in ASCII encoding
    \b      backspace       byte 0x08 in ASCII encoding
    \f      form feed       byte 0x0c in ASCII encoding
    \n      newline         byte 0x0b in ASCII encoding
    \r      return          byte 0x0a in ASCII encoding
    \t      tab             byte 0x0d in ASCII encoding
    \v      vertical tab    byte 0x09 in ASCII encoding
2018-11-04 17:08:11 -08:00
Landon Curt Noll
29c6e9325f Fix issue with E_FUNC under linux
Fixed a problem where gcc complains about E_FUNC not being defined
for Linux systems as reported by Martin Buck (m at rtin-buck dor de).
2018-11-04 17:01:24 -08:00
Landon Curt Noll
81a4a4f828 Improve string and printing documentation
Updated the help files help/config, help/display, help/epsilon,
help/fprint, help/printf, and help/strprintf to give more
examples of how display digits and epsilon precision interact
with displaying values.

Added more information about %g in the help file help/printf.

The '\a' is now recognized in a printf format string as the
single byte audible bell character (byte 0x07 in ASCII encoding).

The following is a partial list of escape sequences recognized
in strings and in printf formats:

    \a      audible bell    byte 0x07 in ASCII encoding
    \b      backspace       byte 0x08 in ASCII encoding
    \f      form feed       byte 0x0c in ASCII encoding
    \n      newline         byte 0x0b in ASCII encoding
    \r      return          byte 0x0a in ASCII encoding
    \t      tab             byte 0x0d in ASCII encoding
    \v      vertical tab    byte 0x09 in ASCII encoding
2018-11-04 17:00:15 -08:00
Landon Curt Noll
1cdb5172d8 Fix Makefile lines that picky complains about 2018-10-19 19:41:58 -07:00
Landon Curt Noll
54a7a3f7bc Release 2.12.6.10
Added a patch to replaces the manual search for include files
    in $(INCDIR) in the have_*.h targets with compiler invocations.
    Thanks goes to Helmut Grohne <helmut at subdivi dot de> who
    implemented the patch and posted it to the Debian bug tracker
    and Martin Buck (m at rtin-buck dor de) for forwarding it to us.

    The check_include make rule was fixed to not assume /usr/include.

    The qprintnum() function now takes outdigits as a 3rd argument.
    Most of the time, this 3rd argument is just conf->outdigits.
    But when it comes to the experimental '%g', this value can
    change.  This avoids having to modify conf->outdigits.
2018-10-19 19:33:57 -07:00
22 changed files with 459 additions and 173 deletions

47
CHANGES
View File

@@ -1,4 +1,44 @@
The following are the changes from calc version 2.12.6.9 to date:
The following are the changes from calc version 2.12.7.0 to date:
Added a patch to replaces the manual search for include files
in $(INCDIR) in the have_*.h targets with compiler invocations.
Thanks goes to Helmut Grohne (helmut at subdivi dot de) who
implemented the patch and posted it to the Debian bug tracker
and Martin Buck (m at rtin-buck dor de) for forwarding it to us.
The check_include make rule was fixed to not assume /usr/include.
The qprintnum() function now takes outdigits as a 3rd argument.
Most of the time, this 3rd argument is just conf->outdigits.
But when it comes to the experimental '%g', this value can
change. This avoids having to modify conf->outdigits.
Fixed a problem where gcc complains about E_FUNC not being defined
for Linux systems as reported by Martin Buck (m at rtin-buck dor de).
Updated the help files help/config, help/display, help/epsilon,
help/fprint, help/printf, and help/strprintf to give more
examples of how display digits and epsilon precision interact
with displaying values.
Added more information about %g in the help file help/printf.
The '\a' is now recognized in a printf format string as the
single byte audible bell character (byte 0x07 in ASCII encoding).
The following is a partial list of escape sequences recognized
in strings and in printf formats:
\a audible bell byte 0x07 in ASCII encoding
\b backspace byte 0x08 in ASCII encoding
\f form feed byte 0x0c in ASCII encoding
\n newline byte 0x0b in ASCII encoding
\r return byte 0x0a in ASCII encoding
\t tab byte 0x0d in ASCII encoding
\v vertical tab byte 0x09 in ASCII encoding
The following are the changes from calc version 2.12.6.9 to 2.12.6.9:
Fixed a number of core dump bugs related to the calculation of
tan(), cot(), sec(), csc(), tanh(), coth(), sech(), and csch(),
@@ -26,8 +66,9 @@ The following are the changes from calc version 2.12.6.9 to date:
INCDIR= $(shell xcrun --show-sdk-path --sdk macosx)/usr/include
to determine the upper path of the /usr/include directory for macOS.
The Darwin target seems to not automatically detected. For now,
under macOS, declare the target as darwin:
In some rare cases, the Darwin target seems to not automatically detected.
If you are running under macOS, and that happens, you can force
the target to be Darwin:
# for macOS users only, force the target to be darwin
#

View File

@@ -207,30 +207,9 @@ all: fix_version check_include
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
check_include:
$(Q) if [ ! -d /usr/include ]; then \
echo "ERROR: critical directory missing: /usr/include" 1>&2; \
echo "Without this critical directory, we cannot compile." 1>&2; \
echo 1>&2; \
echo "Perhaps your system isn't setup to compile C source?" 1>&2; \
echo "For example, Apple OS X / darwin requres that XCode" 1>&2; \
echo "must be installed and that you run the command:" 1>&2; \
echo 1>&2; \
echo " xcode-select --install" 1>&2; \
echo 1>&2; \
exit 1; \
fi
$(Q) if [ ! -f /usr/include/stdio.h ]; then \
echo "ERROR: critical include files are missing" 1>&2; \
echo "Without this critical directory, we cannot compile." 1>&2; \
echo 1>&2; \
echo "Perhaps your system isn't setup to compile C source?" 1>&2; \
echo "For example, Apple OS X / darwin requres that XCode" 1>&2; \
echo "must be installed and that you run the command:" 1>&2; \
echo 1>&2; \
echo " xcode-select --install" 1>&2; \
echo 1>&2; \
exit 1; \
fi
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
calc-dynamic-only:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='

View File

@@ -1054,7 +1054,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.6.9
VERSION= 2.12.7.0
# Names of shared libraries with versions
#
@@ -2179,25 +2179,15 @@ TARGETS= ${EARLY_TARGETS} ${BLD_TYPE} ${LATE_TARGETS}
all: check_include ${BLD_TYPE} CHANGES
check_include:
$(Q) if [ ! -d ${INCDIR} ]; then \
echo "ERROR: critical directory missing: /usr/include" 1>&2; \
echo "Without this critical directory, we cannot compile." 1>&2; \
echo 1>&2; \
$(Q) if ! echo '#include <stdio.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo "ERROR: Missing critical <stdio.h> include file." 1>&2; \
echo "Without critical include files, we cannot compile." 1>&2; \
echo "Perhaps your system isn't setup to compile C source?" 1>&2; \
echo "For example, Apple OS X / darwin requres that XCode" 1>&2; \
echo "must be installed and that you run the command:" 1>&2; \
echo 1>&2; \
echo " xcode-select --install" 1>&2; \
echo "For example, Apple macOS / Darwin requres that XCode" 1>&2; \
echo "must be installed." 1>&2; \
echo 1>&2; \
exit 1; \
fi
$(Q) if [ ! -f ${INCDIR}/stdio.h ]; then \
echo "ERROR: critical include files are missing" 1>&2; \
echo "Without this critical directory, we cannot compile." 1>&2; \
echo 1>&2; \
echo "Perhaps your system isn't setup to compile C source?" 1>&2; \
echo "For example, Apple OS X / darwin requres that XCode" 1>&2; \
echo "must be installed and that you run the command:" 1>&2; \
echo "Also macOS users might later to run this command:" 1>&2; \
echo 1>&2; \
echo " xcode-select --install" 1>&2; \
echo 1>&2; \
@@ -2477,22 +2467,15 @@ endian_calc.h: endian${EXT} ${MAKE_FILE}
${Q} echo '' >> endian_calc.h
${Q} echo '/* what byte order are we? */' >> endian_calc.h
-${Q} if [ X"${CALC_BYTE_ORDER}" = X ]; then \
if [ -f ${INCDIR}/endian.h ]; then \
if echo '#include <endian.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#include <endian.h>' >> endian_calc.h; \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
elif [ -f ${INCDIR}/machine/endian.h ]; then \
elif echo '#include <machine/endian.h>' | \
${CC} -E - >/dev/null 2>&1; then \
echo '#include <machine/endian.h>' >> endian_calc.h; \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
elif [ -f ${INCDIR}/sys/endian.h ]; then \
echo '#include <sys/endian.h>' >> endian_calc.h; \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
elif [ -f /usr/include/endian.h ]; then \
echo '#include <endian.h>' >> endian_calc.h; \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
elif [ -f /usr/include/machine/endian.h ]; then \
echo '#include <machine/endian.h>' >> endian_calc.h; \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
elif [ -f /usr/include/sys/endian.h ]; then \
elif echo '#include <sys/endian.h>' | \
${CC} -E- >/dev/null 2>&1; then \
echo '#include <sys/endian.h>' >> endian_calc.h; \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
else \
@@ -2559,9 +2542,7 @@ have_times.h: ${MAKE_FILE}
echo '#define HAVE_TIMES_H /* yes */' >> have_times.h; \
elif [ X"${HAVE_TIMES_H}" = X"NO" ]; then \
echo '#undef HAVE_TIMES_H /* no */' >> have_times.h; \
elif [ -f ${INCDIR}/times.h ]; then \
echo '#define HAVE_TIMES_H /* yes */' >> have_times.h; \
elif [ -f /usr/include/times.h ]; then \
elif echo '#include <times.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_TIMES_H /* yes */' >> have_times.h; \
else \
echo '#undef HAVE_TIMES_H /* no */' >> have_times.h; \
@@ -2570,9 +2551,7 @@ have_times.h: ${MAKE_FILE}
echo '#define HAVE_SYS_TIMES_H /* yes */' >> have_times.h; \
elif [ X"${HAVE_SYS_TIMES_H}" = X"NO" ]; then \
echo '#undef HAVE_SYS_TIMES_H /* no */' >> have_times.h; \
elif [ -f ${INCDIR}/sys/times.h ]; then \
echo '#define HAVE_SYS_TIMES_H /* yes */' >> have_times.h; \
elif [ -f /usr/include/sys/times.h ]; then \
elif echo '#include <sys/times.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_SYS_TIMES_H /* yes */' >> have_times.h; \
else \
echo '#undef HAVE_SYS_TIMES_H /* no */' >> have_times.h; \
@@ -2581,9 +2560,7 @@ have_times.h: ${MAKE_FILE}
echo '#define HAVE_TIME_H /* yes */' >> have_times.h; \
elif [ X"${HAVE_TIME_H}" = X"NO" ]; then \
echo '#undef HAVE_TIME_H /* no */' >> have_times.h; \
elif [ -f ${INCDIR}/time.h ]; then \
echo '#define HAVE_TIME_H /* yes */' >> have_times.h; \
elif [ -f /usr/include/time.h ]; then \
elif echo '#include <time.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_TIME_H /* yes */' >> have_times.h; \
else \
echo '#undef HAVE_TIME_H /* no */' >> have_times.h; \
@@ -2592,9 +2569,7 @@ have_times.h: ${MAKE_FILE}
echo '#define HAVE_SYS_TIME_H /* yes */' >> have_times.h; \
elif [ X"${HAVE_SYS_TIME_H}" = X"NO" ]; then \
echo '#undef HAVE_SYS_TIME_H /* no */' >> have_times.h; \
elif [ -f ${INCDIR}/sys/time.h ]; then \
echo '#define HAVE_SYS_TIME_H /* yes */' >> have_times.h; \
elif [ -f /usr/include/sys/time.h ]; then \
elif echo '#include <sys/time.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_SYS_TIME_H /* yes */' >> have_times.h; \
else \
echo '#undef HAVE_SYS_TIME_H /* no */' >> have_times.h; \
@@ -2630,9 +2605,7 @@ have_stdlib.h: ${MAKE_FILE}
echo '#define HAVE_STDLIB_H /* yes */' >> have_stdlib.h; \
elif [ X"${HAVE_STDLIB_H}" = X"NO" ]; then \
echo '#undef HAVE_STDLIB_H /* no */' >> have_stdlib.h; \
elif [ -f ${INCDIR}/stdlib.h ]; then \
echo '#define HAVE_STDLIB_H /* yes */' >> have_stdlib.h; \
elif [ -f /usr/include/stdlib.h ]; then \
elif echo '#include <stdlib.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_STDLIB_H /* yes */' >> have_stdlib.h; \
else \
echo '#undef HAVE_STDLIB_H /* no */' >> have_stdlib.h; \
@@ -2668,9 +2641,7 @@ have_unistd.h: ${MAKE_FILE}
echo '#define HAVE_UNISTD_H /* yes */' >> have_unistd.h; \
elif [ X"${HAVE_UNISTD_H}" = X"NO" ]; then \
echo '#undef HAVE_UNISTD_H /* no */' >> have_unistd.h; \
elif [ -f ${INCDIR}/unistd.h ]; then \
echo '#define HAVE_UNISTD_H /* yes */' >> have_unistd.h; \
elif [ -f /usr/include/unistd.h ]; then \
elif echo '#include <unistd.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_UNISTD_H /* yes */' >> have_unistd.h; \
else \
echo '#undef HAVE_UNISTD_H /* no */' >> have_unistd.h; \
@@ -2706,9 +2677,7 @@ have_string.h: ${MAKE_FILE}
echo '#define HAVE_STRING_H /* yes */' >> have_string.h; \
elif [ X"${HAVE_STRING_H}" = X"NO" ]; then \
echo '#undef HAVE_STRING_H /* no */' >> have_string.h; \
elif [ -f ${INCDIR}/string.h ]; then \
echo '#define HAVE_STRING_H /* yes */' >> have_string.h; \
elif [ -f /usr/include/string.h ]; then \
elif echo '#include <string.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_STRING_H /* yes */' >> have_string.h; \
else \
echo '#undef HAVE_STRING_H /* no */' >> have_string.h; \
@@ -2748,22 +2717,12 @@ terminal.h: ${MAKE_FILE}
echo '#undef USE_TERMIOS /* <termios.h> */' >> terminal.h; \
echo '#undef USE_TERMIO /* <termio.h> */' >> terminal.h; \
echo '#undef USE_SGTTY /* <sys/ioctl.h> */' >> terminal.h; \
elif [ -f ${INCDIR}/termios.h ]; then \
elif echo '#include <termios.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '/* use termios */' >> terminal.h; \
echo '#define USE_TERMIOS /* <termios.h> */' >> terminal.h; \
echo '#undef USE_TERMIO /* <termio.h> */' >> terminal.h; \
echo '#undef USE_SGTTY /* <sys/ioctl.h> */' >> terminal.h; \
elif [ -f ${INCDIR}/termio.h ]; then \
echo '/* use termio */' >> terminal.h; \
echo '#undef USE_TERMIOS /* <termios.h> */' >> terminal.h; \
echo '#define USE_TERMIO /* <termio.h> */' >> terminal.h; \
echo '#undef USE_SGTTY /* <sys/ioctl.h> */' >> terminal.h; \
elif [ -f /usr/include/termios.h ]; then \
echo '/* use termios */' >> terminal.h; \
echo '#define USE_TERMIOS /* <termios.h> */' >> terminal.h; \
echo '#undef USE_TERMIO /* <termio.h> */' >> terminal.h; \
echo '#undef USE_SGTTY /* <sys/ioctl.h> */' >> terminal.h; \
elif [ -f /usr/include/termio.h ]; then \
elif echo '#include <termio.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '/* use termio */' >> terminal.h; \
echo '#undef USE_TERMIOS /* <termios.h> */' >> terminal.h; \
echo '#define USE_TERMIO /* <termio.h> */' >> terminal.h; \

View File

@@ -1182,7 +1182,7 @@ comprint(COMPLEX *c)
return;
}
if (!qiszero(c->real) || qiszero(c->imag))
qprintnum(c->real, MODE_DEFAULT);
qprintnum(c->real, MODE_DEFAULT, conf->outdigits);
qtmp = c->imag[0];
if (qiszero(&qtmp))
return;
@@ -1192,7 +1192,7 @@ comprint(COMPLEX *c)
math_chr('-');
qtmp.num.sign = 0;
}
qprintnum(&qtmp, MODE_DEFAULT);
qprintnum(&qtmp, MODE_DEFAULT, conf->outdigits);
math_chr('i');
}

View File

@@ -348,7 +348,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.6.9
VERSION= 2.12.7.0
# Names of shared libraries with versions
#

View File

@@ -348,7 +348,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.6.9
VERSION= 2.12.7.0
# Names of shared libraries with versions
#

2
func.c
View File

@@ -335,7 +335,7 @@ f_str(VALUE *vp)
break;
case V_NUM:
math_divertio();
qprintnum(vp->v_num, MODE_DEFAULT);
qprintnum(vp->v_num, MODE_DEFAULT, conf->outdigits);
cp = math_getdivertedio();
result.v_str = makestring(cp);
break;

View File

@@ -949,6 +949,48 @@ EXAMPLE
; display()
50
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; /* NOTE: display has too few digits and epsilon is not small enough */
; config("display", 12),; /* or display(12),; */
; printf("%f\n", pi(1e-10));
3.1415926536
; config("epsilon", 1e-10),; /* or epsilon(1e-10),; */
; printf("%f\n", pi());
3.1415926536
; /* NOTE: display has too few digits yet epsilon is small enough */
; config("display", 12),; /* or display(12),; */
; printf("%f\n", pi(1e-72));
~3.141592653590
; config("epsilon", 1e-72),; /* or epsilon(1e-72),; */
; printf("%f\n", pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; config("display", 72),; /* or display(72),; */
; printf("%f\n", pi(1e-10));
3.1415926536
; config("epsilon", 1e-10),; /* or epsilon(1e-10),; */
; printf("%f\n", pi());
3.1415926536
/* NOTE: display has enough digits and epsilon is small enough */
; config("display", 72),; /* or display(72),; */
; printf("%f\n", pi(1e-72));
3.141592653589793238462643383279502884197169399375105820974944592307816406
; config("epsilon", 1e-72),; /* or epsilon(1e-72),; */
; printf("%f\n", pi());
3.141592653589793238462643383279502884197169399375105820974944592307816406
LIMITS
none
@@ -956,9 +998,9 @@ LINK LIBRARY
n/a
SEE ALSO
usage, custom, custom_cal, usage, epsilon, display
custom, custom_cal, display, epsilon, fprintf, printf, strprintf, usage
## Copyright (C) 1999-2007 Landon Curt Noll
## Copyright (C) 1999-2007,2018 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -45,6 +45,48 @@ EXAMPLE
; print display(5), 2/3
40 ~0.66667
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; /* NOTE: display has too few digits and epsilon is not small enough */
; display(12),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
; /* NOTE: display has too few digits yet epsilon is small enough */
; display(12),;
; printf("%f\n", pi(1e-72));
~3.141592653590
; epsilon(1e-72),;
; printf("%f\n", pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; display(72),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
/* NOTE: display has enough digits and epsilon is small enough */
; display(72),;
; printf("%f\n", pi(1e-72));
3.141592653589793238462643383279502884197169399375105820974944592307816406
; epsilon(1e-72),;
; printf("%f\n", pi());
3.141592653589793238462643383279502884197169399375105820974944592307816406
LIMITS
d >= 0
@@ -52,9 +94,9 @@ LINK LIBRARY
none
SEE ALSO
config
config, epsilon, fprintf, printf, strprintf
## Copyright (C) 2004 Landon Curt Noll
## Copyright (C) 2004,2018 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -16,13 +16,57 @@ DESCRIPTION
and sets the stored epsilon value to eps.
The stored epsilon value is used as default value for eps in
the functions appr(x, eps, rnd), sqrt(x, eps, rnd), etc.
many functions such as appr(x, eps, rnd), sqrt(x, eps, rnd),
pi(eps), sin(x, eps), tanh(x, eps), etc.
EXAMPLE
; epsilon(1e-20),;
; oldeps = epsilon(1e-6)
; print epsilon(), sqrt(2), epsilon(1e-4), sqrt(2), epsilon(oldeps)
; .000001 1.414214 .000001 1.4142 .0001
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; /* NOTE: display has too few digits and epsilon is not small enough */
; display(12),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
; /* NOTE: display has too few digits yet epsilon is small enough */
; display(12),;
; printf("%f\n", pi(1e-72));
~3.141592653590
; epsilon(1e-72),;
; printf("%f\n", pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; display(72),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
/* NOTE: display has enough digits and epsilon is small enough */
; display(72),;
; printf("%f\n", pi(1e-72));
3.141592653589793238462643383279502884197169399375105820974944592307816406
; epsilon(1e-72),;
; printf("%f\n", pi());
3.141592653589793238462643383279502884197169399375105820974944592307816406
LIMITS
none
@@ -31,9 +75,9 @@ LINK LIBRARY
NUMBER *_epsilon_
SEE ALSO
config
config, display, fprintf, printf, strprintf
## Copyright (C) 1999 Landon Curt Noll
## Copyright (C) 1999,2018 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -45,6 +45,48 @@ EXAMPLE
[2] = "undefined"
[3] = NULL
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; /* NOTE: display has too few digits and epsilon is not small enough */
; display(12),;
; fprintf(files(1), "%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; fprintf(files(1), "%f\n", pi());
3.1415926536
; /* NOTE: display has too few digits yet epsilon is small enough */
; display(12),;
; fprintf(files(1), "%f\n", pi(1e-72));
~3.141592653590
; epsilon(1e-72),;
; fprintf(files(1), "%f\n", pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; display(72),;
; fprintf(files(1), "%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; fprintf(files(1), "%f\n", pi());
3.1415926536
/* NOTE: display has enough digits and epsilon is small enough */
; display(72),;
; fprintf(files(1), "%f\n", pi(1e-72));
3.141592653589793238462643383279502884197169399375105820974944592307816406
; epsilon(1e-72),;
; fprintf(files(1), "%f\n", pi());
3.141592653589793238462643383279502884197169399375105820974944592307816406
LIMITS
The number of arguments of fprintf() is not to exceed 1024.
@@ -52,9 +94,9 @@ LINK LIBRARY
none
SEE ALSO
printf, strprintf, print
config, display, epsilon, printf, strprintf
## Copyright (C) 1999-2006 Landon Curt Noll
## Copyright (C) 1999-2006,2018 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -51,7 +51,7 @@ DESCRIPTION
d, s, c current config("mode")
f real (decimal, floating point)
e exponential
g real or exponential depending on config("display")
g general format (real or exponential)
r fractional
o octal
x hexadecimal
@@ -63,15 +63,27 @@ DESCRIPTION
if a positive width w has been specified, the effect is to
produce w spaces, e.g., printf("abc%6dxyz") prints "abc xyz".
Control charters may be given in fmt by escaping them with
the \ character. The following control charter escape
sequences are recognized:
\a audible bell byte 0x07 in ASCII encoding
\b backspace byte 0x08 in ASCII encoding
\f form feed byte 0x0c in ASCII encoding
\n newline byte 0x0b in ASCII encoding
\r return byte 0x0a in ASCII encoding
\t tab byte 0x0d in ASCII encoding
\v vertical tab byte 0x09 in ASCII encoding
If i <= the number of specifiers in fmt, the value of argument
x_i is printed in the format specified by the i-th specifier.
If a positive width w has been specified and normal printing
of x_i does not include a '\n' character, what is printed will
if necessary be padded with spaces so that the length of the
printed output is at least the w. Note that control characters
like '\t', '\b' each count as one character. If the 'right-pad'
flag has been set, the padding is on the right; otherwise it
is on the left.
(e.g., '\a', '\b', '\f', '\n', '\r', '\t', '\n') count as one
character. If the 'right-pad' flag has been set, the padding
is on the right; otherwise it is on the left.
If i > the number of specifiers in fmt, the value of argument x_i
does not contribute to the printing. However, as all arguments
@@ -84,22 +96,38 @@ DESCRIPTION
specified precision will be ignored except for floating-point
mode.
In the case of floating-point (f) format the precision determines
the maximum number of decimal places to be displayed. Other
aspects of this printing may be affected by the configuration
parameters "outround", "tilde", "fullzero", "leadzero".
The (g) general format will print the as real (f) (decimal or
floating point) or as an exponential (e) depending on the
configuration parameter "display".
In the case of floating-point (f) format, and the (g) general
format, the precision determines the maximum number of decimal
places to be displayed. Other aspects of this printing may be
affected by the configuration parameters "outround", "tilde",
"fullzero", "leadzero".
EXAMPLE
; c = config("epsilon", 1e-6); c = config("display", 6);
; c = config("tilde", 1); c = config("outround", 0);
; c = config("fullzero", 0);
; config("epsilon", 1e-6),;
: config("display", 6),;
; config("tilde", 1),;
; config("outround", 0),;
; config("fullzero", 0),;
; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n";
; a = sqrt(3);
; printf(fmt,a,a,a,a,a,a);
1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1.
; c = config("tilde", 0); c = config("outround",24);
; c = config("fullzero", 1);
; config("display", 5),;
: config("tilde", 0),;
; printf("%f\n", pi());
3.1416
; config("display", 10),;
; printf("%f\n", pi());
3.141592654
; config("tilde", 0),;
: config("outround",24),;
; config("fullzero", 1),;
; printf(fmt,a,a,a,a,a,a);
1.732051, 1.732051,1.732051 , 1.7321,1.7321,2.
@@ -117,11 +145,82 @@ EXAMPLE
[2] = "undefined"
[3] = NULL
; c = config("display", 50);
; config("display", 50),;
; printf("%g %g\n%g %g\n", 1e5, 1e49, 1e50, 1e500);
100000 100000000000000000000000000000000000000000000000000
1e50 1e500
; config("display", 10),;
: config("tilde", 0),;
; printf("%f %f %f\n%f %f %f\n",
exp(1), exp(2), exp(3), exp(4), exp(5), exp(6));
2.7182818285 7.3890560989 20.0855369232
54.5981500331 148.4131591026 403.4287934927
; printf("%e %e %e\n%e %e %e\n",
exp(1), exp(2), exp(3), exp(4), exp(5), exp(6));
2.7182818285 7.3890560989 2.0085536923e1
5.4598150033e1 1.4841315910e2 4.0342879349e2
; printf("%g %g %g\n%g %g %g\n",
exp(1), exp(2), exp(3), exp(4), exp(5), exp(6));
2.718281828 7.389056099 20.08553692
54.59815003 148.4131591 403.4287935
; config("display", 10),;
; config("tilde", 0),;
; printf("%f %f %f\n%f %f %f\n",
exp(20), exp(21), exp(22), exp(23), exp(24), exp(25));
485165195.4097902780 1318815734.4832146972 3584912846.1315915617
9744803446.2489026000 26489122129.8434722941 72004899337.3858725242`
; printf("%e %e %e\n%e %e %e\n",
exp(20), exp(21), exp(22), exp(23), exp(24), exp(25));
4.8516519541e8 1.3188157345e9 3.5849128461e9
9.7448034462e9 2.6489122130e10 7.2004899337e10
; printf("%g %g %g\n%g %g %g\n",
exp(20), exp(21), exp(22), exp(23), exp(24), exp(25));
485165195.4 1318815734 3584912846
9744803446 2.648912213e10 7.200489934e10
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; /* NOTE: display has too few digits and epsilon is not small enough */
; display(12),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
; /* NOTE: display has too few digits yet epsilon is small enough */
; display(12),;
; printf("%f\n", pi(1e-72));
~3.141592653590
; epsilon(1e-72),;
; printf("%f\n", pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; display(72),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
/* NOTE: display has enough digits and epsilon is small enough */
; display(72),;
; printf("%f\n", pi(1e-72));
3.141592653589793238462643383279502884197169399375105820974944592307816406
; epsilon(1e-72),;
; printf("%f\n", pi());
3.141592653589793238462643383279502884197169399375105820974944592307816406
LIMITS
The number of arguments of printf() is not to exceed 1024.
@@ -130,7 +229,7 @@ LINK LIBRARY
none
SEE ALSO
fprintf, strprintf, print
config, display, epsilon, fprintf, strprintf
## Copyright (C) 1999-2006,2018 Landon Curt Noll
##

View File

@@ -37,7 +37,7 @@ LIMITS
LINK LIBRARY
void math_divertio();
qprintnum(NUMBER *x, int outmode);
qprintnum(NUMBER *x, int outmode, LEN outdigits);
char *math_getdivertedio();
math_divertio();
@@ -47,7 +47,7 @@ LINK LIBRARY
SEE ALSO
base, base2, config
## Copyright (C) 1999-2006 Landon Curt Noll
## Copyright (C) 1999-2006,2018 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -18,22 +18,68 @@ EXAMPLE
; strprintf("h=%d, i=%d", 2, 3);
"h=2, i=3"
; c = config("epsilon", 1e-6); c = config("display", 6);
; c = config("tilde", 1); c = config("outround", 0);
; c = config("fullzero", 0);
; config("epsilon", 1e-6),;
; config("display", 6),;
; config("tilde", 1),;
; config("outround", 0),;
; config("fullzero", 0),;
; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n";
; a = sqrt(3);
; strprintf(fmt,a,a,a,a,a,a);
"1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1.
"
; c = config("display", 50);
; config("display", 50),;
; fmt2 = "%g %g\n%g %g\n"
; strprintf(fmt2, 1e5, 1e49, 1e50, 1e500);
"100000 100000000000000000000000000000000000000000000000000
1e50 1e500
"
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; config("tab", 0),;
; fmt1 = "%f";
; /* NOTE: display has too few digits and epsilon is not small enough */
; display(12),;
; strprintf(fmt1, pi(1e-10));
"3.1415926536"
; epsilon(1e-10),;
; strprintf(fmt1, pi());
"3.1415926536"
; /* NOTE: display has too few digits yet epsilon is small enough */
; display(12),;
; strprintf(fmt1, pi(1e-72));
"~3.141592653590"
; epsilon(1e-72),;
; strprintf(fmt1, pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; display(72),;
; strprintf(fmt1, pi(1e-10));
"3.1415926536"
; epsilon(1e-10),;
; strprintf(fmt1, pi());
"3.1415926536"
/* NOTE: display has enough digits and epsilon is small enough */
; display(72),;
; strprintf(fmt1, pi(1e-72));
"3.141592653589793238462643383279502884197169399375105820974944592307816406"
; epsilon(1e-72),;
; strprintf(fmt1, pi());
"3.141592653589793238462643383279502884197169399375105820974944592307816406"
LIMITS
The number of arguments of strprintf() is not to exceed 1024.
@@ -41,10 +87,9 @@ LINK LIBRARY
none
SEE ALSO
strcat, strcpy, strerror, strlen, strncmp, strncpy, strpos,
strscan, strscanf, substr,
printf, fprintf, print
config, display, epsilon, fprintf, strcat, strcpy, strerror,
strlen, strncmp, strncpy, strpos, strscan, strscanf, substr,
printf
## Copyright (C) 1999-2006,2018 Landon Curt Noll
##

View File

@@ -92,12 +92,6 @@
# include <stdlib.h>
#endif
#if defined(__linux)
# if !defined(isascii)
E_FUNC int isascii(int c);
# endif /* !isascii */
#endif /* __linux */
char *program; /* our name */
int

36
qio.c
View File

@@ -62,12 +62,13 @@ qprintf(char *fmt, ...)
if (ch == '\\') {
ch = *fmt++;
switch (ch) {
case 'a': ch = '\a'; break;
case 'b': ch = '\b'; break;
case 'f': ch = '\f'; break;
case 'n': ch = '\n'; break;
case 'r': ch = '\r'; break;
case 't': ch = '\t'; break;
case 'f': ch = '\f'; break;
case 'v': ch = '\v'; break;
case 'b': ch = '\b'; break;
case 0:
va_end(ap);
return;
@@ -183,7 +184,7 @@ qprintf(char *fmt, ...)
* Integers are always printed as themselves.
*/
void
qprintnum(NUMBER *q, int outmode)
qprintnum(NUMBER *q, int outmode, LEN outdigits)
{
NUMBER tmpval;
long prec, exp;
@@ -202,13 +203,13 @@ qprintnum(NUMBER *q, int outmode)
case MODE_REAL:
prec = qdecplaces(q);
if ((prec < 0) || (prec > conf->outdigits)) {
if ((prec < 0) || (prec > outdigits)) {
if (conf->tilde_ok)
PUTCHAR('~');
}
if (conf->fullzero || (prec < 0) ||
(prec > conf->outdigits))
prec = conf->outdigits;
(prec > outdigits))
prec = outdigits;
qprintff(q, 0L, prec);
break;
@@ -225,7 +226,7 @@ qprintnum(NUMBER *q, int outmode)
tmpval.num.sign = 0;
exp = qilog10(&tmpval);
if (exp == 0) { /* in range to output as real */
qprintnum(q, MODE_REAL);
qprintnum(q, MODE_REAL, outdigits);
return;
}
tmpval.num = _one_;
@@ -237,35 +238,22 @@ qprintnum(NUMBER *q, int outmode)
q = qmul(q, &tmpval);
zfree(tmpval.num);
zfree(tmpval.den);
qprintnum(q, MODE_REAL);
qprintnum(q, MODE_REAL, outdigits);
qfree(q);
PRINTF1("e%ld", exp);
break;
case MODE_REAL_AUTO:
{
/*
* XXX - re-write to not modify conf->outdigits
*
* Modifying the configuration value could be dangerious
* when a calculation is aborted within an opcode.
* Better to use qprintfg() use inline code that
* does not depend on changing conf->outdigits.
*/
const int P = conf->outdigits ? conf->outdigits : 1;
long olddigits;
tmpval = *q;
tmpval.num.sign = 0;
exp = qilog10(&tmpval);
olddigits = conf->outdigits;
if (P > exp && exp >= -P) {
conf->outdigits = P - 1 - exp;
qprintnum(q, MODE_REAL);
qprintnum(q, MODE_REAL, P - 1 - exp);
} else {
conf->outdigits = P - 1;
qprintnum(q, MODE_EXP);
qprintnum(q, MODE_EXP, P - 1);
}
conf->outdigits = olddigits;
break;
}
@@ -288,7 +276,7 @@ qprintnum(NUMBER *q, int outmode)
if (outmode2 != MODE2_OFF) {
PUTSTR(" /* ");
qprintnum(q, outmode2);
qprintnum(q, outmode2, outdigits);
PUTSTR(" */");
}
}

View File

@@ -67,7 +67,7 @@ E_FUNC FULL qtou(NUMBER *q);
E_FUNC SFULL qtos(NUMBER *q);
E_FUNC long qparse(char *str, int flags);
E_FUNC void qfreenum(NUMBER *q);
E_FUNC void qprintnum(NUMBER *q, int mode);
E_FUNC void qprintnum(NUMBER *q, int mode, LEN outdigits);
E_FUNC void qprintff(NUMBER *q, long width, long precision);
E_FUNC void qprintfe(NUMBER *q, long width, long precision);
E_FUNC void qprintfr(NUMBER *q, long width, BOOL force);

2
qmod.c
View File

@@ -404,7 +404,7 @@ showredcdata(void)
for (i = 0, rcp = redc_cache; i < MAXREDC; i++, rcp++) {
if (rcp->age > 0) {
printf("%-8ld%-8ld", i, rcp->age);
qprintnum(rcp->rnum, 0);
qprintnum(rcp->rnum, 0, conf->outdigits);
printf("\n");
}
}

19
str.c
View File

@@ -1380,17 +1380,17 @@ printechar(char *c)
math_chr('\\');
ech = 0;
switch (ch) {
case '\a': ech = 'a'; break;
case '\b': ech = 'b'; break;
case '\f': ech = 'f'; break;
case '\n': ech = 'n'; break;
case '\r': ech = 'r'; break;
case '\t': ech = 't'; break;
case '\b': ech = 'b'; break;
case '\f': ech = 'f'; break;
case '\v': ech = 'v'; break;
case '\\': ech = '\\'; break;
case '\"': ech = '\"'; break;
case '\'': ech = '\''; break;
case 0: ech = '0'; break;
case 7: ech = 'a'; break;
case 27: ech = 'e'; break;
}
if (ech == '0') {
@@ -1438,8 +1438,17 @@ fitstring(char *str, long len, long width)
continue;
n++;
switch (ch) {
case '\n': case '\r': case '\t': case '\b': case '\f':
case '\v': case '\\': case '\"': case 7: case 27:
case '\a':
case '\b':
case '\f':
case '\n':
case '\r':
case '\t':
case '\v':
case '\\':
case '\"':
case '\'':
case 27:
continue;
}
if (ch >= 64 || (nch >= '0' && nch <= '7')) {

View File

@@ -183,10 +183,12 @@ gettoken(void)
}
switch (ch) {
case ' ':
case '\t':
case '\r':
case '\v':
case '\a':
case '\b':
case '\f':
case '\r':
case '\t':
case '\v':
case '\0':
break;
case '\n':

View File

@@ -2774,7 +2774,7 @@ printvalue(VALUE *vp, int flags)
}
switch (type) {
case V_NUM:
qprintnum(vp->v_num, MODE_DEFAULT);
qprintnum(vp->v_num, MODE_DEFAULT, conf->outdigits);
if (conf->traceflags & TRACE_LINKS)
math_fmt("#%ld", vp->v_num->links);
break;
@@ -2835,7 +2835,7 @@ printvalue(VALUE *vp, int flags)
if (userfunc("octet_print", vp))
break;
qtemp = itoq((long) *vp->v_octet);
qprintnum(qtemp, MODE_DEFAULT);
qprintnum(qtemp, MODE_DEFAULT, conf->outdigits);
qfree(qtemp);
break;
case V_OPTR:
@@ -2888,7 +2888,7 @@ printestr(VALUE *vp)
math_chr('"');
return;
case V_NUM:
qprintnum(vp->v_num, MODE_FRAC);
qprintnum(vp->v_num, MODE_FRAC, conf->outdigits);
return;
case V_COM:
mode = math_setmode(MODE_FRAC);

View File

@@ -44,8 +44,8 @@ static char *program;
#define MAJOR_VER 2 /* major library version */
#define MINOR_VER 12 /* minor library version */
#define MAJOR_PATCH 6 /* major software level under library version */
#define MINOR_PATCH 9 /* minor software level or 0 if not patched */
#define MAJOR_PATCH 7 /* major software level under library version */
#define MINOR_PATCH 0 /* minor software level or 0 if not patched */
/*