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
| Syntax | Example | Result |
| Addition | 2 + 3 | 5 |
| Subtraction | 10 - 4 | 6 |
| Multiplication | 6 * 7 | 42 |
| Division | 20 / 5 | 4 |
| Exponentiation | 2 ^ 8 | 256 |
| Modulo | 17 mod 5 | 2 |
| Remainder | remainder of 17 divided by 5 | 2 |
| Parentheses | (2 + 3) * 4 | 20 |
| Percentage | 25% | 0.25 |
6 times 7
6 multiplied by 7
20 divided by 5
2 to the power of 8
Constants and built-in functions
| Syntax | Meaning or result |
pi or π | The mathematical constant π |
2.5k, 3m, 1.2b | Thousands, 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
| Syntax | Example | Result |
|---|
| Total / sum | total of 10, 20, 30 | 60 |
| Average / mean | average of 10, 20, 30 | 20 |
| Count | count of 10, 20, 30 | 3 |
| Median, odd | median of 1, 9, 3 | 3 |
| Median, even | median of 1, 9, 3, 7 | 5 |
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.
| Syntax | Meaning | Example result |
|---|
0.15 as % / as percent | Display as percentage | 15% |
15 as % of 60 | Part as percentage of whole | 25% |
100 to 125 as % | Percentage change | 25% |
15 of 200 / 15 on 200 / 15 off 200 | Percent of, add to, or remove from | 30 / 230 / 170 |
30 is 15% of what | Solve for the unknown whole | 200 |
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 function | Base | Decimal/result |
|---|
0b1010 | Binary | 10 |
0o17 | Octal | 15 |
0xFF | Hexadecimal | 255 |
hex(255) / bin(10) / oct(15) | Convert | 0xff / 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
| Syntax | Result |
|---|
square root of 81 | 9 |
cube root of -8 | -2 |
root 4 of 16 | 2 |
log 1000 base 10 | 3 |
16 is 2 to what power | 4 |
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
| Syntax | Result |
|---|
3.14159 to 2 dp / to 2 decimal places | 3.14 |
12.34567 to 3 digits | 12.346 |
3.6 rounded | 4 |
3.6 rounded down / 3.1 rounded up | 3 / 4 |
126 to nearest 10 | 130 |
1234 to nearest hundred | 1,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.
| Syntax | Meaning |
|---|
annual return on 100 invested 121 returned after 2 years | Annualized return: 10% |
100 invested 125 returned | ROI multiplier: 0.25x |
present value of 1000 after 3 years at 5% | Discounted present value |
1000 after 3 years at 5% compounding monthly | Future 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
| Example | Meaning |
|---|
2 m + 30 cm | Add compatible lengths |
1 kg - 250 g | Subtract compatible masses |
10 m * 3 / 10 m / 2 | Scale a length |
4 m * 5 m | Calculate an area, displayed as m² |
2 m + 5 s | Rejected: 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², m^2, m2, m³, 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
| Syntax | Meaning |
|---|
3661 seconds | Automatic readable duration |
3661 seconds as timespan | Explicit readable duration |
3661 seconds as laptime | 01:01:01 |
01:02:03.500 | One hour, two minutes, and 3.5 seconds |
3661 seconds in hours and minutes | 1 h 1 m |
90061 seconds in days and hours | 1 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.
| Syntax | Meaning |
|---|
00:01:02:12 at 30 fps | Parse a timecode |
1 minute at 30 fps in frames | Convert duration to frames |
30 fps * 2 seconds | Frames in a duration |
120 frames / 30 fps | Convert frames to seconds |
90 frames at 30 fps | Format a frame count as timecode |
1 second 12 frames at 30 fps | Combine 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
| Syntax | Result |
|---|
today / now | Current local date and time |
week of year | Current ISO week number |
week number on January 1, 2025 | ISO week number for a date |
weeks in 2025 | Number of ISO weeks in a year |
days in February 2025 | Number 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
| Syntax | Result or meaning |
|---|
half of 80 | 40 |
midpoint between 10 and 20 | 15 |
random number between 1 and 6 | Random integer from 1 through 6 |
random number between 0 and 1 | Random decimal in the unit interval |
gcd of 84 and 30 | 6 |
greatest common divisor of 84 and 30 | 6 |
lcm of 12 and 18 | 36 |
least common multiple of 12 and 18 | 36 |
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.