The JavaScript Interpreter
Still Yet Your Handy Calculator

JavaCalc 1.6  ©1996-2000 Ken Kikuchi 



What's New?

Adaption for maths online, January 2000:
  • Powers may now be written using the symbol ^
  • Factorials may be written using the usual exclamation mark !
(Examples: 5^2 is evaluated to give 25, 5! yields 120). For non-integer numbers x, the input x! yields the same as G(x+1), where G is the gamma function (which may also be called by writing gamma(x)).
Remark for programmers: In JavaScript, the logical XOR function is written by the symbol ^, hence it is no longer available here.

Version 1.5, added JavaCalc LITE as a light weight popup window but no Help. Add unlimited Undo and Redo button. You can recall any historical input in the session. A box under the Redo indicates the history page number. findroot now accepts to enter equation balanced by "==".

Version 1.4, added findroot for finding a root of equation in one variable. Try findroot( "x*x-2", 1), findroot( "x-sin(x)", 1)

Version 1.3, updated the help keyword link to JavaScript Reference at Netscape. Now supports more than 500 JavaScript keywords. Try ?FORM, ?sin

Version 1.2, supports extended factorial that means non-integer n, the numerical value of factorial(n) is given by gamma(1 + n). Thus it has now gamma function and handle negative numbers as well.
Try factorial(3.45), factorial(-1.23), factorial(-10).

About JavaCalc

JavaCalc is a simple demonstration of JavaScript (originally called LiveScript by Netscape). You can evaluate your expressions in the above INPUT box.

Since Netscape released version 3.0.1, JavaScript becomes less memory leak. As a result, I am happy to advise you that the JavaCalc can support more JavaScript features and it works as a JavaScript Interpreter. For example, you can test your own functions, loops and other statements on the JavaCalc. Not necessary to write the code in HTML format and open it by Browser. I have been developing and testing the JavaScript code on the JavaCalc because very easy to test on major browsers. JavaCalc may have limitation to use as Interpreter. However, I believe, you can still enjoy its powerful functions, variables and multi-expression capabilities. 

Note 1) Variable and function names are caps sensitive. 
Note 2) Some enhanced script commands are not compatible between Netscape and Internet Explorer.
Note 3) Keyword compatible does not mean runtime compatible. You should test both environment. For example, Netscape try to keep definition through the session but IE does not. Netscape Communicator 4.7 seems more buggy than IE5.0.

One difference is that JavaCalc allows to use mathematics function without typing "Math" method. For example, you can type sin(0.5) as a short-cut instead of Math.sin(0.5).

In addition, actually you don't need to connect to my home page every time. Because, it uses Netscape 2 and later built-in functions. Click here and saves the page through the Netscape menu View/Document Source. When you need the JavaCalc off-line, drop the saved source onto Netscape. You can use it like a JavaScript Interpreter. Return to FRAME mode.

JavaCalc can do more than calculator. Enjoy, Ken

Sample Expressions

Try the following. You may copy&paste.

Won't you see more samples? Send me your wish, I will add in!

Math Properties

  1. E : Euler's constant and the base of natural logarithms, approximately 2.718.
  2. LN10 : The natural logarithm of ten, approximately 2.302.
  3. LN2 : The natural logarithm of two, approximately 0.693.
  4. PI : The ratio of the circumference of a circle to its diameter, approximately 3.1415.
  5. SQRT1_2 : The square root of one-half; equivalently, one over the square root of two, approximately 0.707.
  6. SQRT2: The square root of two, approximately 1.414.

Math Methods

  1. abs : Returns the absolute value of a number.
  2. acos : Returns the arc cosine (in radians) of a number.
  3. asin : Returns the arc sine (in radians) of a number.
  4. atan : Returns the arc tangent (in radians) of a number.
  5. ceil : Returns the least integer greater than or equal to a number.
  6. cos : Returns the cosine of a number.
  7. exp : Returns e to the power of its argument (ex), where x is the argument, and e is Euler's constant, the base of the natural logarithms.
  8. floor : Returns the greatest integer less than or equal to a number.
  9. log : Returns the natural logarithm (base e) of a number.
  10. max : Returns the greater of two numbers.
  11. min : Returns the lesser of two numbers.
  12. POW : Returns base to the exponent power. Apply POW(x,y) instead of x^y.
  13. random : Returns a pseudo-random number between zero and one. This method is available on X-platforms only
  14. round : Returns the value of a number rounded to the nearest integer. If the decimal portion of the argument is .5 or greater, the argument is rounded to the next highest integer. If the decimal portion of the argument is less than .5, the argument is rounded to the next lowest integer.
  15. sin : Returns the sine of a number.
  16. sqrt : Returns the square root of a number.
  17. tan : Returns the tangent of a number.
Bonus. The following functions are unique on JavaCalc.
  1. factorial : Returns the factorial of a number. For example, factorial(3) returns 6.
      for (var i=-25; i<26; i++)
           document.write (i/2+' '+factorial(i/2)+'<br>');
      } /* somehow it did not work on Communicator 4.7 for Mac */
  2. round2 : Returns the number rounded to a specified number of digits. For example, round2(PI,-4) returns 3.1416. 
  3. gamma : Returns Euler's gamma. For example, gamma(4.5) returns 11.6317.
      Gamma(3/2)-sqrt(PI)/2 should be zero but shows machine level error.
  4. loggamma : Returns the natural logarithm (base E) of gamma.
  5. findroot(expression, initial_value) : Returns the root of an equation in one variable. The expression must equal to zero, and the variable must be "x". For example, if you want to solve the following Kepler's equation;
            E - e sin E = M
    under a condition : M = 0.828; e = 0.967
    you enter the following.
    findroot( "x-0.967*sin(x)==0.828", 1 )
    findroot( "x-0.976*sin(x)-0.828", 1)
    It will return approximate 1.7749 as an eccentric anomaly.

See more information about JavaScript at JavaScript Development Central at Netscape.

Changes History

2/29/2000 1.6 Minor enhancement to search keyword by ? as a workaround for Netscape bug.
2/27/2000 1.5 Added JavaCalc LITE as a light weight popup window but no Help. Added unlimited Undo and Redo button.
2/13/2000 1.4 Added findroot function.
2/10/2000 1.3 Updated help keyword link.
2/6/20000 1.2 Added gamma function to extend factorial for negative and non-integer.
2/3/2000 Thanks Franz for his maths online to extend JavaCalc with ^ and ! functionality as well as to give me a hint of expanding factorial by gamma. Also thanks for the colorful frame.
9/15/97 1.1 Added help function (?). Tuning tags to improve display compatibility.
9/10/97 1.0a Eliminate global variables that makes potential conflict with user operations.
9/7/97 1.0 Cosmetic changes, update introduction. Announced interpreter capability.
10/5/96 1.0b6 Removed window.register to prevent error. Thanks Tina again! Added factorial, round2.
4/27/96 1.0b5 Added TARGET="_TOP" to fix frame error.
3/18/96 1.0b4 Hid script contents from old browsers.
2/14/96 1.0b3 Added Frames.
2/12/96 1.0b2 Added table form, buttons, clear.
2/11/96 1.0b1 Created prototype.

Return to MathCollections

Ken Kikuchi
Comment me:
Last updated: 2/29/2000