Skip to main content

Math Utilities

Explore the math utility steps in Torq.

Updated over 2 weeks ago

Use the math utility step to perform calculations in Torq.

Solve Equation

Solves an equation containing mathematical operators. Use the Round parameter to round off to an integer.

Sprig functions also allow you to perform simple integer-based calculations inline.

Input

A mathematical equation that can include multiple inputs from other steps.

1 + 1 + {{$.given_number.int}}

Output

4

Calculate the geodistance between 2 IP addresses

Calculates the distance between 2 IP addresses based on geodata from freegeoip.app.

Input

Source IP: 128.118.26.2
Destination IP: 17.253.20.125

Output

 {
"distance": 197.70390615702496,
"ip_destination": {
"ip": "17.253.20.125",
"location": [
39.03947448730469,
-77.49180603027344
]
},
"ip_source": {
"ip": "128.118.26.2",
"location": [
40.7968864440918,
-77.86371612548828
]
},
"measurement": "km",
"step_status": {
"code": 1,
"message": "",
"verbose": ""
}
}

Get the Levenshtein distance between a value and an array

Measures how similar a single value is to each value in an array of strings.

It measures the minimum number of single-character edits required to change one string into another. This is a commonly used method for detecting typo squatting.

Input

String to check: smapledomain.org
Array to compare:
[
"sampledomain.org",
"gooddomain.org",
"sampledomain.com",
"gooddomain.com"
]

Output

{
"output": [
{
"distance": 2,
"domain": "sampledomain.org"
},
{
"distance": 6,
"domain": "gooddomain.org"
},
{
"distance": 5,
"domain": "sampledomain.com"
},
{
"distance": 9,
"domain": "gooddomain.com"
}
],
"step_status": {
"code": 1,
"message": "",
"verbose": ""
}
}

Percentile Calculator

Returns the k-th percentile of the values in the given range. This is the value below which a given percentage of the input numbers fall.

Input

Array of numbers:
[
1,
2,
3,
4
]

K:
95

Output

{
"output": 3.8499999999999996,
"step_status": {
"code": 1,
"message": "",
"verbose": ""
}
}

Did this answer your question?