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

Like many functions in DataPrime, sqrt supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

sqrt(number: number): number
number: number.sqrt(): number

Arguments

NameTypeRequiredDescription
numbernumbertrueThe 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)
create ror from ((sold_at_price / bought_at_price).sqrt() - 1)

This will result in the following document:

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