Skip to content
ToolsOnDuty - free online tools
ToolsOnDuty / docs
Browse documentation

Reference / Math

Math API

20 endpoints for math workflows. Every call requires bearer authentication and uses the standard ToolsOnDuty response envelope.

Try it

Runs a real request from your browser to your own ToolsOnDuty account. Your key is only kept in this page and is never stored.

POST/v1/math/evaluate1 credit / call

Expression evaluator

Safely evaluate a calculator expression (supports sin/cos/tan, sqrt, ln, log, exp, ^, %, !).

ParameterTypeRequiredDescription
expressionstringYesExpression to evaluate, e.g. "sqrt(16)+2^3".
angleModestringNodeg | rad. Default: deg.

Request

curl -X POST https://toolsonduty.com/api/v1/math/evaluate \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"expression":"sqrt(16)+2^3"}'

Response

{
  "ok": true,
  "data": {
    "result": 12
  }
}
POST/v1/math/average1 credit / call

Average / mean

Compute count, sum, mean, median, minimum and maximum for a list of numbers.

ParameterTypeRequiredDescription
valuesstringYesArray of numbers, e.g. [1,2,3].

Request

curl -X POST https://toolsonduty.com/api/v1/math/average \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"values":[1,2,3,4]}'

Response

{
  "ok": true,
  "data": {
    "count": 4,
    "sum": 10,
    "mean": 2.5,
    "median": 2.5,
    "minimum": 1,
    "maximum": 4
  }
}
POST/v1/math/percentage1 credit / call

Percentage calculations

Compute a percentage of a value, a part-of-whole ratio, or percentage change between two values.

ParameterTypeRequiredDescription
modestringYesof | ratio | change.
anumberYesmode=of: percentage; mode=ratio: part; mode=change: original value.
bnumberYesmode=of: value; mode=ratio: whole; mode=change: updated value.

Request

curl -X POST https://toolsonduty.com/api/v1/math/percentage \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"mode":"of","a":20,"b":150}'

Response

{
  "ok": true,
  "data": {
    "result": 30
  }
}
POST/v1/math/fraction1 credit / call

Fraction arithmetic

Add, subtract, multiply or divide two fractions and simplify the result.

ParameterTypeRequiredDescription
firstNumeratornumberYesNumerator of the first fraction.
firstDenominatornumberYesDenominator of the first fraction.
secondNumeratornumberYesNumerator of the second fraction.
secondDenominatornumberYesDenominator of the second fraction.
operatorstringYes+ | - | * | /.

Request

curl -X POST https://toolsonduty.com/api/v1/math/fraction \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"firstNumerator":1,"firstDenominator":2,"secondNumerator":1,"secondDenominator":3,"operator":"+"}'

Response

{
  "ok": true,
  "data": {
    "numerator": 5,
    "denominator": 6,
    "whole": 0,
    "remainder": 5,
    "decimal": 0.833
  }
}
POST/v1/math/statistics1 credit / call

Descriptive statistics

Compute mean, median, range, modes, variance and standard deviation (population and sample) for a list of numbers.

ParameterTypeRequiredDescription
valuesstringYesArray of numbers.

Request

curl -X POST https://toolsonduty.com/api/v1/math/statistics \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"values":[2,4,4,4,5,5,7,9]}'

Response

{
  "ok": true,
  "data": {
    "mean": 5,
    "populationStandardDeviation": 2
  }
}
POST/v1/math/ratio1 credit / call

Ratio simplification

Simplify a ratio of two whole numbers to lowest terms.

ParameterTypeRequiredDescription
anumberYesFirst whole number.
bnumberYesSecond whole number.

Request

curl -X POST https://toolsonduty.com/api/v1/math/ratio \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"a":8,"b":12}'

Response

{
  "ok": true,
  "data": {
    "simplified": [
      2,
      3
    ]
  }
}
POST/v1/math/quadratic1 credit / call

Quadratic equation solver

