Skip to content

sqrt

Description

Returns the square root of a number.

Note

This 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 value to compute the square root of

Example

Use case: Compute rate of return over 2 years

Calculate the rate of return for an asset purchase and sale by taking the square root of the price ratio and subtracting 1.

{
    "buyer": "Chris",
    "asset": "DataDog",
    "bought_at_price": 100,
    "sold_at_price": 10
}
create ror from (sqrt(sold_at_price / bought_at_price) - 1)
create ror from ((sold_at_price / bought_at_price).sqrt() - 1)

Output

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