Skip to content

sqrt - Compute the square root of a value

sqrt is a fundamental function in mathematics. It calculates the square root of a given value.

NOTE: It is the inverse of power(number, 2)

Syntax

sqrt(number: number): number

Arguments

Name Type Required Description
number number true The number whose square root we seek

Example - Computing "Rate of Return" over 2 years

Consider the following document:

{
    "buyer": "Chris",
    "asset": "DataDog",
    "bought_at_price": 100,
    "sold_at_price": 10
}

The above document represents a trade that occurred in a financial service. We can use the sqrt function to aid us in computing the rate of return:

create ror from (sqrt(sold_at_price / bought_at_price) - 1)

This will result in the following document:

{
    "buyer": "Chris",
    "asset": "DataDog"
    "bought_at_price": 100,
    "sold_at_price": 10,
    "ror": -0.683772233983162
}