Calculator API
This API provides a high-precision mathematical calculator. It allows for complex expression evaluationI, useful for bots, apps or other applications needing safe math parsing.
Supported Operations
Section titled “Supported Operations”- Arithmetic:
+,-,*,/,^ - Functions:
sqrt(),sin(),cos(),log() - Unit conversion:
5 cm to inch
Endpoint
Section titled “Endpoint” POST
/api/v1/calc Request Parameters
Section titled “Request Parameters”The following parameters are accepted in the request body:
| Field | Type | Required | Description |
|---|---|---|---|
expr | string | Yes | The mathematical expression to evaluate. |
Request Examples
Section titled “Request Examples”curl -X POST https://heavstal.com.ng/api/v1/calc \-H "Content-Type: application/json" \-H "x-api-key: <YOUR_API_KEY>" \-d '{"expr": "sqrt(16) + 5^2"}'const response = await fetch('https://heavstal.com.ng/api/v1/calc', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': '<YOUR_API_KEY>' }, body: JSON.stringify({ expr: "sqrt(16) + 5^2" })});
const res = await response.json();console.log(res.data.result);import { tools } from '@heavstal/api';
const math = await tools.calc("sqrt(16) + 5^2");console.log(`Result: ${math.data.result}`); // Outputs "29"import requests
url = "https://heavstal.com.ng/api/v1/calc"headers = { "Content-Type": "application/json", "x-api-key": "<YOUR_API_KEY>"}payload = { "expr": "sqrt(16) + 5^2"}
response = requests.post(url, headers=headers, json=payload)print(response.json()["data"]["result"])Response Examples
Section titled “Response Examples”{ "status": "success", "creator": "HEAVSTAL TECH", "data": { "expression": "sqrt(16) + 5^2", "result": "29" }}{ "status": "error", "error": "Invalid mathematical expression."}