Scientific Calculator

0

What This Calculator Does

A basic calculator handles the four operations; this one goes further, adding trigonometric functions (regular and inverse), factorials, logarithms, square roots, exponents, and π on top of standard arithmetic, all in a single button-driven expression builder. Rather than solving one fixed type of problem, it lets you build up an arbitrary expression — nested parentheses and all — and evaluates the whole thing at once when you press equals. A RAD/DEG toggle lets both regular and inverse trigonometric functions work in either radians or degrees.

How to Use It

Tap number and operator buttons to build an expression in the display, the same way you'd use a physical scientific calculator. Function buttons like sin, cos, tan, sin⁻¹, cos⁻¹, tan⁻¹, log, ln, and sqrt insert the function name followed by an open parenthesis, ready for you to type the value it applies to; if you tap a function right after a number or a closing parenthesis, the calculator automatically inserts a multiplication sign first, since "5sin(" isn't a valid expression on its own. The x! button appends a factorial directly after whatever's already in the display, since factorial is a suffix rather than a function you open a parenthesis for. C clears everything, ⌫ deletes one step at a time (including undoing a function name in one backspace), and = evaluates the full expression. The RAD/DEG toggle above the display controls how sin, cos, tan, and their inverses (sin⁻¹, cos⁻¹, tan⁻¹) interpret angles — it defaults to RAD, so existing expressions behave exactly as before unless you switch it.

The Formula

Every expression you build is evaluated by math.js's expression engine rather than a hand-rolled parser, so it correctly follows standard order of operations and handles right-associative exponentiation — 2^3^2 evaluates as 2^(3^2) = 2^9 = 512, not (2^3)^2 = 64, matching standard mathematical convention rather than simple left-to-right evaluation.

In RAD mode, trigonometric functions (sin, cos, tan) take their argument directly in radians, so sin(90) does not give you 1 the way it would in degree mode — you'd need sin(pi/2) instead. π is available as its own button rather than requiring you to type out the digits, which is useful for exactly this kind of radian input. In DEG mode, each argument x you type into sin, cos, or tan is converted as (x) × (π/180) before evaluation, so sin(90) correctly returns 1 and cos(180) returns -1, matching what a physical calculator's DEG mode would give you.

Inverse trig functions (sin⁻¹, cos⁻¹, tan⁻¹) work the other direction: their argument is always a plain ratio, never an angle, so it's never converted — only their resultis. In RAD mode the result is left as radians (mathjs's native output); in DEG mode it's converted as result × (180 ÷ π), so sin⁻¹(1) returns 90 in DEG mode and π/2 (≈1.5708) in RAD mode. Factorial (x!) is unaffected by the RAD/DEG toggle entirely, since it involves no angle at all — 5! is 120 regardless of which mode is selected.

A Worked Example

Type 7, +, 5, then = and the calculator returns 12 — straightforward arithmetic to confirm the basics work as expected. For something that actually shows off order of operations, try (2+3)*4: the parentheses force the addition first, giving 5, then the multiplication gives 20, rather than incorrectly computing 2+(3*4)=14. And for the right-associative exponent behavior specifically, 2^3^2 returns 512, since the rightmost exponentiation (3^2 = 9) is evaluated before the base is raised to it (2^9 = 512).

For the DEG toggle specifically: switch to DEG, type sin(30)+cos(60), and press = — the calculator converts each argument to radians internally (30° → 30×π/180, 60° → 60×π/180) before evaluating, giving 0.5 + 0.5 = 1, exactly matching the well-known identity sin(30°) = cos(60°) = 0.5.

For inverse trig: in DEG mode, type sin⁻¹(1) and press = to get 90 — the angle whose sine is 1. Clear and type the same sin⁻¹(1) again after switching to RAD mode, and you'll get 1.5707963267949 instead (π/2), the same angle expressed in radians rather than degrees. For factorial, typing 5, then x!, then = gives 120 (5 × 4 × 3 × 2 × 1), regardless of which angle mode is selected.

FAQ

What functions does the scientific calculator support?
Trig functions (sin, cos, tan) and their inverses (sin⁻¹, cos⁻¹, tan⁻¹), factorial (x!), logarithms (log, ln), square roots, exponents, and π.
Does it support degrees and radians?
Yes. Use the RAD/DEG toggle above the display to switch trigonometric functions between radians (the default) and degrees. This applies to inverse trig too — sin⁻¹(1) returns 90 in DEG mode and π/2 (≈1.5708) in RAD mode.