# Math Calculator API

> Math Calculator performs mathematical operations including arithmetic, number properties, base conversions, and expression evaluation. Decimal results are rounded to 15 significant digits, as a calculator shows them, so 0.1 + 0.2 returns 0.3.

**Endpoint:** `POST https://api.apiverve.com/v1/math`  
**Category:** Data Conversion  
**Cost:** 1 credit per call  
**Canonical page:** https://apiverve.com/marketplace/math

## Overview

All operations return structured responses with input values and results. Handles edge cases like division by zero and number limits.

## Authentication

Every call carries your key in an `x-api-key` header. The same key works across the whole
APIVerve catalog — there are no per-API subscriptions. Responses always use the same three
top-level keys: `status`, `error`, and `data`.

## Example request

```bash
curl -X POST "https://api.apiverve.com/v1/math" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"operation":"add","a":10,"b":5}'
```

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `operation` | string | Yes | Operation to perform. One of: add, subtract, multiply, divide, power, modulo |
| `a` | number | Yes | First number |
| `b` | number | Yes | Second number |

## Response fields

- `result` — number · Result of the operation
- `operation` — string · Operation performed
- `input` — object
  - `input.a` — number · First input number (not present for power, which echoes base/exponent instead)
  - `input.b` — number · Second input number (not present for power, which echoes base/exponent instead)
- `steps` — array

## Sample response

```json
{
  "status": "ok",
  "error": null,
  "data": {
    "result": 15,
    "operation": "add",
    "input": {
      "a": 10,
      "b": 5
    },
    "steps": [
      "10 + 5 = 15"
    ]
  }
}
```

## Use cases

- **Number Analysis** — Check if numbers are prime, get prime factorization, or compute GCD/LCM
- **Base Conversion** — Convert between decimal, binary, hexadecimal, and octal number systems
- **Math Operations** — Perform calculations with detailed results for application integration
- **Expression Evaluation** — Evaluate mathematical expressions safely on the server side

## SDKs

- **npm** — `npm install @apiverve/math` (https://www.npmjs.com/package/@apiverve/math)
- **NuGet** — `dotnet add package APIVerve.API.MathCalculator` (https://www.nuget.org/packages/APIVerve.API.MathCalculator)
- **Source** — https://github.com/apiverve/math-api

## More

- Full reference: https://docs.apiverve.com/ref/math
- Get an API key: https://dashboard.apiverve.com
- Full catalog: https://apiverve.com/marketplace
