dmath - a double precision calculator
Description
Interactive Commands
Math Expressions
Examples
See Also
License
Copyright
Acknowledgements
Authors
dmath
(There are no command line options.)
dmath is a double precision calculator that takes its commands from stdin and writes its results to stdout. It also supports bitwise operations on integer values - which are converted out of and back into double precision float represenation as needed. Operations are supported both on scalar and array operands.dmath may be obtained as part of the drm_tools package from: http://sourceforge.net/projects/drmtools/
help,h,? Show the help message
hexp Show the syntax for math expressions
=A Store the last result in variable A.
>A Add an element to array A and store last result in it.
<A List all values in A.
>>Name Store the last operation as Name.
<<Name Run stored operation Name.
xxName Delete stored operation Name.
?? List the stored operations.
[no]echo Echo input to output (instead of just results).
digits # The number of digits shown after the decimal for double precision notations and the total number of digits shown for integer notations. (default is 6)
sci,eng Set scientific/engineering notation and show double precision numbers.
sint,uint,oint,xint Set signed, unsigned, octal, and hexadecimal notation and show integer numbers (converted with truncation from double precision numbers).
pnz,nnz Print -0 as 0/-0 in scientific and engineering notation.
math expression A MATH EXPRESSION to calculate.
info Show version and copyright information.
exit,quit Exit the program.
Math expressions use an algebraic syntax to operate on 26 variables ($A-$Z, not case sensitive).Scalar and Array math: Unless otherwise noted operators and functions will work with either scalar or array operands. If array operands are used the result will also be an array, with intermediate values stored in the leftmost array at each operation. In scalar math the RETURN value is meaningful, but it is not in array math.
Array elements are indexed as 1->N (from start) or -1->-N (from end).
Operands: 12e-1,120,0xF0,0o77,0b1010 numbers in float, integer, hexadecimal, octal, or binary formats $A variable ($A is the same as $A[1]) $A[12],$A[3,4],$A[] element, range of elements, all elements Assignment: $A[6] = 1+$B[$C[3]] to an element $A[1,2]= $B[3,4] to a range of alements (number must match) $A[] = 3 to an entire array Expressions may contain 0 or 1 ’=’ assignments. Operators: val1 OP val2 + addition - subtraction * multiplication % remainder ^ power (val1 ^ val2) ? compare (returns 1,0,-1 if value is >,==,< zero) Functions(val): log base 10 log ln natural log e10 10^val ee e^val chs change sign abs absolute value rnd round to nearest int lid round away from zero to next integer trc round towards zero to next integer sin,asin sine, arc sine (angle in radians) cos,acos cosine, arc cosine tan,atan tangent, arc tangent d2r degrees to radians r2d radians to degress sinh,cosh,tanh hyperbolic sine, cosine,tangent not bitwise not (unsigned integer) Functions(val1,val2): max maximum min minimum and,or,xor bitwise and, or, xor (unsigned integer). shl,shr bitwise shift left/right (unsigned integer). Functions($A[range]) [scalar results only]: len number of cells sum sum of cells sm2 sum of squares of cells inv invert order of cells in range, Returns 0. del delete cells in range. Returns elements remaining. (If all deleted, variable is reset to one element with value zero.) idx replace elements with their array positions (1-N). Returns 0. srt sort elements into ascending order. Returns 0. six replace elements with the positions they would occupy if sorted into ascending order. Ie {5,10,-21} -> {2,3,1}. Returns 0. nml test for normal numbers. 0=all elements normal, 1=at least one infinite, 2=at least one NaN, 3=some infinite and some NaN Functions($A[],value) [scalar results only]: dim (Re)size $A to value entries. New elements = 0.0. Returns 0. Functions($A[],val1,val2,...) [scalar results only]: cat Add values as new elements to $A, returns new length. ini (Re)initialize $A with values as elements, returns (new) length. Functions($A[],$B[]) [array results only] Rearrange array contents. RETURN value is not meaningful. map $A[i] = $A[$B[i]] for all i in the range. ump $A[$B[i]]= $A[i] for all i in the range (unmap). Operator Precedence: ^ > */% > +- > ? > (), > =
These examples assume they are run in the order shown, so that results from preceding operations are present.5+3/6 Emits 5.500000.
ini($A[],1,20,3,4,10) Initialize the variable $A as an array with 5 values 1,20,3,4,10. Emits 5.000000, the number of elements in $A.
ee(1) >A Emits 2.718282 and then appends that value as a new element to variable $A.
<A Emits: 1 1.000000 2 20.000000 3 3.000000 4 4.000000 5 10.000000 6 2.718282 digits 3 sci $A[6] Emits: 2.718e+00
eng dim($B[],len($A[])) $B[]=$A[] $B[1,3] - 5 - sum($B[2,5]) <B Emits: 0.000 from dim() 6.000 from array assignment,number of elements 1.000 from array math, value has no significance 1 -31.000 Contents of $B following array math 2 -12.000 3 -29.000 4 4.000 5 10.000 6 2.718
extract(1)
GNU General Public License 2
Copyright (C) 2012 David Mathog and Caltech.
none
David Mathog, Biology Division, Caltech <mathog@caltech.edu>
drm_tools | dmath (1) | 0.0.8 Dec 12 2012 |