BigInteger Calculator


Calc is an interactive reverse Polish calculator using Java's BigInteger class. It can be run either as an applet or as a standalone Java application.

applet - run the applet version of the calculator - JNLP

documentation - calculator commands

calc.zip - download everything, including the source code

Source code: Calc.java, Element.java, CalcApplet.java, B64Decoder.java, B64Encoder.java, B256Decoder.java, B256Encoder.java, Makefile

RSA example: RSA.calc, Calc.out

To run the standalone version: java -jar Calc.jar


The calculator commands are: clear, Clear, clean, Clean, dup, pop, size, swap, save, milk, factorial, font, tic, toc, Euclid, cubeRoot, sqrt, +, -, *, /, ++, --, %, **, ^, &, |, ~, <<, >>, =, ==, !=, <, <=, >, >=, who, ;, !!, !<num>, history, repeat ... until, if ... [else ...] end, while ... end, run, echo, #, exit, quit, rand, prime, BigInteger, ECadd, ECmul, ECmul2, IDEAadd, IDEAaddInverse, IDEAmul, IDEAmulInverse; plus all of the methods from the BigInteger class by name: abs, add, and, andNot, bitCount, bitLength, byteValue, byteValueExact, clearBit, compareTo, divide, divideAndRemainder, doubleValue, equals, flipBit, floatValue, gcd, getLowestSetBit, hashCode, intValue, intValueExact, isProbablePrime, longValue, longValueExact, max, min, mod, modInverse, modPow, multiply, negate, nextProbablePrime, not, or, pow, probablePrime, remainder, setBit, shiftLeft, shiftRight, shortValue, shortValueExact, signum, subtract, testBit, toByteArray, toString, valueOf, xor.

Notes

probablePrime uses an implicit certainty value of 100 so, for example, 1024 probablePrime is the same as 1024 100 prime

toString and BigInteger support bases 2 to 36, 64, and 256 (ASCII, with C escape sequences, blank = \_).

Sample run

0> 1 2 3
---
		1
		2
		3
1> = a = b
---
		1
2> who
---
	a	3
	b	2
---
		1
3> a b +
---
		1
		5
4> clear a 3 equals if b 4 equals if 7 else 8 end else 9 end
---
		8
5> clear 10 factorial
---
		3628800
6> clear 1 = f 1 = a repeat a 1 add = a f a * = f a 10 == until f
---
	f	3628800
7> clear 10 = a 0 = s a while a s + = s a -- end a s
---
	a	0
	s	55
8> clear 1 2 3 4 5 6 7 8 9 10
---
		1
		2
		3
		4
		5
		6
		7
		8
		9
		10
9> repeat + size 2 < until
---
		55
10> history
---
0	1 2 3
1	= a = b
2	who
3	a b +
4	clear a 3 equals if b 4 equals if 7 else 8 end else 9 end
5	clear 10 factorial
6	clear 1 = f 1 = a repeat a 1 add = a f a * = f a 10 == until f
7	clear 10 = a 0 = s a while a s + = s a -- end a s
8	clear 1 2 3 4 5 6 7 8 9 10
9	repeat + size 2 < until
10	history
---
		55
> !5
11> clear 10 factorial
---
		3628800
12> 16 toString
toString = 375f00
---
		3628800
13> 16 BigInteger 375f00
---
		3628800
		3628800
14> pop 64 toString
toString = N18A

---
		3628800
15> 64 BigInteger N18A
---
		3628800
		3628800
16> clear 256 BigInteger If\_you\_stand\_on\_your\_head,\_you\_will\_get\_footprints\_in\_your\_hair.
---
		3844214047602880274116792097371961830022437782477107213730468712757681843837922767463199738603549492858290160763032479651851604910636269895102065197806126
17> 16 toString 256 toString
toString = 496620796f75207374616e64206f6e20796f757220686561642c20796f752077696c6c2067657420666f6f747072696e747320696e20796f757220686169722e
toString = If\_you\_stand\_on\_your\_head,\_you\_will\_get\_footprints\_in\_your\_hair.
---
		3844214047602880274116792097371961830022437782477107213730468712757681843837922767463199738603549492858290160763032479651851604910636269895102065197806126