Math that reads
like a note.

The complete guide to the expression engine: everyday arithmetic, natural-language equations, units, dates, time zones, and the line-based features that keep a calculation sheet useful.

This is the reference for the expression engine used by NerdyCalc. Keywords, function names, units, and variable references are not case sensitive.

Heads up. Results that depend on the current date, current time, local time zone, locale, or random number generation will vary.

How evaluation works

NerdyCalc evaluates calculation lines from top to bottom. A line can be a plain expression, assignment, boolean expression, natural-language calculation, or section command such as subtotal.

rent = 1850
utilities = 146.50
home = rent + utilities
home

→ 1,996.50

General rules

  • Variable names may contain letters, numbers, spaces, underscores, and hyphens, but must begin with a letter.
  • Parentheses control order of operations. Commas and common currency symbols are ignored inside numeric expressions.
  • The symbols ×, ÷, and − normalize to *, /, and -.
  • Natural-language operators such as plus, minus, times, multiplied by, divided by, and to the power of are normalized before parsing.
  • // starts an inline comment and is ignored during evaluation.

Basic expressions

Arithmetic operators

SyntaxExampleResult
Addition2 + 35
Subtraction10 - 46
Multiplication6 * 742
Division20 / 54
Exponentiation2 ^ 8256
Modulo17 mod 52
Remainderremainder of 17 divided by 52
Parentheses(2 + 3) * 420
Percentage25%0.25
6 times 7
6 multiplied by 7
20 divided by 5
2 to the power of 8

Constants and built-in functions

SyntaxMeaning or result
pi or πThe mathematical constant π
2.5k, 3m, 1.2bThousands, millions, and billions
sqrt(81), cbrt(-8)9 and -2
sin(30), cos(60), tan(45)0.5, 0.5, and 1; trigonometry uses degrees
exp(1), ln(exp(1)), log2(8), log(1000)Exponential, natural, base-2, and base-10 logs
abs(-12), fact(5)12 and 120
sqrt(9 + 16)
sin(90 / 2)
2 * fact(4)

Variables, labels, comments, and line references

Use name = expression. An assignment may include a label before the expression, as in total: 25 * 4. Variables can store numeric values or booleans and are normalized case-insensitively.

hourly rate = 42.50
hours = 8
day = hourly rate * hours
day

→ 340

Everything after // is ignored. Full-line comments and separators produce no numeric result.

rent = 1850 // monthly rent
# Home expenses
---
// Notes for this section

Use one-based names such as line1, line2, and line10 to reference a previous numeric line.

12
8
line1 + line2

Totals and aggregates

SyntaxExampleResult
Total / sumtotal of 10, 20, 3060
Average / meanaverage of 10, 20, 3020
Countcount of 10, 20, 303
Median, oddmedian of 1, 9, 33
Median, evenmedian of 1, 9, 3, 75

Section commands

# Groceries
12
18.50
9.25
subtotal

# Transport
25
sum

total
  • subtotal totals all evaluated numeric lines in the sheet.
  • sum totals the current section since the most recent heading or separator.
  • total excludes earlier aggregate command rows.
  • Percent results are applied to the amount total: 100, 10% totals as 110.

Boolean expressions and conditionals

true
false
is ready = true
10 == 10
age >= 18 and has ticket == true

Supported comparisons are ==, !=, >, <, >=, and <=. Compatible quantities with units or clock times can be compared too. Combine comparisons with && / || or and / or.

age = 21
if age >= 18 then status = true else status = false
status

The else branch is optional. Expressions can also be conditional with discount if is member == true and discount unless is member == true.

Percentages, fractions, and multipliers

The engine distinguishes 15% from 15. In percentage-aware phrases, a bare number is treated as a percentage.

SyntaxMeaningExample result
0.15 as % / as percentDisplay as percentage15%
15 as % of 60Part as percentage of whole25%
100 to 125 as %Percentage change25%
15 of 200 / 15 on 200 / 15 off 200Percent of, add to, or remove from30 / 230 / 170
30 is 15% of whatSolve for the unknown whole200
200 + 15%
200 - 15%
200 + 15% tip

