dmath - a double precision calculator

Description

Interactive Commands

Math Expressions

Examples

See Also

License

Copyright

Acknowledgements

Authors

dmath

(There are no command line options.)

dmathis 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.

dmathmay be obtained as part of thedrm_toolspackage from:http://sourceforge.net/projects/drmtools/

help,h,?Show the help message

hexpShow the syntax for math expressions

=AStore the last result in variable A.

>AAdd an element to array Aand store last result in it.

<AList all values in A.

>>NameStore the last operation as Name.

<<NameRun stored operation Name.

xxNameDelete stored operation Name.

??List the stored operations.

[no]echoEcho 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,engSet scientific/engineering notation and show double precision numbers.

sint,uint,oint,xintSet signed, unsigned, octal, and hexadecimal notation and show integer numbers (converted with truncation from double precision numbers).

pnz,nnzPrint -0 as 0/-0 in scientific and engineering notation.

math expressionA MATH EXPRESSIONto calculate.

infoShow version and copyright information.

exit,quitExit 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

RETURNvalue 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,0b1010numbers in float, integer, hexadecimal, octal, or binary formats$Avariable ($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[] = 3to 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):logbase 10 loglnnatural loge1010^valeee^valchschange signabsabsolute valuerndround to nearest intlidround away from zero to next integertrcround towards zero to next integersin,asinsine, arc sine (angle in radians)cos,acoscosine, arc cosinetan,atantangent, arc tangentd2rdegrees to radiansr2dradians to degresssinh,cosh,tanhhyperbolic sine, cosine,tangentnotbitwise not (unsigned integer) Functions(val1,val2):maxmaximumminminimumand,or,xorbitwise and, or, xor (unsigned integer).shl,shrbitwise shift left/right (unsigned integer). Functions($A[range]) [scalar results only]:lennumber of cellssumsum of cellssm2sum of squares of cellsinvinvert order of cells in range, Returns 0.deldelete cells in range. Returns elements remaining. (If all deleted, variable is reset to one element with value zero.)idxreplace elements with their array positions (1-N). Returns 0.srtsort elements into ascending order. Returns 0.sixreplace elements with the positions they would occupy if sorted into ascending order. Ie {5,10,-21} -> {2,3,1}. Returns 0.nmltest 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]:catAdd 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.RETURNvalue 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/6Emits5.500000.

ini($A[],1,20,3,4,10)Initialize the variable $A as an array with 5 values 1,20,3,4,10. Emits5.000000, the number of elements in $A.

ee(1) >AEmits2.718282and then appends that value as a new element to variable $A.

<AEmits:1 1.000000 2 20.000000 3 3.000000 4 4.000000 5 10.000000 6 2.718282digits 3 sci $A[6]Emits:2.718e+00

eng dim($B[],len($A[])) $B[]=$A[] $B[1,3] - 5 - sum($B[2,5]) <BEmits: 0.000from dim()6.000from array assignment,number of elements1.000from array math, value has no significance1 -31.000Contents of $B following array math2 -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 |