3.5 Trigonometric and Exponential Functions

Sh provides a variety of useful transcendental math functions. The names of these functions follow those in the C standard math library. However, generally they have been extended to operate componentwise, as with arithmetic instructions.

Supported trigonometric functions are listed in Table 3.9. These functions operate componentwise on tuples. This means that if you take the sine of an n-tuple, you will compute n sines in parallel. A special case is sincos, which computes sine and cosine in one function. It returns a tuple twice as long as the input tuple. Normally you would just apply it to a 1-tuple, but if a larger tuple is given to it multiple invocation will be made and packed together into the output tuple. All trigonometric functions take radians as their arguments. The helper function radians converts from degrees to radians and degrees goes the other way.

Functions for exponentiation and logarithms to the bases of e, 2, and 10 are listed in Table 3.10. The exponential functions also work on complex numbers, and return a complex number.





Operation r <-- a,b,c,...Description






acos  N <-- N Arccosine



/ E  acosh  N <-- N Hyperbolic arccosine



asin  N <-- N Arcsine



/ E  asinh  N <-- N Hyperbolic arcsine



/ E  atan  N <-- N Arctangent



/ E  atan2  N <-- N,N Arctangent of b/a



/ E  atanh  N <-- N Hyperbolic arctangent



cos  N <-- N Cosine



/ E  cosh  N <-- N Hyperbolic cosine



sin  N <-- N Sine



/ E  sinh  N <-- N Hyperbolic sine



/ E  tan  N <-- N Tangent



/ E  tanh  N <-- N Hyperbolic tangent



 


Table 3.9: Trigonometric functions. Some of these functions may be replaced with approximations if the compilation target does not support them directly.





Operation r <-- a,b,c,...Description






/ E  exp  N <-- N Natural (base-e) exponential



/ E  expm1  N <-- N Natural (base-e) exponential of a - 1



/ E  exp2  N <-- N Base-2 exponential



/ E  exp10  N <-- N Base-10 exponential



/ E  log  N <-- N Natural (base-e) logarithm



/ E  logp1  N <-- N Natural (base-e) logarithm of a + 1



/ E  log2  N <-- N Base-2 logarithm



/ E  log10  N <-- N Base-10 logarithm



pow  N <-- N,N Power
ri <-- (ai)bi



pow  N <-- 1,N Power
r <--  (a)bi
 i



pow  N <-- N,1 Power
        b
ri <-- (ai)



 


Table 3.10: Exponential and logarithmic functions. Some of these functions may be replaced with approximations if the compilation target does not support them.

Not all functions are supported natively on all compilation targets, but in this case Sh will implement the function using other existing capabilities. For example, trigonometric functions like sin are not available in the OpenGL ARB vertex program assembly language. Sh will evaluate a polynomial or rational approximation for these functions.


Note: This manual is available as a bound book from AK Peters, including better formatting, in-depth examples, and about 200 pages not available on-line.