S-Lang Run-Time Library Reference: Version 2.0.4: Mathematical Functions

Next Previous Contents

## 9. Mathematical Functions

## 9.1 abs

Synopsis

  Compute the absolute value of a number

Usage

  `y = abs(x)`

Description

  The `abs` function returns the absolute value of an arithmetic type. If its argument is a complex number (`Complex_Type`), then it returns the modulus. If the argument is an array, a new array will be created whose elements are obtained from the original array by using the `abs` function.

See Also

  `sign, sqr`

## 9.2 acos

Synopsis

  Compute the arc-cosine of a number

Usage

  `y = acos (x)`

Description

  The `acos` function computes the arc-cosine of a number and returns the result. If its argument is an array, the `acos` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.3 acosh

Synopsis

  Compute the inverse cosh of a number

Usage

  `y = acosh (x)`

Description

  The `acosh` function computes the inverse hyperbolic cosine of a number and returns the result. If its argument is an array, the `acosh` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.4 asin

Synopsis

  Compute the arc-sine of a number

Usage

  `y = asin (x)`

Description

  The `asin` function computes the arc-sine of a number and returns the result. If its argument is an array, the `asin` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.5 asinh

Synopsis

  Compute the inverse-sinh of a number

Usage

  `y = asinh (x)`

Description

  The `asinh` function computes the inverse hyperbolic sine of a number and returns the result. If its argument is an array, the `asinh` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.6 atan

Synopsis

  Compute the arc-tangent of a number

Usage

  `y = atan (x)`

Description

  The `atan` function computes the arc-tangent of a number and returns the result. If its argument is an array, the `atan` function will be applied to each element and the result returned as an array.

See Also

  `atan2, cos, acosh, cosh`

## 9.7 atan2

Synopsis

  Compute the arc-tangent of the ratio of two variables

Usage

  `z = atan2 (y, x)`

Description

  The `atan2` function computes the arc-tangent of the ratio `y/x` and returns the result as a value that has the proper sign for the quadrant where the point (x,y) is located. The returned value `z` will satisfy (-PI < z <= PI). If either of the arguments is an array, an array of the corresponding values will be returned.

See Also

  `hypot, cos, atan, acosh, cosh`

## 9.8 atanh

Synopsis

  Compute the inverse-tanh of a number

Usage

  `y = atanh (x)`

Description

  The `atanh` function computes the inverse hyperbolic tangent of a number and returns the result. If its argument is an array, the `atanh` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.9 ceil

Synopsis

  Round x up to the nearest integral value

Usage

  `y = ceil (x)`

Description

  This function rounds its numeric argument up to the nearest integral value. If the argument is an array, the corresponding array will be returned.

See Also

  `floor, round`

## 9.10 Conj

Synopsis

  Compute the complex conjugate of a number

Usage

  `z1 = Conj (z)`

Description

  The `Conj` function returns the complex conjugate of a number. If its argument is an array, the `Conj` function will be applied to each element and the result returned as an array.

See Also

  `Real, Imag, abs`

## 9.11 cos

Synopsis

  Compute the cosine of a number

Usage

  `y = cos (x)`

Description

  The `cos` function computes the cosine of a number and returns the result. If its argument is an array, the `cos` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.12 cosh

Synopsis

  Compute the hyperbolic cosine of a number

Usage

  `y = cosh (x)`

Description

  The `cosh` function computes the hyperbolic cosine of a number and returns the result. If its argument is an array, the `cosh` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.13 _diff

Synopsis

  Compute the absolute difference between two values

Usage

  `y = _diff (x, y)`

Description

  The `_diff` function returns a floating point number equal to the absolute value of the difference between its two arguments. If either argument is an array, an array of the corresponding values will be returned.

See Also

  `abs`

## 9.14 exp

Synopsis

  Compute the exponential of a number

Usage

  `y = exp (x)`

Description

  The `exp` function computes the exponential of a number and returns the result. If its argument is an array, the `exp` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.15 floor

Synopsis

  Round x down to the nearest integer

Usage

  `y = floor (x)`

Description

  This function rounds its numeric argument down to the nearest integral value. If the argument is an array, the corresponding array will be returned.

See Also

  `ceil, round`

## 9.16 hypot

Synopsis

  Compute sqrt(x^2+y^2)

Usage

  `r = hypot (x, y)`

Description

  The `hypot` function computes the quantity `sqrt(x^2+y^2)` except that it employs an algorithm that tries to avoid arithmetic overflow when `x` or `y` are large. If either argument is an array, an array of the corresponding values will be returned.

See Also

  `atan2, cos, atan, acosh, cosh`

## 9.17 Imag

Synopsis

  Compute the imaginary part of a number

Usage

  `i = Imag (z)`

Description

  The `Imag` function returns the imaginary part of a number. If its argument is an array, the `Imag` function will be applied to each element and the result returned as an array.

See Also

  `Real, Conj, abs`

## 9.18 isinf

Synopsis

  Test for infinity

Usage

  `y = isinf (x)`

Description

  This function returns 1 if x corresponds to an IEEE infinity, or 0 otherwise. If the argument is an array, an array of the corresponding values will be returned.

See Also

  `isnan, _Inf`

## 9.19 isnan

Synopsis

  isnan

Usage

  `y = isnan (x)`

Description

  This function returns 1 if x corresponds to an IEEE NaN (Not a Number), or 0 otherwise. If the argument is an array, an array of the corresponding values will be returned.

See Also

  `isinf, _NaN`

## 9.20 log

Synopsis

  Compute the logarithm of a number

Usage

  `y = log (x)`

Description

  The `log` function computes the natural logarithm of a number and returns the result. If its argument is an array, the `log` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.21 log10

Synopsis

  Compute the base-10 logarithm of a number

Usage

  `y = log10 (x)`

Description

  The `log10` function computes the base-10 logarithm of a number and returns the result. If its argument is an array, the `log10` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.22 _max

Synopsis

  Compute the maximum of two values

Usage

  `z = _max (x,y)`

Description

  The `_max` function returns a floating point number equal to the maximum value of its two arguments. If either argument is an array, an array of the corresponding values will be returned.

Notes

  This function returns a floating point result even when both arguments are integers.

See Also

  `max, _min, min`

## 9.23 _min

Synopsis

  Compute the minimum of two values

Usage

  `z = _min (x,y)`

Description

  The `_min` function returns a floating point number equal to the minimum value of its two arguments. If either argument is an array, an array of the corresponding values will be returned.

Notes

  This function returns a floating point result even when both arguments are integers.

See Also

  `min, _max, max`

## 9.24 mul2

Synopsis

  Multiply a number by 2

Usage

  `y = mul2(x)`

Description

  The `mul2` function multiplies an arithmetic type by two and returns the result. If its argument is an array, a new array will be created whose elements are obtained from the original array by using the `mul2` function.

See Also

  `sqr, abs`

## 9.25 polynom

Synopsis

  Evaluate a polynomial

Usage

  `Double_Type polynom(Double_Type a, b, ...c, Integer_Type n, Double_Type x)`

Description

  The `polynom` function returns the value of the polynomial expression:

  > `

  >          ax^n + bx^(n - 1) + ... c

  > `

Notes

  The `polynom` function should be extended to work with complex and array data types. The current implementation is limited to `Double_Type` quantities.

See Also

  `exp`

## 9.26 Real

Synopsis

  Compute the real part of a number

Usage

  `r = Real (z)`

Description

  The `Real` function returns the real part of a number. If its argument is an array, the `Real` function will be applied to each element and the result returned as an array.

See Also

  `Imag, Conj, abs`

## 9.27 round

Synopsis

  Round to the nearest integral value

Usage

  `y = round (x)`

Description

  This function rounds its argument to the nearest integral value and returns it as a floating point result. If the argument is an array, an array of the corresponding values will be returned.

See Also

  `floor, ceil`

## 9.28 set_float_format

Synopsis

  Set the format for printing floating point values.

Usage

  `set_float_format (String_Type fmt)`

Description

  The `set_float_format` function is used to set the floating point format to be used when floating point numbers are printed. The routines that use this are the traceback routines and the `string` function, any anything based upon the `string` function. The default value is `"%g"`

Example

  > `

  >          s = string (PI);                %  --> s = "3.14159"
  >          set_float_format ("%16.10f");
  >          s = string (PI);                %  --> s = "3.1415926536"
  >          set_float_format ("%10.6e");
  >          s = string (PI);                %  --> s = "3.141593e+00"

  > `

See Also

  `string, sprintf, double`

## 9.29 sign

Synopsis

  Compute the sign of a number

Usage

  `y = sign(x)`

Description

  The `sign` function returns the sign of an arithmetic type. If its argument is a complex number (`Complex_Type`), the `sign` will be applied to the imaginary part of the number. If the argument is an array, a new array will be created whose elements are obtained from the original array by using the `sign` function.

  When applied to a real number or an integer, the `sign` function returns `-1`, `0`, or `+1` according to whether the number is less than zero, equal to zero, or greater than zero, respectively.

See Also

  `abs`

## 9.30 sin

Synopsis

  Compute the sine of a number

Usage

  `y = sin (x)`

Description

  The `sin` function computes the sine of a number and returns the result. If its argument is an array, the `sin` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.31 sinh

Synopsis

  Compute the hyperbolic sine of a number

Usage

  `y = sinh (x)`

Description

  The `sinh` function computes the hyperbolic sine of a number and returns the result. If its argument is an array, the `sinh` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.32 sqr

Synopsis

  Compute the square of a number

Usage

  `y = sqr(x)`

Description

  The `sqr` function returns the square of an arithmetic type. If its argument is a complex number (`Complex_Type`), then it returns the square of the modulus. If the argument is an array, a new array will be created whose elements are obtained from the original array by using the `sqr` function.

Notes

  For real scalar numbers, using `x*x` instead of `sqr(x)` will result in faster executing code. However, if `x` is an array, then `sqr(x)` will execute faster.

See Also

  `abs, mul2`

## 9.33 sqrt

Synopsis

  Compute the square root of a number

Usage

  `y = sqrt (x)`

Description

  The `sqrt` function computes the square root of a number and returns the result. If its argument is an array, the `sqrt` function will be applied to each element and the result returned as an array.

See Also

  `sqr, cos, atan, acosh, cosh`

## 9.34 tan

Synopsis

  Compute the tangent of a number

Usage

  `y = tan (x)`

Description

  The `tan` function computes the tangent of a number and returns the result. If its argument is an array, the `tan` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

## 9.35 tanh

Synopsis

  Compute the hyperbolic tangent of a number

Usage

  `y = tanh (x)`

Description

  The `tanh` function computes the hyperbolic tangent of a number and returns the result. If its argument is an array, the `tanh` function will be applied to each element and the result returned as an array.

See Also

  `cos, atan, acosh, cosh`

Next Previous Contents