mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.11.5t4
This commit is contained in:
@@ -17,8 +17,8 @@
|
||||
# received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# @(#) $Revision: 29.9 $
|
||||
# @(#) $Id: Makefile,v 29.9 2001/04/08 10:53:52 chongo Exp $
|
||||
# @(#) $Revision: 29.13 $
|
||||
# @(#) $Id: Makefile,v 29.13 2001/05/13 14:43:56 chongo Exp chongo $
|
||||
# @(#) $Source: /usr/local/src/cmd/calc/cscript/RCS/Makefile,v $
|
||||
#
|
||||
# Under source code control: 1999/11/29 11:10:26
|
||||
@@ -39,8 +39,8 @@ MAKE_FILE = Makefile
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
BINDIR= /usr/local/bin
|
||||
#BINDIR= /usr/bin
|
||||
#BINDIR= /usr/local/bin
|
||||
BINDIR= /usr/bin
|
||||
#BINDIR= /usr/contrib/bin
|
||||
#
|
||||
SCRIPTDIR= ${BINDIR}/cscript
|
||||
@@ -59,6 +59,7 @@ CHMOD= chmod
|
||||
SED= sed
|
||||
SORT= sort
|
||||
FMT= fmt
|
||||
CMP= cmp
|
||||
|
||||
# The ${SCRIPT} list is the list of calc shell script files (without the .calc
|
||||
# extension) which will be installed.
|
||||
@@ -76,10 +77,10 @@ FMT= fmt
|
||||
#
|
||||
# make detaillist
|
||||
#
|
||||
SCRIPT= mersenne piforever plus simple square fproduct
|
||||
SCRIPT= mersenne piforever plus simple square fproduct powerterm
|
||||
|
||||
SCRIPT_SRC= mersenne.calc piforever.calc plus.calc simple.calc square.calc \
|
||||
fproduct.calc
|
||||
fproduct.calc powerterm.calc
|
||||
|
||||
# These files are found (but not built) in the distribution
|
||||
#
|
||||
@@ -89,9 +90,17 @@ DISTLIST= ${SCRIPT_SRC} ${MAKE_FILE} README
|
||||
#
|
||||
CALCLIBLIST=
|
||||
|
||||
# complete list of targets
|
||||
#
|
||||
# NOTE: This list MUST be co-ordinated with the ${CSCRIPT_TARGETS} variable
|
||||
# in the upper level ../Makefile
|
||||
#
|
||||
CSCRIPT_TARGETS= ${SCRIPT}
|
||||
TARGETS= ${CSCRIPT_TARGETS}
|
||||
|
||||
# The reason for this Makefile
|
||||
#
|
||||
all: ${SCRIPT} ${SCRIPT_SRC} .all
|
||||
all: ${TARGETS} .all
|
||||
|
||||
# used by the upper level Makefile to determine if we have done all
|
||||
#
|
||||
@@ -185,7 +194,7 @@ depend:
|
||||
${Q}echo "" >> Makefile
|
||||
${Q}${SED} -n '3,$$p' makedep.out >> Makefile
|
||||
-${Q}rm -f makedep.out
|
||||
-${Q}if cmp -s Makefile.bak Makefile; then \
|
||||
-${Q}if ${CMP} -s Makefile.bak Makefile; then \
|
||||
echo 'sample Makefile was already up to date'; \
|
||||
mv -f Makefile.bak Makefile; \
|
||||
else \
|
||||
@@ -200,32 +209,59 @@ depend:
|
||||
fi; \
|
||||
fi
|
||||
|
||||
##
|
||||
#
|
||||
# rpm rules
|
||||
#
|
||||
##
|
||||
|
||||
echo_SCRIPT: ${MAKE_FILE}
|
||||
@echo ${SCRIPT}
|
||||
|
||||
|
||||
echo_install.list: ${MAKE_FILE}
|
||||
@for i in ${SCRIPT}; do \
|
||||
echo ${SCRIPTDIR}/$$i; \
|
||||
done
|
||||
##
|
||||
#
|
||||
# Utility rules
|
||||
#
|
||||
##
|
||||
|
||||
clean:
|
||||
-rm -f makedep.out
|
||||
|
||||
clobber:
|
||||
-rm -f ${SCRIPT}
|
||||
-rm -f ${TARGETS}
|
||||
|
||||
install: all
|
||||
-${Q}if [ ! -d ${BINDIR} ]; then \
|
||||
echo mkdir ${BINDIR}; \
|
||||
mkdir ${BINDIR}; \
|
||||
echo mkdir ${BINDIR}; \
|
||||
mkdir ${BINDIR}; \
|
||||
echo ${CHMOD} 0755 ${BINDIR}; \
|
||||
${CHMOD} 0755 ${BINDIR}; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
-${Q}if [ ! -d ${SCRIPTDIR} ]; then \
|
||||
echo mkdir ${SCRIPTDIR}; \
|
||||
mkdir ${SCRIPTDIR}; \
|
||||
echo mkdir ${SCRIPTDIR}; \
|
||||
mkdir ${SCRIPTDIR}; \
|
||||
echo ${CHMOD} 0755 ${SCRIPTDIR}; \
|
||||
${CHMOD} 0755 ${SCRIPTDIR}; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
${Q}for i in ${SCRIPT}; do \
|
||||
echo rm -f ${SCRIPTDIR}/$$i; \
|
||||
rm -f ${SCRIPTDIR}/$$i; \
|
||||
echo cp $$i ${SCRIPTDIR}; \
|
||||
cp $$i ${SCRIPTDIR}; \
|
||||
echo ${CHMOD} 0555 ${SCRIPTDIR}/$$i; \
|
||||
if ${CMP} -s $$i ${SCRIPTDIR}/$$i; then \
|
||||
true; \
|
||||
else \
|
||||
rm -f ${SCRIPTDIR}/$$i.new; \
|
||||
cp -f $$i ${SCRIPTDIR}/$$i.new; \
|
||||
${CHMOD} 0555 ${SCRIPTDIR}/$$i; \
|
||||
mv -f ${SCRIPTDIR}/$$i.new ${SCRIPTDIR}/$$i; \
|
||||
echo "installed ${SCRIPTDIR}/$$i"; \
|
||||
fi; \
|
||||
done
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
@@ -254,3 +290,7 @@ fproduct: fproduct.calc
|
||||
rm -f $@
|
||||
${SED} -e "1s:^#!/usr/local/src/cmd/calc/calc:#!${BINDIR}/calc:" $?>$@
|
||||
${CHMOD} +x $@
|
||||
powerterm: powerterm.calc
|
||||
rm -f $@
|
||||
${SED} -e "1s:^#!/usr/local/src/cmd/calc/calc:#!${BINDIR}/calc:" $?>$@
|
||||
${CHMOD} +x $@
|
||||
|
@@ -39,6 +39,12 @@ plus arg ...
|
||||
Print the sum of 1 or more arguments.
|
||||
|
||||
|
||||
powerterm [base_limit] value
|
||||
|
||||
Print the value as a sum (or difference) of powers of integers up
|
||||
to and including powers <= base_limit. By default, base_limit is 10000.
|
||||
|
||||
|
||||
simple
|
||||
|
||||
A trivial example of a calc shell script.
|
||||
@@ -59,8 +65,8 @@ simple
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: README,v 29.5 2001/04/08 08:24:40 chongo Exp $
|
||||
## @(#) $Revision: 29.6 $
|
||||
## @(#) $Id: README,v 29.6 2001/04/25 07:26:12 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/cscript/RCS/README,v $
|
||||
##
|
||||
## Under source code control: 1999/12/17 10:23:40
|
||||
|
185
cscript/powerterm.calc
Normal file
185
cscript/powerterm.calc
Normal file
@@ -0,0 +1,185 @@
|
||||
#!/usr/local/bin/calc -q -s -f
|
||||
/*
|
||||
* powerterm - print the argument as a sum of powers of integers
|
||||
*
|
||||
* usage:
|
||||
* powerterm [base_limit] value
|
||||
*
|
||||
* base_limit largest base we will consider (def: 10000)
|
||||
* value value to convert into sums of powers of integers
|
||||
*
|
||||
* Copyright (C) 2001 Landon Curt Noll
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the powerterm of the version 2.1 of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
* Public License for more details.
|
||||
*
|
||||
* A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
* distributed with calc under the filename COPYING-LGPL. You should have
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.5 $
|
||||
* @(#) $Id: powerterm.calc,v 29.5 2001/04/25 08:41:36 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cscript/RCS/powerterm.calc,v $
|
||||
*
|
||||
* Under source code control: 2001/04/24 23:49:11
|
||||
* File existed as early as: 2001
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* parse args
|
||||
*/
|
||||
config("verbose_quit", 0),;
|
||||
base_lim = 10000; /* default: highest base we will consider */
|
||||
if (argv() < 2 || argv() > 3) {
|
||||
fprintf(files(2), "usage: %s [base_limit] value\n", argv(0));
|
||||
exit;
|
||||
}
|
||||
if (argv() == 3) {
|
||||
x = eval(argv(2));
|
||||
base_lim = eval(argv(1));
|
||||
} else {
|
||||
x = eval(argv(1));
|
||||
}
|
||||
if (! isint(x)) {
|
||||
fprintf(files(2), "%s: value must be an integer\n");
|
||||
exit;
|
||||
}
|
||||
if (! isint(base_lim)) {
|
||||
fprintf(files(2), "%s: base limit must be an integer\n");
|
||||
exit;
|
||||
}
|
||||
if (base_lim <= 1) {
|
||||
fprintf(files(2), "%s: base limit is too small\n");
|
||||
exit;
|
||||
}
|
||||
++base_lim;
|
||||
|
||||
/*
|
||||
* setup loop variables
|
||||
*/
|
||||
term = 0; /* number of powerterm found */
|
||||
|
||||
/*
|
||||
* log constants
|
||||
*/
|
||||
if (base_lim <= 2^20+1) { /* 2^20 requires ~96 Megs of memory */
|
||||
mat lni[base_lim]; /* log of integers */
|
||||
for (i=2; i < base_lim; ++i) {
|
||||
lni[i] = ln(i);
|
||||
}
|
||||
have_lni = 1; /* have lni[x] array */
|
||||
} else {
|
||||
mat lni[1]; /* not used */
|
||||
have_lni = 0; /* base_lim too large for array */
|
||||
}
|
||||
|
||||
/*
|
||||
* remove nestest powers
|
||||
*/
|
||||
while (abs(x) >= base_lim) {
|
||||
|
||||
/*
|
||||
* look for the nearest power
|
||||
*/
|
||||
lnx = ln(abs(x)); /* log of the remaining co-factor */
|
||||
closest = 0.5;
|
||||
base = 1;
|
||||
exponent = 0;
|
||||
if (have_lni) {
|
||||
|
||||
/*
|
||||
* use pre-calculated log array when looking for the nearest power
|
||||
*/
|
||||
for (i = 2; i < base_lim; ++i) {
|
||||
|
||||
/*
|
||||
* determine exponent closeness to an integer
|
||||
*/
|
||||
ex = lnx / lni[i];
|
||||
power = int(ex + 0.5);
|
||||
diff = ex - power;
|
||||
|
||||
/*
|
||||
* look for a closer power
|
||||
*/
|
||||
if (abs(diff) < closest) {
|
||||
closest = abs(diff);
|
||||
base = i;
|
||||
exponent = power;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/*
|
||||
* re-calculate logs when looking for the nearest power
|
||||
*/
|
||||
for (i = 2; i < base_lim; ++i) {
|
||||
|
||||
/*
|
||||
* determine exponent closeness to an integer
|
||||
*/
|
||||
ex = lnx / ln(i);
|
||||
power = int(ex + 0.5);
|
||||
diff = ex - power;
|
||||
|
||||
/*
|
||||
* look for a closer power
|
||||
*/
|
||||
if (abs(diff) < closest) {
|
||||
closest = abs(diff);
|
||||
base = i;
|
||||
exponent = power;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* output current term and then subtract it
|
||||
*/
|
||||
if (x != 0) {
|
||||
if (x < 0) {
|
||||
print "-",;
|
||||
} else if (term > 0) {
|
||||
print "+",;
|
||||
}
|
||||
if (exponent > 1) {
|
||||
print base: "^": exponent,;
|
||||
} else {
|
||||
print base,;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* subtract (or add) this near power
|
||||
*/
|
||||
if (x < 0) {
|
||||
x = x + base^exponent;
|
||||
} else {
|
||||
x = x - base^exponent;
|
||||
}
|
||||
++term;
|
||||
}
|
||||
|
||||
/*
|
||||
* print the final term
|
||||
*/
|
||||
if (x < 0) {
|
||||
print "-", -x;
|
||||
} else if (x > 0) {
|
||||
print "+", x;
|
||||
} else {
|
||||
print "";
|
||||
}
|
||||
exit;
|
Reference in New Issue
Block a user