Math

Math is a command-line calculator, similar to bc. It also includes a lot of extra functionality for hashing files and manipulating strings.

Click here to download the zip file containing binaries for the following platforms:

Example 1: Basic math

> x = 2
ans = 2
> x+1
ans = 3
> ans*5
ans = 15
> sqrt(4^2)
ans = 4

Example 2: Converting to and from hex

> hex 1234
4d2
> unhex 4d2
1234

Example 3: Hashing a file

> md5 empty.txt
d41d8cd98f00b204e9800998ecf8427e
> sha1 empty.txt
da39a3ee5e6b4b0d3255bfef95601890afd80709
> sha256 empty.txt
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

Example 4: Converting Unix time

> time
ans = 1515480324
> gmtime
2018-01-09 06:45:29 AM Tue
> localtime
2018-01-09 01:45:32 AM Tue
> gmtime 0
1970-01-01 00:00:00 AM Thu

Example 5: Encoding and decoding common formats

> base64 hello
aGVsbG8=
> unbase64 aGVsbG8=
hello
> url_encode { asdf: 1234 }
%7B%20asdf:%201234%20%7D
> url_decode %7B%20asdf:%201234%20%7D
{ asdf: 1234 }

Example 6: Miscellaneous

> comma 1234567890
1,234,567,890
> uuid
f27f4c4b-c3f4-7dfb-4205-206383c0685d

Usage

COMMANDS: these must be typed exactly with no leading or trailing characters

	help       - shows this message
	debug on   - turns debug on
	debug off  - turns debug off
	exit       - exits the program
	quit       - exits the program
	clear      - clears the screen
	reset      - reset all variables
	*.frm      - run a formula file
	formula    - view help text about formula files
	hex [n]    - convert n to hex
	unhex [n]  - convert n to decimal
	md5|sha1|sha256 [file] - compute the hex digest for a file
	escape [file] - C-string escape a file
	base64|unbase64 [file|string] - base64 encode/decode a file or string
	url_encode|url_decode [file|string] -url encode/decode a file or string
	comma [n]  - add commas to a number
	time       - get seconds since unix epoch
	localtime [t] -format time to local time string
	gmtime [t] -format time to UTC time string
	uuid       - generate a UUID
	bench      - run a simple benchmark

FUNCTIONS: these all take a single parameter

	abs()	acos()	asin()
	atan()	cos()	exp()
	ln()	log()	sin()
	sqrt()	tan()

OPERATORS: in order of precedence

	!
	^
	* / %
	+ -
	=

The factorial operator (!) takes two operands and a!b is equivalent to a!/b! in traditional notation.
Also, the variables 'pi', 'e', and 'ans' are pre-defined.
The variable 'ans' always corresponds to the last answer.

Formula Files

Formula files are files with the extension ".frm" and are in the same directory
in which you are running math. They generally consist of several lines of 
mathematical expressions, except they can contain several special lines, based
on what the line begins with:

    #                 - Comments. The line is ignored.

    prompt [variable] - The evaluation of the formula stops to receive
                        a number from standard input, which is then
                        stored in [variable].

    show [variable]   - Prints a line like "[variable] = [value]".

    print [text]      - Prints [text]. Variables may be included within
                        [text] by escaping them with the an ampersand ('&').
                        For example:

                            print x = &x 

                        is equivalent to: 

                            show x 

Formula files can be run by simply specifying the filename.
For example:

    pythagoras.frm

will look for a file called pythagoras.frm in the same directory, and run it.

Formula files can also take arguments which bind to "prompt" statements
within the file itself. This allows you to run a formula and fill in the
prompts in a concise way.
For example, assuming that "pythagoras.frm" looks like:

    prompt a
    prompt b
    c = sqrt(a^2+b^2)
    show c

Running this:

    pythagoras.frm 1 2

will allow you to skip the prompts and assign 1 to a and 2 to b.
Any missing arguments are still prompted. Any extra arguments are ignored.

How is this better than bc?

I'm not too familiar with bc, but in general this has more features: it has commands to convert timestamps, hash files, etc.

How is this better than the NodeJS/Python REPL?

In general it's less typing to do basic things.

Does this support bignum/bigints?

No. All numbers are double-precision floating points (64 bits).