cosmopolitan/tool/build/calculator.ctest
Justine Tunney 4918121810 Add new calculator app
Cosmopolitan makes it easy to build and maintain programming languages,
since it abstracts system call #ifdef toil, so you can focus on vision.
Here's an example of a language that isn't turing complete, weighing in
at <1,000 lines of modern C, intended to help with testing libc / libm:

    .1 .2 + .3 - abs epsilon < assert
    pi sqrt pi sqrt * pi - abs epsilon < assert
    -.5 rint dup 0 = assert signbit assert
    -.5 nearbyint dup 0 = assert signbit assert
    -.5 ceil dup 0 = assert signbit assert
    -.5 trunc dup 0 = assert signbit assert
    -.5 round -1 = assert
    -.5 floor -1 = assert
    0 signbit ! assert

CALCULATOR.COM pays homage to CALC.EXE recently removed from Windows 10.
Microsoft should bundle this app instead. It too is roughly 100kb, works
just fine w/ command prompt, and portable since it runs on Mac/Linux/BSD
too while bundling even more features than the calculator on Google.com.

It should be possible to run CALCULATOR.COM on Android and iOS too, just
in case anyone needs a backend pipe driven framework, for graphical user
interfaces of calculators. Sadly we haven't tried it since we don't know
how to run software on telephones so the system call support is a priori
2020-06-30 19:58:08 -07:00

83 lines
2 KiB
Text
Executable file

# INTEGER
2 3 + 5 = assert
3 2 + 5 = assert
5 2 - 3 = assert
2 5 - -3 = assert
81 3 / 27 = assert
81 3 // 27 = assert
2 8 ** 256 = assert
17 10 % 7 = assert
17 10 mod 7 = assert
# FLOATING POINT
.1 .2 + .3 - abs epsilon < assert
pi sqrt pi sqrt * pi - abs epsilon < assert
3 2 / 1.5 = assert
pi pi = assert
pi cos -1 = assert
pi 2 / sin 1 = assert
81 3 / 27 = assert
inf isinf assert
inf isnormal ! assert
nan isnormal ! assert
1 0 / isnormal ! assert
0 signbit ! assert
-.5 round -1 = assert
-.5 floor -1 = assert
-.5 rint dup 0 = assert signbit assert
-.5 nearbyint dup 0 = assert signbit assert
-.5 ceil dup 0 = assert signbit assert
-.5 trunc dup 0 = assert signbit assert
0 0 / dup isnan assert signbit assert # is this right?
1 0 / dup isinf assert signbit ! assert # is this right?
nan nan != assert # is this right?
-nan -nan != assert # is this right?
inf inf = assert # is this right?
-inf -inf = assert # is this right?
# BIT ARITHMETIC
-1 ~ 0 = assert
0xffffffffffffffffffffffffffffffff ~ 0 = assert
0b1010101 popcnt 4 = assert
0b1010101 0b0110101 ^ 0b1100000 = assert
0b1010101 0b0110101 | 0b1110101 = assert
0b1010101 0b0110101 & 0b0010101 = assert
0b1010101 1 >> 0b000101010 = assert
0b1010101 2 >> 0b000010101 = assert
0b1010101 1 << 0b010101010 = assert
0b1010101 2 << 0b101010100 = assert
# BOOLEAN
true assert
false ! assert
true ! ! assert
true true && assert
true false && ! assert
false true && ! assert
true false && ! assert
false true && ! assert
true true || assert
false true || assert
true false || assert
false false || ! assert
4 5 < assert
5 4 < ! assert
-5 4 < assert
5 5 < ! assert
5 5 <= assert
5 4 > assert
4 5 > ! assert
4 -5 > assert
5 5 > ! assert
5 5 >= assert
# MISC
1 abs 1 = assert
-1 abs 1 = assert
-1 1 max 1 = assert
1 -1 max 1 = assert
1 2 max 2 = assert
-1 1 min -1 = assert
1 -1 min -1 = assert
1 2 min 1 = assert
rand64 rand64 rand64 rand64 != != && assert