- publishing free software manuals
The Org Mode 7 Reference Manual
by Carsten Dominik and others
Paperback (6"x9"), 282 pages
ISBN 9781906966089
RRP £9.95 ($14.95)

Sales of this book support the Org project! Get a printed copy>>>

15.2 Formula syntax for Calc

A formula can be any algebraic expression understood by the Emacs ‘Calc’ package. Note that ‘calc’ has the non-standard convention that ‘/’ has lower precedence than ‘*’, so that ‘a/b*c’ is interpreted as ‘a/(b*c)’. Before evaluation by calc-eval (see section `Calling Calc from Your Lisp Programs' in GNU Emacs Calc Manual), variable substitution takes place according to the rules described above. The range vectors can be directly fed into the Calc vector functions like ‘vmean’ and ‘vsum’.

A formula can contain an optional mode string after a semicolon. This string consists of flags to influence Calc and other modes during execution. By default, Org uses the standard Calc modes (precision 12, angular units degrees, fraction and symbolic modes off). The display format, however, has been changed to (float 8) to keep tables compact. The default settings can be configured using the variable org-calc-default-modes.

p20 set the internal Calc calculation precision to 20 digits
n3 s3 e2 f4 Normal, scientific, engineering, or fixed format of the result of Calc passed back to Org. Calc formatting is unlimited in precision as long as the Calc calculation precision is greater.
D R angle modes: degrees, radians
F S fraction and symbolic modes
N interpret all fields as numbers, use 0 for non-numbers
T force text interpretation
E keep empty fields in ranges
L literal
Unless you use large integer numbers or high-precision-calculation and -display for floating point numbers you may alternatively provide a printf format specifier to reformat the Calc result after it has been passed back to Org instead of letting Calc already do the formatting.(132) A few examples:
$1+$2 Sum of first and second field
$1+$2;%.2f Same, format result to two decimals
exp($2)+exp($1) Math functions can be used
$0;%.1f Reformat current cell to 1 decimal
($3-32)*5/9 Degrees F -> C conversion
$c/$1/$cm Hz -> cm conversion, using ‘constants.el’
tan($1);Dp3s1 Compute in degrees, precision 3, display SCI 1
sin($1);Dp3%.1e Same, but use printf specifier for display
vmean($2..$7) Compute column range mean, using vector function
vmean($2..$7);EN Same, but treat empty fields as 0
taylor($3,x=7,2) Taylor series of $3, at x=7, second degree
Calc also contains a complete set of logical operations. For example
if($1<20,teen,string(""))  “teen” if age $1 less than 20, else empty
ISBN 9781906966089The Org Mode 7 Reference ManualSee the print edition