# desk calculator

desk calculator, aka desk calculator, is a programming language created in 1978. dc (desk calculator) is a cross-platform reverse-polish calculator which supports arbitrary-precision arithmetic. It is one of the oldest Unix utilities, predating even the invention of the C programming language. Like other utilities of that vintage, it has a powerful set of features but terse syntax. Read more on Wikipedia...

42Years Old | 20Users | ?Jobs |

- desk calculator ranks in the top 25% of languages
- the desk calculator wikipedia page
- desk calculator first appeared in 1978
- tryitonline has an online desk calculator repl
- See also: reverse-polish-notation, unix, c
- Have a question about desk calculator not answered here? Email me and let me know how I can help.

### Example code from Wikipedia:

#!/usr/bin/perl my ($g,$e,$m) = map { "\U$_" } @ARGV; die "$0 gen exp mod\n" unless $m; print `echo $g $e $m | dc -e ' # Hex input and output 16dio # Read m, e and g from stdin on one line ?SmSeSg # Function z: return g * top of stack [lg*]sz # Function Q: remove the top of the stack and return 1 [sb1q]sQ # Function X(e): recursively compute g^e % m # It is the same as Sm^Lm%, but handles arbitrarily large exponents. # Stack at entry: e # Stack at exit: g^e % m # Since e may be very large, this uses the property that g^e % m == # if( e == 0 ) # return 1 # x = (g^(e/2)) ^ 2 # if( e % 2 == 1 ) # x *= g # return x % [ d 0=Q # return 1 if e==0 (otherwise, stack: e) d 2% Sa # Store e%2 in a (stack: e) 2/ # compute e/2 lXx # call X(e/2) d* # compute X(e/2)^2 La1=z # multiply by g if e%2==1 lm % # compute (g^e) % m ] SX le # Load e from the register lXx # compute g^e % m p # Print the result '`;

Last updated August 9th, 2020