Solve ax²+bx+c=0: discriminant, real or complex roots, and vertex.

ParameterTypeRequiredDescription
anumberYesCoefficient a (must not be zero).
bnumberYesCoefficient b.
cnumberYesCoefficient c.

Request

curl -X POST https://toolsonduty.com/api/v1/math/quadratic \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"a":1,"b":-3,"c":2}'

Response

{
  "ok": true,
  "data": {
    "discriminant": 1,
    "roots": [
      "2",
      "1"
    ],
    "vertexX": 1.5,
    "vertexY": -0.25
  }
}
POST/v1/math/power1 credit / call

Exponents and roots

Raise a number to a power, or compute its nth root.

ParameterTypeRequiredDescription
modestringYespower | root.
valuenumberYesBase (mode=power) or radicand (mode=root).
nnumberYesExponent (mode=power) or root degree, >=2 (mode=root).

Request

curl -X POST https://toolsonduty.com/api/v1/math/power \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"mode":"power","value":2,"n":10}'

Response

{
  "ok": true,
  "data": {
    "result": 1024
  }
}
POST/v1/math/round1 credit / call

Configurable rounding

Round a number to a given number of decimal places using nearest, up, down or truncate.

ParameterTypeRequiredDescription
valuenumberYesValue to round.
placesnumberNoDecimal places, -10 to 10. Default: 0.
modestringNonearest | up | down | truncate. Default: nearest.

Request

curl -X POST https://toolsonduty.com/api/v1/math/round \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"value":3.14159,"places":2}'

Response

{
  "ok": true,
  "data": {
    "result": 3.14
  }
}
POST/v1/math/lcm1 credit / call

Least common multiple

Compute the least common multiple of a list of whole numbers.

ParameterTypeRequiredDescription
valuesstringYesArray of whole numbers (2+).

Request

curl -X POST https://toolsonduty.com/api/v1/math/lcm \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"values":[4,6]}'

Response

{
  "ok": true,
  "data": {
    "result": 12
  }
}
POST/v1/math/gcf1 credit / call

Greatest common factor

Compute the greatest common factor of a list of whole numbers.

ParameterTypeRequiredDescription
valuesstringYesArray of whole numbers (2+).

Request

curl -X POST https://toolsonduty.com/api/v1/math/gcf \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"values":[12,18]}'

Response

{
  "ok": true,
  "data": {
    "result": 6
  }
}
POST/v1/math/prime-factors1 credit / call

Prime factorization

Factorize a whole number (2 or more) into its prime factors with exponents.

ParameterTypeRequiredDescription
valuenumberYesWhole number, 2 or more.

Request

curl -X POST https://toolsonduty.com/api/v1/math/prime-factors \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"value":60}'

Response

{
  "ok": true,
  "data": {
    "factors": [
      {
        "prime": 2,
        "exponent": 2
      },
      {
        "prime": 3,
        "exponent": 1
      },
      {
        "prime": 5,
        "exponent": 1
      }
    ]
  }
}
POST/v1/math/random1 credit / call

Secure random integers

Generate secure random integers in an inclusive range, optionally without repeats.

ParameterTypeRequiredDescription
minimumnumberYesRange minimum.
maximumnumberYesRange maximum.
countnumberNoHow many to generate (1-1000). Default: 1.
uniquebooleanNoDisallow repeated values. Default: false.

Request

curl -X POST https://toolsonduty.com/api/v1/math/random \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"minimum":1,"maximum":100,"count":5}'

Response

{
  "ok": true,
  "data": {
    "values": [
      12,
      87,
      3,
      45,
      60
    ]
  }
}
POST/v1/math/probability1 credit / call

Probability calculations

Compute a single-event probability from favorable/total outcomes, or combine two independent probabilities with AND/OR.

ParameterTypeRequiredDescription
modestringNosingle | combine. Default: single.
favorablenumberNomode=single: favorable outcomes.
totalnumberNomode=single: total outcomes.
firstnumberNomode=combine: first probability (0-1).
secondnumberNomode=combine: second probability (0-1).
operationstringNomode=combine: and | or. Default: and.

