> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Math Functions

## Math Functions

<AccordionGroup>
  <Accordion title="ABS(expr)" id="abs-expr" defaultOpen>
    Calculates the absolute value of `expr`
  </Accordion>

  <Accordion title="ACOS(expr)" id="acos-expr" defaultOpen>
    Returns the inverse cosine (arccosine) of `expr` as a *double*
  </Accordion>

  <Accordion title="ACOSF(expr)" id="acosf-expr" defaultOpen>
    Returns the inverse cosine (arccosine) of `expr` as a *float*
  </Accordion>

  <Accordion title="ACOSH(expr)" id="acosh-expr" defaultOpen>
    Returns the inverse hyperbolic cosine of `expr` as a *double*
  </Accordion>

  <Accordion title="ACOSHF(expr)" id="acoshf-expr" defaultOpen>
    Returns the inverse hyperbolic cosine of `expr` as a *float*
  </Accordion>

  <Accordion title="ASIN(expr)" id="asin-expr" defaultOpen>
    Returns the inverse sine (arcsine) of `expr` as a *double*
  </Accordion>

  <Accordion title="ASINF(expr)" id="asinf-expr" defaultOpen>
    Returns the inverse sine (arcsine) of `expr` as a *float*
  </Accordion>

  <Accordion title="ASINH(expr)" id="asinh-expr" defaultOpen>
    Returns the inverse hyperbolic sine of `expr` as a *double*
  </Accordion>

  <Accordion title="ASINHF(expr)" id="asinhf-expr" defaultOpen>
    Returns the inverse hyperbolic sine of `expr` as a *float*
  </Accordion>

  <Accordion title="ATAN(expr)" id="atan-expr" defaultOpen>
    Returns the inverse tangent (arctangent) of `expr` as a *double*
  </Accordion>

  <Accordion title="ATANF(expr)" id="atanf-expr" defaultOpen>
    Returns the inverse tangent (arctangent) of `expr` as a *float*
  </Accordion>

  <Accordion title="ATANH(expr)" id="atanh-expr" defaultOpen>
    Returns the inverse hyperbolic tangent of `expr` as a *double*
  </Accordion>

  <Accordion title="ATANHF(expr)" id="atanhf-expr" defaultOpen>
    Returns the inverse hyperbolic tangent of `expr` as a *float*
  </Accordion>

  <Accordion title="ATAN2(x, y)" id="atan2-x-y" defaultOpen>
    Returns the inverse tangent (arctangent) using two arguments as a *double*
  </Accordion>

  <Accordion title="ATAN2F(x, y)" id="atan2f-x-y" defaultOpen>
    Returns the inverse tangent (arctangent) using two arguments as a *float*
  </Accordion>

  <Accordion title="ATN2(x, y)" id="atn2-x-y" defaultOpen>
    Alias for `ATAN2`
  </Accordion>

  <Accordion title="ATN2F(x, y)" id="atn2f-x-y" defaultOpen>
    Alias for `ATAN2F`
  </Accordion>

  <Accordion title="CBRT(expr)" id="cbrt-expr" defaultOpen>
    Returns the cube root of `expr` as a *double*
  </Accordion>

  <Accordion title="CBRTF(expr)" id="cbrtf-expr" defaultOpen>
    Returns the cube root of `expr` as a *float*
  </Accordion>

  <Accordion title="CEIL(expr)" id="ceil-expr" defaultOpen>
    Alias for `CEILING`
  </Accordion>

  <Accordion title="CEILING(expr)" id="ceiling-expr" defaultOpen>
    Rounds `expr` up to the next highest integer
  </Accordion>

  <Accordion title="COS(expr)" id="cos-expr" defaultOpen>
    Returns the cosine of `expr` as a *double*
  </Accordion>

  <Accordion title="COSF(expr)" id="cosf-expr" defaultOpen>
    Returns the cosine of `expr` as a *float*
  </Accordion>

  <Accordion title="COSH(expr)" id="cosh-expr" defaultOpen>
    Returns the hyperbolic cosine of `expr` as a *double*
  </Accordion>

  <Accordion title="COSHF(expr)" id="coshf-expr" defaultOpen>
    Returns the hyperbolic cosine of `expr` as a *float*
  </Accordion>

  <Accordion title="COT(expr)" id="cot-expr" defaultOpen>
    Returns the cotangent of `expr` as a *double*
  </Accordion>

  <Accordion title="COTF(expr)" id="cotf-expr" defaultOpen>
    Returns the cotangent of `expr` as a *float*
  </Accordion>

  <Accordion title="DEGREES(expr)" id="degrees-expr" defaultOpen>
    Returns the conversion of `expr` (in radians) to degrees as a *double*
  </Accordion>

  <Accordion title="DEGREESF(expr)" id="degreesf-expr" defaultOpen>
    Returns the conversion of `expr` (in radians) to degrees as a *float*
  </Accordion>

  <Accordion title="DIVZ(a, b, c)" id="divz-a-b-c" defaultOpen>
    Returns the quotient `a / b` unless `b == 0`, in which case it returns `c`
  </Accordion>

  <Accordion title="EXP(expr)" id="exp-expr" defaultOpen>
    Returns *e* to the power of `expr` as a *double*
  </Accordion>

  <Accordion title="EXPF(expr)" id="expf-expr" defaultOpen>
    Returns *e* to the power of `expr` as a *float*
  </Accordion>

  <Accordion title="FLOOR(expr)" id="floor-expr" defaultOpen>
    Rounds `expr` down to the next lowest integer
  </Accordion>

  <Accordion title="GREATER(expr_a, expr_b)" id="greater-expr_a-expr_b" defaultOpen>
    Returns whichever of `expr_a` and `expr_b` has the larger value, based on typed
    comparison
  </Accordion>

  <Accordion title="HYPOT(x, y)" id="hypot-x-y" defaultOpen>
    Returns the hypotenuse of `x` and `y` as a *double*
  </Accordion>

  <Accordion title="HYPOTF(x, y)" id="hypotf-x-y" defaultOpen>
    Returns the hypotenuse of `x` and `y` as a *float*
  </Accordion>

  <Accordion title="IFERROR(expr, val)" id="iferror-expr-val" defaultOpen>
    Alias for `IF_ERROR(expr, val)`
  </Accordion>

  <Accordion title="IFINF(expr, val)" id="ifinf-expr-val" defaultOpen>
    Alias for `IF_INF(expr, val)`
  </Accordion>

  <Accordion title="IFINFINITY(expr, val)" id="ifinfinity-expr-val" defaultOpen>
    Alias for `IF_INF(expr, val)`
  </Accordion>

  <Accordion title="IFNAN(expr, val)" id="ifnan-expr-val" defaultOpen>
    Alias for `IF_NAN(expr, val)`
  </Accordion>

  <Accordion title="IF_ERROR(expr, val)" id="if_error-expr-val" defaultOpen>
    Evaluates the given *double* or *float* `expr`, and if it resolves to infinity or
    `NaN`, return `val`

    <Tip>
      Conceptually, this function is the same as
      `IF_INF(IF_NAN(expr, val), val)`
    </Tip>

    Example:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Function Call</th>
            <th>Result</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>IF\_ERROR((double(10)/0), 1)</code></td>
            <td><code>1.0</code></td>
          </tr>

          <tr>
            <td><code>IF\_ERROR(log(-1), 1)</code></td>
            <td><code>1.0</code></td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="IF_INF(expr, val)" id="if_inf-expr-val" defaultOpen>
    Evaluates the given *double* or *float* `expr`, and if it resolves to infinity,
    return `val`

    Example:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Function Call</th>
            <th>Result</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>IF\_INF((double(10)/0), 999)</code></td>
            <td><code>999.0</code></td>
          </tr>

          <tr>
            <td><code>IF\_INF(log(-1), 999)</code></td>
            <td><code>NaN</code></td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="IF_INFINITY(expr, val)" id="if_infinity-expr-val" defaultOpen>
    Alias for `IF_INF(expr, val)`
  </Accordion>

  <Accordion title="IF_NAN(expr, val)" id="if_nan-expr-val" defaultOpen>
    Evaluates the given *double* or *float* `expr`, and if it resolves to `NaN`,
    return `val`

    Example:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Function Call</th>
            <th>Result</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>IF\_NAN((double(10)/0), -1)</code></td>
            <td><code>Infinity</code></td>
          </tr>

          <tr>
            <td><code>IF\_NAN(log(-1), -1)</code></td>
            <td><code>-1.0</code></td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="ISINFINITY(expr)" id="isinfinity-expr" defaultOpen>
    Returns `1` (true) if `expr` is infinity by IEEE standard; otherwise, returns
    `0` (false)
  </Accordion>

  <Accordion title="IS_INFINITY(expr)" id="is_infinity-expr" defaultOpen>
    Alias for `ISINFINITY`
  </Accordion>

  <Accordion title="ISNAN(expr)" id="isnan-expr" defaultOpen>
    Returns `1` (true) if `expr` is not a number by IEEE standard; otherwise, returns
    `0` (false)
  </Accordion>

  <Accordion title="IS_NAN(expr)" id="is_nan-expr" defaultOpen>
    Alias for `ISNAN`
  </Accordion>

  <Accordion title="ISNUMERIC(expr)" id="isnumeric-expr" defaultOpen>
    Returns `1` (true) if `expr` is a number by IEEE standard; otherwise, returns
    `0` (false)
  </Accordion>

  <Accordion title="IS_NUMERIC(expr)" id="is_numeric-expr" defaultOpen>
    Alias for `ISNUMERIC`
  </Accordion>

  <Accordion title="LDEXP(x, exp)" id="ldexp-x-exp" defaultOpen>
    Returns the value of `x` \* 2<sup>exp</sup> as a *double*
  </Accordion>

  <Accordion title="LDEXPF(x, exp)" id="ldexpf-x-exp" defaultOpen>
    Returns the value of `x` \* 2<sup>exp</sup> as a *float*
  </Accordion>

  <Accordion title="LESSER(expr_a, expr_b)" id="lesser-expr_a-expr_b" defaultOpen>
    Returns whichever of `expr_a` and `expr_b` has the smaller value, based on typed
    comparison
  </Accordion>

  <Accordion title="LN(expr)" id="ln-expr" defaultOpen>
    Returns the natural logarithm of `expr` as a *double*
  </Accordion>

  <Accordion title="LNF(expr)" id="lnf-expr" defaultOpen>
    Returns the natural logarithm of `expr` as a *float*
  </Accordion>

  <Accordion title="LOG(expr)" id="log-expr" defaultOpen>
    Alias for `LN`
  </Accordion>

  <Accordion title="LOG10(expr)" id="log10-expr" defaultOpen>
    Returns the *base-10* logarithm of `expr` as a *double*
  </Accordion>

  <Accordion title="LOG10F(expr)" id="log10f-expr" defaultOpen>
    Returns the *base-10* logarithm of `expr` as a *float*
  </Accordion>

  <Accordion title="LOG1P(expr)" id="log1p-expr" defaultOpen>
    Returns the natural logarithm of one plus `expr` as a *double*
  </Accordion>

  <Accordion title="LOG1PF(expr)" id="log1pf-expr" defaultOpen>
    Returns the natural logarithm of one plus `expr` as a *float*
  </Accordion>

  <Accordion title="LOG2(expr)" id="log2-expr" defaultOpen>
    Returns the binary (*base-2*) logarithm of `expr` as a *double*
  </Accordion>

  <Accordion title="LOG2F(expr)" id="log2f-expr" defaultOpen>
    Returns the binary (*base-2*) logarithm of `expr` as a *float*
  </Accordion>

  <Accordion title="LOGF(expr)" id="logf-expr" defaultOpen>
    Alias for `LNF`
  </Accordion>

  <Accordion title="MAX_CONSECUTIVE_BITS(expr)" id="max_consecutive_bits-expr" defaultOpen>
    Calculates the length of the longest series of consecutive `1` bits in the integer
    `expr`
  </Accordion>

  <Accordion title="MOD(dividend, divisor)" id="mod-dividend-divisor" defaultOpen>
    Calculates the remainder after integer division of `dividend` by `divisor`
  </Accordion>

  <Accordion title="PI()" id="pi" defaultOpen>
    Returns the value of *pi*
  </Accordion>

  <Accordion title="POW(base, exponent)" id="pow-base-exponent" defaultOpen>
    Alias for `POWER`
  </Accordion>

  <Accordion title="POWF(base, exponent)" id="powf-base-exponent" defaultOpen>
    Alias for `POWERF`
  </Accordion>

  <Accordion title="POWER(base, exponent)" id="power-base-exponent" defaultOpen>
    Returns `base` raised to the power of `exponent` as a *double*
  </Accordion>

  <Accordion title="POWERF(base, exponent)" id="powerf-base-exponent" defaultOpen>
    Returns `base` raised to the power of `exponent` as a *float*
  </Accordion>

  <Accordion title="RADIANS(expr)" id="radians-expr" defaultOpen>
    Returns the conversion of `expr` (in degrees) to radians as a *double*
  </Accordion>

  <Accordion title="RADIANSF(expr)" id="radiansf-expr" defaultOpen>
    Returns the conversion of `expr` (in degrees) to radians as a *float*
  </Accordion>

  <Accordion title="RAND([seed])" id="rand-seed" defaultOpen>
    Returns a random floating-point value, with an optional `seed`
  </Accordion>

  <Accordion title="REGR_VALX(y, x)" id="regr_valx-y-x" defaultOpen>
    Returns NULL if `y` is NULL; otherwise, returns `x`
  </Accordion>

  <Accordion title="REGR_VALY(y, x)" id="regr_valy-y-x" defaultOpen>
    Returns NULL if `x` is NULL; otherwise, returns `y`
  </Accordion>

  <Accordion title="ROUND(expr[, scale])" id="round-expr-scale" defaultOpen>
    Rounds `expr` to the nearest decimal number with `scale`
    decimal places when `scale` is a positive number; rounds to
    the nearest number such that the result has `-(scale)` zeros
    to the left of the decimal point when `scale` is negative; use
    `scale` of `0` to round to the nearest integer.

    The default value of `scale` is `0`.

    Examples:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Function Call</th>
            <th>Result</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>ROUND(12345.678)</code></td>
            <td><code>12346</code></td>
          </tr>

          <tr>
            <td><code>ROUND(12345.678, 2)</code></td>
            <td><code>12345.68</code></td>
          </tr>

          <tr>
            <td><code>ROUND(12345.678, 0)</code></td>
            <td><code>12346</code></td>
          </tr>

          <tr>
            <td><code>ROUND(12345.678, -2)</code></td>
            <td><code>12300</code></td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="SIGN(expr)" id="sign-expr" defaultOpen>
    Determines whether a number is positive, negative, or zero;
    returns one of the following three values:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Expression Value</th>
            <th>Result</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td>*positive*</td>
            <td><code>1</code></td>
          </tr>

          <tr>
            <td>*zero*</td>
            <td><code>0</code></td>
          </tr>

          <tr>
            <td>*negative*</td>
            <td><code>-1</code></td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="SIN(expr)" id="sin-expr" defaultOpen>
    Returns the sine of `expr` as a *double*
  </Accordion>

  <Accordion title="SINF(expr)" id="sinf-expr" defaultOpen>
    Returns the sine of `expr` as a *float*
  </Accordion>

  <Accordion title="SINH(expr)" id="sinh-expr" defaultOpen>
    Returns the hyperbolic sine of `expr` as a *double*
  </Accordion>

  <Accordion title="SINHF(expr)" id="sinhf-expr" defaultOpen>
    Returns the hyperbolic sine of `expr` as a *float*
  </Accordion>

  <Accordion title="SQRT(expr)" id="sqrt-expr" defaultOpen>
    Returns the square root of `expr` as a *double*
  </Accordion>

  <Accordion title="SQRTF(expr)" id="sqrtf-expr" defaultOpen>
    Returns the square root of `expr` as a *float*
  </Accordion>

  <Accordion title="TAN(expr)" id="tan-expr" defaultOpen>
    Returns the tangent of `expr` as a *double*
  </Accordion>

  <Accordion title="TANF(expr)" id="tanf-expr" defaultOpen>
    Returns the tangent of `expr` as a *float*
  </Accordion>

  <Accordion title="TANH(expr)" id="tanh-expr" defaultOpen>
    Returns the hyperbolic tangent of `expr` as a *double*
  </Accordion>

  <Accordion title="TANHF(expr)" id="tanhf-expr" defaultOpen>
    Returns the hyperbolic tangent of `expr` as a *float*
  </Accordion>

  <Accordion title="TRUNCATE(expr[, scale])" id="truncate-expr-scale" defaultOpen>
    Rounds `expr` down to the nearest decimal number with
    `scale` decimal places when `scale` is a positive number;
    rounds down to the nearest number such that the result has
    `-(scale)` zeros to the left of the decimal point when
    `scale` is negative; use `scale` of `0` to round down to
    the nearest integer.

    The default value of `scale` is `0`.

    Examples:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Function Call</th>
            <th>Result</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>TRUNCATE(12345.678)</code></td>
            <td><code>12345</code></td>
          </tr>

          <tr>
            <td><code>TRUNCATE(12345.678, 2)</code></td>
            <td><code>12345.67</code></td>
          </tr>

          <tr>
            <td><code>TRUNCATE(12345.678, 0)</code></td>
            <td><code>12345</code></td>
          </tr>

          <tr>
            <td><code>TRUNCATE(12345.678, -2)</code></td>
            <td><code>12300</code></td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="WIDTH_BUCKET(expr, min, max, count)" id="width_bucket-expr-min-max-count" defaultOpen>
    Defines a set of `count` equal intervals (buckets) within the range of `min` &
    `max`, and puts the value of `expr` into one of those buckets, where the value is
    greater than or equal to the minimum value of the bucket and less than the maximum
    value of the bucket.  Returns the 1-based number of the bucket into which the value
    of `expr` fell.  For values smaller than `min`, `0` is returned; for values
    greater than or equal to `max`, `count + 1` is returned.  Examples:

    In the following examples, a set of *5* equal buckets are defined between *0* and
    *10* (*0-2*, *2-4*, *4-6*, *6-8*, & *8-10*), and various values are bucketed using
    that set.

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Function Call</th>
            <th>Result</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>WIDTH\_BUCKET(-1, 0, 10, 5)</code></td>
            <td><code>0</code></td>
          </tr>

          <tr>
            <td><code>WIDTH\_BUCKET(0, 0, 10, 5)</code></td>
            <td><code>1</code></td>
          </tr>

          <tr>
            <td><code>WIDTH\_BUCKET(5, 0, 10, 5)</code></td>
            <td><code>3</code></td>
          </tr>

          <tr>
            <td><code>WIDTH\_BUCKET(10, 0, 10, 5)</code></td>
            <td><code>6</code></td>
          </tr>

          <tr>
            <td><code>WIDTH\_BUCKET(11, 0, 10, 5)</code></td>
            <td><code>6</code></td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>
</AccordionGroup>
