Misc.
This commit is contained in:
parent
e94704a2fe
commit
cdbbefbc8a
8 changed files with 113 additions and 185 deletions
2
Makefile
2
Makefile
|
@ -40,7 +40,7 @@ sinh.o cosh.o tanh.o arcsinh.o arccosh.o arctanh.o \
|
|||
abs.o mod.o roots.o eigen.o simplify.o for.o isprime.o index.o wedge.o \
|
||||
rationalize.o prog.o lcm.o floor.o ceiling.o condense.o userfunc.o find.o \
|
||||
init.o primetab.o bignum.o symbol.o run.o atomize.o pollard.o outer.o inner.o \
|
||||
is.o clear.o expcos.o expsin.o coeff.o \
|
||||
is.o clear.o expcos.o expsin.o coeff.o log.o \
|
||||
main.o \
|
||||
misc.o \
|
||||
data.o \
|
||||
|
|
2
defs.h
2
defs.h
|
@ -188,7 +188,7 @@ extern void addk(int);
|
|||
extern void multiply_all(int);
|
||||
extern void divide(void);
|
||||
extern void multiply(void);
|
||||
extern void slog(void);
|
||||
extern void logarithm(void);
|
||||
extern void add(void);
|
||||
extern int lessp(U *, U *);
|
||||
extern void list(int);
|
||||
|
|
|
@ -233,7 +233,7 @@ dpower(void)
|
|||
multiply();
|
||||
|
||||
push(cadr(p1)); // log u
|
||||
slog();
|
||||
logarithm();
|
||||
|
||||
push(caddr(p1)); // dv/dx
|
||||
push(p2);
|
||||
|
|
9
eval.cpp
9
eval.cpp
|
@ -30,6 +30,7 @@ extern void eval_filter(void);
|
|||
extern void eval_floor(void);
|
||||
extern void eval_inner(void);
|
||||
extern void eval_isprime(void);
|
||||
extern void eval_log(void);
|
||||
extern void eval_mod(void);
|
||||
extern void eval_outer(void);
|
||||
extern void eval_product(void);
|
||||
|
@ -550,14 +551,6 @@ eval_legendre(void)
|
|||
legendre();
|
||||
}
|
||||
|
||||
static void
|
||||
eval_log(void)
|
||||
{
|
||||
push(cadr(p1));
|
||||
eval();
|
||||
slog();
|
||||
}
|
||||
|
||||
static void
|
||||
eval_multiply(void)
|
||||
{
|
||||
|
|
107
log.cpp
Normal file
107
log.cpp
Normal file
|
@ -0,0 +1,107 @@
|
|||
// Do the logarithm function.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "defs.h"
|
||||
|
||||
static void logf(void);
|
||||
|
||||
void
|
||||
eval_log(void)
|
||||
{
|
||||
push(cadr(p1));
|
||||
eval();
|
||||
logarithm();
|
||||
}
|
||||
|
||||
void
|
||||
logarithm(void)
|
||||
{
|
||||
save();
|
||||
logf();
|
||||
restore();
|
||||
}
|
||||
|
||||
static void
|
||||
logf(void)
|
||||
{
|
||||
double d;
|
||||
|
||||
p1 = pop();
|
||||
|
||||
if (p1->k == DOUBLE) {
|
||||
d = p1->u.d;
|
||||
if (d < 0.0) {
|
||||
d = log(-d);
|
||||
push_double(d);
|
||||
push(imaginaryunit);
|
||||
push_symbol(PI);
|
||||
multiply();
|
||||
add();
|
||||
} else {
|
||||
d = log(d);
|
||||
push_double(d);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (equal(p1, one)) {
|
||||
push_integer(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p1 == symbol(E)) {
|
||||
push(one);
|
||||
return;
|
||||
}
|
||||
|
||||
if (car(p1) == symbol(POWER)) {
|
||||
push(caddr(p1));
|
||||
push(cadr(p1));
|
||||
logarithm();
|
||||
multiply();
|
||||
return;
|
||||
}
|
||||
|
||||
push_symbol(LOG);
|
||||
push(p1);
|
||||
list(2);
|
||||
}
|
||||
|
||||
static char *s[] = {
|
||||
|
||||
"log(1)",
|
||||
"0",
|
||||
|
||||
"log(exp(1))",
|
||||
"1",
|
||||
|
||||
"log(exp(x))",
|
||||
"x",
|
||||
|
||||
"exp(log(x))",
|
||||
"x",
|
||||
|
||||
"log(x^2)",
|
||||
"2*log(x)",
|
||||
|
||||
"log(1/x)",
|
||||
"-log(x)",
|
||||
|
||||
"log(a^b)",
|
||||
"b*log(a)",
|
||||
|
||||
"log(2)",
|
||||
"log(2)",
|
||||
|
||||
"log(2.0)",
|
||||
"0.693147",
|
||||
|
||||
"float(log(2))",
|
||||
"0.693147",
|
||||
};
|
||||
|
||||
void
|
||||
test_log(void)
|
||||
{
|
||||
test(__FILE__, s, sizeof s / sizeof (char *));
|
||||
}
|
62
misc.cpp
62
misc.cpp
|
@ -7,15 +7,6 @@ extern void define_variable(char *, int);
|
|||
U *varlist;
|
||||
int symbol_level;
|
||||
|
||||
int
|
||||
is_blank(char *s)
|
||||
{
|
||||
while (*s)
|
||||
if (!isspace(*s++))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
list(int n)
|
||||
{
|
||||
|
@ -317,59 +308,6 @@ ssqrt(void)
|
|||
power();
|
||||
}
|
||||
|
||||
void
|
||||
slog(void)
|
||||
{
|
||||
double d;
|
||||
|
||||
save();
|
||||
|
||||
p1 = pop();
|
||||
|
||||
if (p1->k == DOUBLE) {
|
||||
d = p1->u.d;
|
||||
if (d < 0.0) {
|
||||
d = log(-d);
|
||||
push_double(d);
|
||||
push(imaginaryunit);
|
||||
push_symbol(PI);
|
||||
multiply();
|
||||
add();
|
||||
} else {
|
||||
d = log(d);
|
||||
push_double(d);
|
||||
}
|
||||
restore();
|
||||
return;
|
||||
}
|
||||
|
||||
if (equal(p1, one)) {
|
||||
push_integer(0);
|
||||
restore();
|
||||
return;
|
||||
}
|
||||
|
||||
if (p1 == symbol(E)) {
|
||||
push(one);
|
||||
restore();
|
||||
return;
|
||||
}
|
||||
|
||||
if (car(p1) == symbol(POWER)) {
|
||||
push(caddr(p1));
|
||||
push(cadr(p1));
|
||||
slog();
|
||||
multiply();
|
||||
restore();
|
||||
return;
|
||||
}
|
||||
|
||||
push_symbol(LOG);
|
||||
push(p1);
|
||||
list(2);
|
||||
restore();
|
||||
}
|
||||
|
||||
void
|
||||
conjugate(void)
|
||||
{
|
||||
|
|
|
@ -30,6 +30,7 @@ extern void test_inner(void);
|
|||
extern void test_integral(void);
|
||||
extern void test_isprime(void);
|
||||
extern void test_lcm(void);
|
||||
extern void test_log(void);
|
||||
extern void test_madd(void);
|
||||
extern void test_mdiv(void);
|
||||
extern void test_mgcd(void);
|
||||
|
@ -118,6 +119,7 @@ selftest(void)
|
|||
test_for();
|
||||
test_inner();
|
||||
test_lcm();
|
||||
test_log();
|
||||
test_mod();
|
||||
test_outer();
|
||||
test_product();
|
||||
|
|
112
test.cpp
112
test.cpp
|
@ -324,42 +324,6 @@ char *script[] = {
|
|||
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// log
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
"log(1)",
|
||||
"0",
|
||||
|
||||
"log(exp(1))",
|
||||
"1",
|
||||
|
||||
"log(exp(x))",
|
||||
"x",
|
||||
|
||||
"exp(log(x))",
|
||||
"x",
|
||||
|
||||
"log(x^2)",
|
||||
"2*log(x)",
|
||||
|
||||
"log(1/x)",
|
||||
"-log(x)",
|
||||
|
||||
"log(a^b)",
|
||||
"b*log(a)",
|
||||
|
||||
"log(2)",
|
||||
"log(2)",
|
||||
|
||||
"log(2.0)",
|
||||
"0.693147",
|
||||
|
||||
"float(log(2))",
|
||||
"0.693147",
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// arctan
|
||||
|
@ -676,82 +640,6 @@ char *script[] = {
|
|||
"B=quote(B)",
|
||||
"B",
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// derivative
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if 0 // now in derivative.c
|
||||
|
||||
"x=quote(x)",
|
||||
"",
|
||||
|
||||
"f=quote(f)",
|
||||
"",
|
||||
|
||||
"g=quote(g)",
|
||||
"",
|
||||
|
||||
"d(a,x)",
|
||||
"0",
|
||||
|
||||
"d(x,x)",
|
||||
"1",
|
||||
|
||||
"d(x^2,x)",
|
||||
"2*x",
|
||||
|
||||
"d(log(x),x)",
|
||||
"1/x",
|
||||
|
||||
"d(exp(x),x)",
|
||||
"exp(x)",
|
||||
|
||||
"d(a^x,x)",
|
||||
"a^x*log(a)",
|
||||
|
||||
"d(x^x,x)-(x^x+x^x*log(x))",
|
||||
"0",
|
||||
|
||||
"d(log(x^2+5),x)",
|
||||
"2*x/(5+x^2)",
|
||||
|
||||
"d(d(f(x),x),y)",
|
||||
"0",
|
||||
|
||||
"d(d(f(x),y),x)",
|
||||
"0",
|
||||
|
||||
"d(d(f(y),x),y)",
|
||||
"0",
|
||||
|
||||
"d(d(f(y),y),x)",
|
||||
"0",
|
||||
|
||||
"d((x*y*z,y,x+z),(x,y,z))",
|
||||
"((y*z,x*z,x*y),(0,1,0),(1,0,1))",
|
||||
|
||||
"d(x+z,(x,y,z))",
|
||||
"(1,0,1)",
|
||||
|
||||
"d(cos(theta)^2,cos(theta))",
|
||||
"2*cos(theta)",
|
||||
|
||||
"d(f())",
|
||||
"d(f(),x)",
|
||||
|
||||
"d(x^2)",
|
||||
"2*x",
|
||||
|
||||
"d(t^2)",
|
||||
"2*t",
|
||||
|
||||
"d(t^2 x^2)",
|
||||
"2*t^2*x",
|
||||
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// integral
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue