# Numeric Functions

Functions that take a Numeric Scalar as their input

## abs

Transforms all values of the input variable to absolute (positive) values.

Works with:

#### Syntax

`abs(var)`

#### Examples

##### Timeseries

`at = TimeSeries("DAILY")`

at.add("2020-11-01", 12.5)

at.add("2020-11-02", -12.75)

at.add("2020-11-03", 12.9)

at.add("2020-11-04", -11.5)

at.add("2020-11-05", 11.9)

absat = abs(at)

print absat.values

`[`

{"2020-11-01": 12.5},

{"2020-11-02": 12.75},

{"2020-11-03": 12.9},

{"2020-11-04": 11.5},

{"2020-11-05": 11.9}

]

##### List

`testarray = [-1,6,0,-2]`

print abs(testarray)

##### Curve

`expiry = ExpiryCalendar(BusinessCalendar())`

expiry.addRule("go back 1 day using calendar")

ondate = CurveDate(Date("2020-12-01"), expiry)

c1 = Curve(ondate)

c1.add(Contract(ondate, "2021M01", 12.5))

c1.add(Contract(ondate, "2021M02", -12.75))

c1.add(Contract(ondate, "2021M03", 13.0))

print abs(c1)

##### Scalar

`print abs(-2)`

`2`

## acos

Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.

**Special case:** If the argument is NaN or its absolute value is greater than 1, then the result is NaN.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

#### Syntax

`acos(var)`

## asin

Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2.

**Special cases:**

- If the argument is NaN or its absolute value is greater than 1, then the result is NaN.
- If the argument is zero, then the result is a zero with the same sign as the argument.

Works with:

#### Syntax

`asin(var)`

## atan

Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2.

**Special cases:**

- If the argument is NaN or its absolute value is greater than 1, then the result is NaN.
- If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`atan(var)`

## atan2

Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi.

**Special cases:**

- If either argument is NaN, then the result is NaN.
- If the first argument is positive zero and the second argument is positive, or the first argument is positive and finite and the second argument is positive infinity, then the result is positive zero.
- If the first argument is negative zero and the second argument is positive, or the first argument is negative and finite and the second argument is positive infinity, then the result is negative zero.
- If the first argument is positive zero and the second argument is negative, or the first argument is positive and finite and the second argument is negative infinity, then the result is the double value closest to pi.
- If the first argument is negative zero and the second argument is negative, or the first argument is negative and finite and the second argument is negative infinity, then the result is the double value closest to -pi.
- If the first argument is positive and the second argument is positive zero or negative zero, or the first argument is positive infinity and the second argument is finite, then the result is the double value closest to pi/2.
- If the first argument is negative and the second argument is positive zero or negative zero, or the first argument is negative infinity and the second argument is finite, then the result is the double value closest to -pi/2.
- If both arguments are positive infinity, then the result is the double value closest to pi/4.
- If the first argument is positive infinity and the second argument is negative infinity, then the result is the double value closest to 3*pi/4.
- If the first argument is negative infinity and the second argument is positive infinity, then the result is the double value closest to -pi/4.
- If both arguments are negative infinity, then the result is the double value closest to -3*pi/4.

The computed result must be within 2 ulps of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`atan2(ordinate, abscissa)`

## cbrt

Returns the cube root of a double value. For positive finite x, cbrt(-x) == -cbrt(x); that is, the cube root of a negative value is the negative of the cube root of that value's magnitude.

**Special cases:**

- If the argument is NaN, then the result is NaN.
- If the argument is infinite, then the result is an infinity with the same sign as the argument.
- If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`cbrt(var)`

## cos

Returns the trigonometric cosine of an angle.

**Special cases:**

- If the argument is NaN or an infinity, then the result is NaN.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`cos(var)`

## cosh

Returns the hyperbolic cosine of a double value. The hyperbolic cosine of x is defined to be (ex + e-x)/2 where e is Euler's number.

**Special cases:**

- If the argument is NaN, then the result is NaN.
- If the argument is infinite, then the result is positive infinity.
- If the argument is zero, then the result is 1.0.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`cosh(var)`

## exp

Returns Euler's number e raised to the power of a double value.

**Special cases:**

- If the argument is NaN, the result is NaN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is negative infinity, then the result is positive zero.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`exp(var)`

## log

Returns the natural logarithm (base e) of a double value.

**Special cases:**

- If the argument is NaN or less than zero, then the result is NaN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is positive zero or negative zero, then the result is negative infinity.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`log(var)`

## log10

Returns the base 10 logarithm of a double value.

**Special cases:**

- If the argument is NaN or less than zero, then the result is NaN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is positive zero or negative zero, then the result is negative infinity.
- If the argument is equal to 10n for integer n, then the result is n.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`log10(var)`

## log1p

Returns the natural logarithm of the sum of the argument and 1. Note that for small values x, the result of log1p(x) is much closer to the true result of ln(1 + x) than the floating-point evaluation of log(1.0+x).

**Special cases:**

- If the argument is NaN or less than -1, then the result is NaN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is negative one, then the result is negative infinity.
- If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`log10(var)`

## pow

Returns the value of the first argument raised to the power of the second argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`pow(base, exponent)`

## sin

Returns the trigonometric sine of an angle.

**Special cases:**

- If the argument is NaN or an infinity, then the result is NaN.
- If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`sin(var)`

## sinh

Returns the hyperbolic sine of a double value. The hyperbolic sine of x is defined to be (ex - e-x)/2 where e is Euler's number.

**Special cases:**

- If the argument is NaN, then the result is NaN.
- If the argument is infinite, then the result is an infinity with the same sign as the argument.
- If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`sinh(var)`

## sqrt

Returns the correctly rounded positive square root of a double value.

**Special cases:**

- If the argument is NaN or less than zero, then the result is NaN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is positive zero or negative zero, then the result is the same as the argument.
- Otherwise, the result is the double value closest to the true mathematical square root of the argument value.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`sqrt(var)`

## tan

Returns the trigonometric tangent of an angle.

**Special cases:**

- If the argument is NaN or an infinity, then the result is NaN.
- If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`tan(var)`

## tanh

Returns the hyperbolic tangent of a double value. The hyperbolic tangent of x is defined to be (ex - e-x)/(ex + e-x), in other words, sinh(x)/cosh(x). Note that the absolute value of the exact tanh is always less than 1.

**Special cases:**

- If the argument is NaN, then the result is NaN.
- If the argument is zero, then the result is a zero with the same sign as the argument.
- If the argument is positive infinity, then the result is +1.0.
- If the argument is negative infinity, then the result is -1.0.

The computed result must be within 2.5 ulps of the exact result. The result of tanh for any finite input must have an absolute value less than or equal to 1. Note that once the exact result of tanh is within 1/2 of an ulp of the limit value of ±1, correctly signed ±1.0 should be returned.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`tanh(var)`

## toDegrees

Converts an angle measured in radians to an approximately equivalent angle measured in degrees. The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`toDegrees(var)`

## toRadians

Converts an angle measured in degrees to an approximately equivalent angle measured in radians. The conversion from degrees to radians is generally inexact.

Works with:

- Scalars
- Timeseries
- Curves
- Lists/Arrays

#### Syntax

`toRadians(var)`