These evaluate to 230, 170, and 230. Display fractions and multipliers with 0.75 as a fraction, 1.5 as x, 3 as x of 12, and 3 to 12 is what x.

Number bases

Literal or functionBaseDecimal/result
0b1010Binary10
0o17Octal15
0xFFHexadecimal255
hex(255) / bin(10) / oct(15)Convert0xff / 0b1010 / 0o17
255 as hex
255 in hexadecimal
255 to base16
0b1010 as decimal
0xFF to binary
15 in octal

Accepted names are hex / hexadecimal / base16, bin / binary / base2, oct / octal / base8, and dec / decimal / base10. Signed literals such as -0x10 are supported.

Advanced mathematics

SyntaxResult
square root of 819
cube root of -8-2
root 4 of 162
log 1000 base 103
16 is 2 to what power4
Domain rulesSquare roots require non-negative values. Cube roots support negative values. Even roots of negative values are rejected. Root degree cannot be zero. Logarithm values and bases must be positive, and the base cannot be 1.

Rounding and precision

SyntaxResult
3.14159 to 2 dp / to 2 decimal places3.14
12.34567 to 3 digits12.346
3.6 rounded4
3.6 rounded down / 3.1 rounded up3 / 4
126 to nearest 10130
1234 to nearest hundred1,200

Use rounded up to nearest 10 or rounded down to nearest 10 for directed multiple rounding. Decimal places and digits may be from 0 through 15.

Finance

Rates can be percentages or decimal rates. A bare rate greater than 1 is interpreted as a percentage, so 5 means 5% in finance phrases.

SyntaxMeaning
annual return on 100 invested 121 returned after 2 yearsAnnualized return: 10%
100 invested 125 returnedROI multiplier: 0.25x
present value of 1000 after 3 years at 5%Discounted present value
1000 after 3 years at 5% compounding monthlyFuture value
interest on 1000 after 3 years at 5%Interest only

for can replace after. Compound interest uses principal × (1 + annualRate / periodsPerYear)^(periodsPerYear × years).

monthly repayment on 300000 over 30 years at 6%
annual interest on 300000 over 30 years at 6%
total repayment on 300000 over 30 years at 6%
5% / day to decimal

Loan calculations use a monthly amortization schedule. The monthly repayment formula is P × r / (1 - (1 + r)^(-n)), where r is annual rate divided by 12 and n is years multiplied by 12.

Units and conversions

Conversion syntax

5 km to mi
5 km in mi
5 km > mi
5 km -> mi
miles in 5 kilometers
90 minutes in hours

Only units from the same dimension can be converted directly, except Celsius/Fahrenheit temperature conversion.

Dimensional arithmetic

ExampleMeaning
2 m + 30 cmAdd compatible lengths
1 kg - 250 gSubtract compatible masses
10 m * 3 / 10 m / 2Scale a length
4 m * 5 mCalculate an area, displayed as m²
2 m + 5 sRejected: incompatible dimensions

Supported unit families

Lengthnm, µm, mm, cm, dm, m, km
in, ft, yd, mi, fur, ftm, nmi, ly
px, pt, em
Areanm², µm², mm², cm², m², km²
in², ft², yd², mi²
a, ha, ac
Volumeµm³, mm³, cm³, m³, km³
ml, µl, l, kl, ML
tsp, tbsp, cup, fl oz, pint, quart, gallon
Timens, µs, ms, s, min, h, d, wk, mo, yr
Massng, mcg, mg, g, kg, t
oz, lb, st, ton, oz t, ct
Speed & anglem/s, km/h, mph, kn
rad, radians, °, deg
Frequency & powernHz through THz
hp, mW, W, kW, MW, GW, TW
EnergyTWh through Wh
kCal, cal, GJ, MJ, kJ, J
Digital storagebit, B; kb through YB
Kib through YiB
Data ratebps, Bps; kbps through YBps
Binary Kibps through YiBps
Temperaturecelsius, fahrenheit
°F, °C, degC, degF

Square and cubic units accept superscripts or forms such as , m^2, m2, , m^3, and m3. Uppercase B means bytes; lowercase b means bits.

Time spans and laptimes

Durations can combine multiple units; the engine converts them to seconds internally and formats the result as a readable span.

