ABCalc is a powerful programmable calculator with support for complex expressions, some of them shown on this page.

Copy the expressions to ABCalc to see its power.

Sample #1. Fibonacci sequence

Illustrates the use of a multi-statement sequence, memory operations, while, compound assignment (+=), implicit last-expression return.

// 15th Fibonacci number
a := 0; b := 1; i := 2;
while (i <= 15) {
    t := a + b;
    a := b;
    b := t;
    i += 1;
};

Expected value: 610

Sample #2. Compound interest

Illustrates the use of an arrow-form custom function, the ** exponentiation operator, and the percent math (1 + 7% → 1.07). The 10_000 underscore separator is a visual touch.

// $10 000 at 7% annually for 20 years
fn FutureValue(principal; rate; years) =>
    principal * (1 + rate) ** years;

FutureValue(10_000; 7%; 20)

Expected value: 38 696.84...

Sample #3. RGB unpacking

Illustrates the use of hex literals (0xFF6A00), >> bit-shift, BIT_AND, and string concatenation all in one expression.

// Unpack 24-bit hex colour into channels
color := 0xFF6A00;
r := (color >> 16) BIT_AND 0xFF;
g := (color >> 8)  BIT_AND 0xFF;
b :=  color        BIT_AND 0xFF;
'R=' + r + '  G=' + g + '  B=' + b

Expected value: R=255 G=106 B=0

Sample #4. Combinations C(n,k)

Illustrates the use of a postfix ! factorial and memory operations.

// "10 choose 3" via postfix factorial
n := 10; k := 3;
n! / (k! * (n - k)!)

Expected value: 120

Sample #5. Complex number multiplication

Illustrates the use of complex literals (4 + 3i, 1 - 2i)

// (4+3i) × (1−2i) = 10−5i
z := 4 + 3i;
w := 1 - 2i;
z * w

Expected value: 10-5i

Sample #6. First element above threshold

Illustrates the use of a list literal, Count(), indexed access data[ctr], and the return keyword to break out of a loop early.

// Early-exit list search
data := (18; 42; 7; 99; 3; 55; 21);
ctr := 0;
while (ctr < Count(data)) {
    if (data[ctr] > 50) { return data[ctr]; };
    ctr += 1;
};
null

Expected value: 99

Sample #7. Business hours check

Illustrates the use of #datetime# literals and a ternary ? : operator producing a string result.

// Is the appointment within office hours?
appt   := #2026-06-15T14:30:00#;
opens  := #2026-06-15T09:00:00#;
closes := #2026-06-15T17:00:00#;
appt >= opens and appt <= closes
    ? 'Within business hours'
    : 'Outside business hours'

Expected value: Within business hours

Sample #8. String slicing

Illustrates the use of slice notation [..3] for a prefix slice and the ^ caret (count-from-end) notation for a suffix slice.

// First and last word via range slices
phrase := 'The quick brown fox jumps';
first  := phrase[..3];
last   := phrase[^5..];
first + ' ... ' + last

Expected value: The ... jumps

Sample #9. Clamp with multi-call demo

Illustrates the use of a full-body fn with if/return guards and an implicit return, then called three times in one expression to show the range behavior.

// Constrain values to [0, 100]
fn Clamp(x; lo; hi) {
    if (x < lo) { return lo; };
    if (x > hi) { return hi; };
    x
};
Clamp(-7; 0; 100) + ', ' +
Clamp(42; 0; 100) + ', ' +
Clamp(250; 0; 100)

Expected value: 0, 42, 100

Sample #10. Unix-style permission flags

Illustrates the use of binary literals (0b001), BIT_OR to compose flags, BIT_AND + != 0 to test a flag, showing the whole read/write/exec pattern.

// Compose and inspect bit-field permissions
READ  := 0b001;
WRITE := 0b010;
EXEC  := 0b100;
perms    := READ BIT_OR WRITE;
has_exec := (perms BIT_AND EXEC) != 0;
full     := perms BIT_OR EXEC;
'rw=' + perms + '  rwx=' + full
    + '  exec=' + has_exec

Expected value: rw=3 rwx=7 exec=False