next up previous 405
Next: String Processing
Up: Arithmetic
Previous: Floating Point


Intrinsic Functions

If you want to include intrinsic functions, such as logarithms and trigonometric functions in your calculations, or perhaps you need some function for an integer expression that is not supplied by the C-shell, such as finding the maximum or the absolute value, calc may be the solution. It offers the 28 functions tabulated below.

Here are a few examples.

     set a = 5
     set b = (3 4 6 -2)
     set c = `calc exp="'min( $a, $b[1], $b[2], $b[3] )'"`
     set d = `calc exp="'dim( $b[4], $a ) + dim( $b[3], $a )'"`
The first expression finds the minimum of the four integers, namely 3 and assigns it to variable c. The second expression sums two positive differences: 0 and 1 respectively.

     set mag = `calc exp="'-2.5 * LOG10( $counts )'"`
     set separation = `calc exp="atand2(35.3,$dist)"`
     echo The nearest index is `calc exp="nint($x+0.5)"`
Variable mag is the magnitude derived from the flux stored in variable counts. separation is assigned the inverse tangent of 35.3 divided by the value of variable dist measured between $-$180 and 180 degrees.


Function Number of arguments Description
     
SQRT 1 square root: $\sqrt{\mbox{arg}}$
LOG 1 natural logarithm: $\ln (\mbox{arg})$
LOG10 1 common logarithm: $\log _{10}(\mbox{arg})$
EXP 1 exponential: $\exp (\mbox{arg})$
ABS 1 absolute (positive) value: $\left\vert \mbox{arg} \right\vert$
NINT 1 nearest integer value to arg
MAX 2 or more maximum of arguments
MIN 2 or more minimum of arguments
DIM 2 Fortran DIM (positive difference) function
MOD 2 Fortran MOD (remainder) function
SIGN 2 Fortran SIGN (transfer of sign) function
SIN* 1 sine function: $\sin (\mbox{arg})$
COS* 1 cosine function: $\cos (\mbox{arg})$
TAN* 1 tangent function: $\tan (\mbox{arg})$
ASIN* 1 inverse sine function: $\sin ^{-1}(\mbox{arg})$
ACOS* 1 inverse cosine function: $\cos ^{-1}(\mbox{arg})$
ATAN* 1 inverse tangent function: $\tan ^{-1}(\mbox{arg})$
ATAN2* 2 inverse tangent function: $\tan ^{-1}(\mbox{arg1/arg2})$
SINH* 1 hyperbolic sine function: $\sinh (\mbox{arg})$
COSH* 1 hyperbolic cosine function: $\cosh (\mbox{arg})$
TANH* 1 hyperbolic tangent function: $\tanh (\mbox{arg})$
SIND* 1 sine function: $\sin (\mbox{arg})$
COSD* 1 cosine function: $\cos (\mbox{arg})$
TAND* 1 tangent function: $\tan (\mbox{arg})$
ASIND* 1 inverse sine function: $\sin ^{-1}(\mbox{arg})$
ACOSD* 1 inverse cosine function: $\cos ^{-1}(\mbox{arg})$
ATAND* 1 inverse tangent function: $\tan ^{-1}(\mbox{arg})$
ATAN2D* 2 inverse tangent function: $\tan ^{-1}(\mbox{arg1/arg2})$
  *Function does not support integer arithmetic.
     
The intrinsic functions recognised by calc (adapted from SUN/61). The angular arguments/results of the trigonometric functions are in radians, except those suffixed with a D, which are in degrees.



next up previous 405
Next: String Processing
Up: Arithmetic
Previous: Floating Point

C-shell Cookbook
Starlink Cookbook 4
Malcolm J. Currie
2006 November 26
E-mail:ussc@star.rl.ac.uk

Copyright © 2009 Science and Technology Facilities Council