1 week 2 days 3 hours 4 minutes 5 seconds
SyntaxMeaning
3661 secondsAutomatic readable duration
3661 seconds as timespanExplicit readable duration
3661 seconds as laptime01:01:01
01:02:03.500One hour, two minutes, and 3.5 seconds
3661 seconds in hours and minutes1 h 1 m
90061 seconds in days and hours1 day 1 h

Supported laptime shapes are MM:SS, HH:MM:SS, and HH:MM:SS.fraction, with either a period or comma before fractional seconds.

Video timecodes and frames

Video equations use HH:MM:SS:FF timecodes and an explicit frame rate written as at 30 fps or @ 30 fps.

SyntaxMeaning
00:01:02:12 at 30 fpsParse a timecode
1 minute at 30 fps in framesConvert duration to frames
30 fps * 2 secondsFrames in a duration
120 frames / 30 fpsConvert frames to seconds
90 frames at 30 fpsFormat a frame count as timecode
1 second 12 frames at 30 fpsCombine duration and frame remainder

Frame numbers must be less than the frame rate. In a 30 fps timecode, the frame part must be 00 through 29.

Dates and calendars

Current date and time

SyntaxResult
today / nowCurrent local date and time
week of yearCurrent ISO week number
week number on January 1, 2025ISO week number for a date
weeks in 2025Number of ISO weeks in a year
days in February 2025Number of days in a month

Accepted inputs and calendar equations

today
tomorrow
this monday
next friday
January 1, 2025
2025-01-01T12:30:00
01/01/2025
weekday on January 1, 2025
workdays in 4 weeks
January 1, 2025 + 5 workdays
week of year
days in February 2025
days between January 1, 2025 and January 10, 2025
midpoint between January 1, 2025 and January 11, 2025
2 weeks after January 1, 2025
2 days ago

Recognized holidays include New Year, New Year’s Eve, Valentine’s Day, Easter, Memorial Day, Independence Day, Fourth of July, Labor Day, Halloween, Thanksgiving, Christmas, and Boxing Day. Workday calculations exclude Saturdays, Sundays, and the engine’s built-in public holidays.

500 / workday * 4 weeks
500 / workdays × 4 weeks

Clock arithmetic and time zones

5 pm + 2 hours
9:30 am - 45 minutes
now + 90 minutes
11:30 pm + 2 hours
9:00 am to 5:30 pm
time in Tokyo
time in timezone London
Tokyo time
date in Sydney
9:00 am New York to London
time difference between New York and London

Clock results include “Yesterday at” or “Tomorrow at” when a calculation crosses a date boundary. Duration terms support seconds, minutes, hours, days, weeks, months, and years. The engine recognizes fixed abbreviations such as EST, EDT, CST, CDT, MST, MDT, PST, PDT, UTC, and GMT+5:30, plus common city aliases and supported IANA time-zone identifiers.

Special math helpers

SyntaxResult or meaning
half of 8040
midpoint between 10 and 2015
random number between 1 and 6Random integer from 1 through 6
random number between 0 and 1Random decimal in the unit interval
gcd of 84 and 306
greatest common divisor of 84 and 306
lcm of 12 and 1836
least common multiple of 12 and 1836

Integer-only helpers such as gcd and lcm reject non-integral inputs.

Formatting and limitations

Display behavior

  • Ordinary numeric results display up to six fractional digits.
  • Currency expressions preserve the detected symbol: $, €, £, ¥, or ₹.
  • Function calls and unit results use natural precision with category-specific maximums.
  • Percentage results display with %; multiplier results display with x.
  • Base conversions display with 0b, 0o, or 0x prefixes.
  • Date and time output follows the engine’s local calendar and time zone.

Invalid or unsupported expressions

The engine returns an em dash (—) for an expression it cannot solve. Common causes include division by zero; invalid roots or logarithms; incompatible unit dimensions; unrelated conversions; invalid frame numbers; missing time zones; and malformed assignments or unrecognized phrases.

Source coverageThe documented families map to the evaluation pipeline in CalculatorEngine.swift: arithmetic, variables, aggregates, booleans, percentages, bases, advanced math, rounding, finance, dimensions, durations, video, calendars, clocks, and time zones.