Request

curl -X POST https://toolsonduty.com/api/v1/math/probability \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"mode":"single","favorable":1,"total":6}'

Response

{
  "ok": true,
  "data": {
    "probability": 0.1667,
    "percentage": 16.67
  }
}
POST/v1/math/combinatorics1 credit / call

Permutations and combinations

Compute nPr (permutations) and nCr (combinations) for n items choosing r.

ParameterTypeRequiredDescription
nnumberYesTotal items.
rnumberYesItems chosen (0 <= r <= n).

Request

curl -X POST https://toolsonduty.com/api/v1/math/combinatorics \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"n":5,"r":2}'

Response

{
  "ok": true,
  "data": {
    "permutations": 20,
    "combinations": 10
  }
}
POST/v1/math/pythagorean1 credit / call

Right-triangle solver

Solve for the missing side, area and perimeter of a right triangle given two known sides.

ParameterTypeRequiredDescription
firstSidenumberYesFirst known side.
secondSidenumberYesSecond known side (or hypotenuse when mode=leg).
modestringNohypotenuse | leg. Default: hypotenuse.

Request

curl -X POST https://toolsonduty.com/api/v1/math/pythagorean \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"firstSide":3,"secondSide":4}'

Response

{
  "ok": true,
  "data": {
    "missingSide": 5,
    "area": 6,
    "perimeter": 12
  }
}
POST/v1/math/logarithm1 credit / call

Logarithm calculator

Compute a custom-base logarithm along with the natural (ln) and common (log10) logarithm.

ParameterTypeRequiredDescription
argumentnumberYesValue to take the logarithm of (must be > 0).
basenumberYesLogarithm base (must be > 0 and not 1).

Request

curl -X POST https://toolsonduty.com/api/v1/math/logarithm \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"argument":8,"base":2}'

Response

{
  "ok": true,
  "data": {
    "value": 3,
    "naturalLog": 2.079,
    "commonLog": 0.903
  }
}
POST/v1/math/fibonacci1 credit / call

Fibonacci generator

Generate a bounded Fibonacci-style safe-integer sequence.

ParameterTypeRequiredDescription
countnumberYesNumber of values from 1 to 1,000.
firstnumberNoFirst integer. Default: 0.
secondnumberNoSecond integer. Default: 1.

Request

curl -X POST https://toolsonduty.com/api/v1/math/fibonacci \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"count":8}'

Response

{
  "ok": true,
  "data": {
    "values": [
      0,
      1,
      1,
      2,
      3,
      5,
      8,
      13
    ]
  }
}
POST/v1/math/truth-table1 credit / call

Truth table generator

Generate a Boolean truth table for !, &&, ||, ^ and parentheses with up to eight variables.

ParameterTypeRequiredDescription
expressionstringYesBoolean expression, e.g. (A && B) || !C.

Request

curl -X POST https://toolsonduty.com/api/v1/math/truth-table \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"expression":"A && B"}'

Response

{
  "ok": true,
  "data": {
    "expression": "A && B",
    "variables": [
      "A",
      "B"
    ],
    "rows": [
      {
        "values": {
          "A": false,
          "B": false
        },
        "result": false
      }
    ]
  }
}
POST/v1/math/roman1 credit / call

Roman numeral math

Add, subtract, multiply or divide canonical Roman numerals with results from 1 to 3999.

ParameterTypeRequiredDescription
firststringYesFirst Roman numeral.
operatorstringYes+ | - | * | /.
secondstringYesSecond Roman numeral.

Request

curl -X POST https://toolsonduty.com/api/v1/math/roman \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -d '{"first":"XIV","operator":"+","second":"IX"}'

Response

{
  "ok": true,
  "data": {
    "first": 14,
    "second": 9,
    "result": 23,
    "roman": "XXIII"
  }
}