PROPHET/OS
NAME
calc: an exact decimal calculator, one-shot or interactive
SYNOPSIS
calc [expression|selbsttest]
DESCRIPTION
An exact decimal calculator, one-shot or interactive.
operators + - * / ^, parentheses, hex 0x.., binary 0b..
functions sqrt abs floor ceil round, sin cos tan and their kin,
exp ln log, pow root hypot, integral(f, a, b)
money pmt(amount, rate, n), fv(amount, rate, n), pv(amount, rate, n),
rates(amount, n[, rounding])
/mode standard, finance (two places, like money), scientific,
programmer (also hex and binary)
/round half, commercial, down, floor, ceiling, up
constants pi e
calc 0.1 + 0.2 exact 0.3, no binary rounding
calc 2^64 18446744073709551616
calc (0x1F + 0b1010) * 3 mixes hex, binary, decimal
calc sqrt(16) + pow(2, 10) 4 + 1024 = 1028
Money
calc rates(12000, 6) 6 x 2000.00 calc rates(12000, 7) 6 x 1714.28, then 1714.32 calc rates(100.005, 3) not possible calc /mode finance pmt(12000, 0.049/12, 12) the monthly rate of a loan at 4.9 % calc /mode finance fv(10000, 0.03, 10) 10000 after ten years at 3 %
rates writes a plan the way a financing does, and rounds nothing: the amount in cents divided by n, quotient and remainder; n - 1 rates of the quotient, the last one adds the remainder. An amount below the cent, or fewer cents than rates, is "not possible". Only a third word rounds the amount to the cent first, by the name /round takes: rates(12000 * 1.049, 7, commercial). pmt is the rate of an annuity with rate per period, fv what an amount grows to and pv what a later amount is worth today.
Decimal and exact, not binary floating point: 0.1 + 0.2 is 0.3 here because the arithmetic underneath is decimal, 34 digits. A line of whole numbers only (+ - * % ^, signs and brackets) is exact at any length up to 20000 digits: calc 2^1000 prints all 302 of them. A point, a division or a function in the line sends it to the decimal arithmetic.
calc selbsttest drives the exponent of the scientific form at both ends of an i32. The most negative one cannot be typed in, because the parser never builds such an exponent, so the probe sets the field: until 2026-10-14 the magnitude was taken with a signed negation, which is undefined there (R12-CALC-01).
EXAMPLE
$ calc 'e^(pi*sqrt(163))' 262537412640768743.9999999999992455 reported: inexact