Menu of Available Commands for the Eval function in the Long Number Calculator
The "Eval" button will apply a javascript "eval" function to the text in the box for variable "X". Output is not automatic for this button: You must use the "prt" function to add to the output results. Here is a list of functions you can use for the "Eval" option available in the real number version of the javascript calculator: (Remember that this is a javascript function, so commands and variable names are case-sensitive. Also, be aware that some functions expect integer input, so unexpected results can occur if you feed those functions with non-integer input.)Function | Meaning |
maxdigits(x) | Change the Max Digits setting to x |
prt(x) | Append x to the output that will appear in the results |
abs(x) | absolute value of x |
neg(x) | -x |
a(x, y) | x + y |
s(x, y) | x - y |
m(x, y) | x * y |
d(x, y) | x / y |
sqr(x) | x * x |
sqrt(x) | Square root of x |
pow(x, y) | x raised to y power |
root(x, y) | yth root of x |
doubleValue(x) | x converted to double |
dblln(x) | Natural Log of x converted to double |
dbllog2(x) | Base 2 Log of x converted to double |
dbllog10(x) | Decimal Log of x converted to double |
gcd(x, y) | Greatest Common Divisor of x and y |
lcm(x, y) | Least Common Multiple of x and y |
flr(x) | x truncated to integer |
exp(x) | Natural Exponential function |
ln(x) | Natural Logarithmic function |
tenpow(x) | 10 raised to the x power |
log10(x) | Base 10 Logarithmic function |
fctrl(x) | x factorial |
comb(x, y) | Combinations x choose y |
perm(x, y) | Permutations x choose y |
gamma(x) | Gamma function |
sin(x) | Trigonometric sine |
cos(x) | Trigonometric cosine |
tan(x) | Trigonometric tangent |
asin(x) | Trigonometric Arcsine |
acos(x) | Trigonometric Arccosine |
atan(x) | Trigonometric Arctangent |
sinh(x) | Hyperbolic sine |
cosh(x) | Hyperbolic cosine |
tanh(x) | Hyperbolic tangent |
asinh(x) | Inverse hyperbolic sine |
acosh(x) | Inverse hyperbolic cosine |
atanh(x) | Inverse hyperbolic tangent |
am(x, y) | Arithmetic mean of x and y |
gm(x, y) | Geometric mean of x and y |
hm(x, y) | Harmonic mean of x and y |
agm(x, y) | Arithmetic-Geometric mean of x and y |
ghm(x, y) | Geometric-Harmonic mean of x and y |
ahm(x, y) | Arithmetic-Harmonic mean of x and y |
compareLog2To(x, y) | -1 or 1 as Base 2 Log of x is less than or greater than y (y is a double) |
compareTo(x, y) | -1, 0, or 1 as x is less than, equal to, or greater than y |
isprime(x) | 1 if x is prime, else 0 |
nextprime(x) | next prime after x |
prevprime(x) | previous prime to x |
pi() | Constant Pi |
em() | Constant Euler-Mascheroni |
ln2() | Constant natural log(2) |
ln10() | Constant natural log(10) |
zeta(x) | Zeta Function of x |
bernoulli(x, y) | Bernoulli Function at x & y |
euler(x, y) | Euler Polynomial at x & y |
bsl1(x, y) | Bessel Function of the first type at x & y |
Some Examples for the use of the Eval function
Good example #1: Add the square roots of all integers between 1 and 100: Paste this text in the box for X, enter 100 for MaxDigits, and press the "Eval" button:var result = 0;
for(var i = 1; i <= 100; i++){ result = a(result,sqrt(i)); }
prt("The total of the square roots is:\n");
prt(result);
Good example #2: List all the primes between 5,000,000,000,000 and 5,000,000,001,000: Paste this text in the box for X, enter 100 for MaxDigits, and press the "Eval" button:
var t = 0;
var i = "5000000000000";
while(compareTo(i,"5000000001000") <= 0){
if(isprime(i) == 1){ prt(i); prt("\n"); t++; }
i = a(i,1);
}
prt("There are ");
prt(t);
prt(" primes between 5,000,000,000,000 and 5,000,000,001,000\n");
Good example #3: Find the value of Zeta(100) to 100 digits using a brute force method: (1/(1^100) + 1/(2^100) + 1/(3^100) + 1/(4^100) + ... ) (first calculate to 150 digits, then truncate) Paste this text in the box for X, enter 150 for MaxDigits, and press the "Eval" button:
var result = 0;
var lastresult = -1;
var i = 1;
var cutoff = dbllog2(tenpow(-150));
while(compareLog2To(s(result,lastresult),cutoff) > 0){
lastresult = a(result,0);
result = a(result,d(1,pow(i,100)));
i++;
}
//find the magnitude of result - number of digits to left of "."
var mag = Math.floor(dblln(result) / Math.log(10)) + 1;
var res = d(floor(m(result,tenpow(100 - mag))),tenpow(100 - mag));
prt("Untruncated results: \n");
prt(result);
prt("\nTruncated results:\n");
prt(res);
prt("\nNumber of terms:\n");
prt(i - 1);
Bad example #1: Add the total of i + square(i) for all of the integers between 100000000000000000 and 100000000000000100: Paste this text in the box for X, enter 20000 for MaxDigits, and press the "Eval" button:
var result = 0;
var j;
for(var i = 100000000000000000; i <= 100000000000000100; i++){ j = sqr(i) + i; result = a(result,j); }
prt("The total is:\n");
prt(result);
This doesn't work for several reasons: 1) you cannot use "+" to add a "LongNumber" and an integer -- "sqr(i) + i" cannot be evaluated. Change that expression to "a(sqr(i),i)". and
2) The number 100000000000000000 is too long to be a "double", which is pure javascript's only number type. Enclose the two big numbers in quotes.
3) There still remains the problem of the "for" loop parameters. "i" is now a "LongNumber" and cannot be incremented by using "i++".
And also, i <= "100000000000000100" cannot be evaluated.
One solution is to do the following:
var result = 0;
var j;
for(var i = "100000000000000000"; compareTo(i,"100000000000000100") <= 0; i = a(i,1)){
j = a(sqr(i),i);
result = a(result,j); }
prt("The total is:\n");
prt(result);
Keep in mind that the outputs from all of the functions listed above are "LongNumbers", except for the comparator functions and the functions specifically labeled as having "double" output values.