Math Utilities

Modulo

Computes modulo operation (a mod b) returning the remainder when dividing two numbers. Access via MCP in Cursor or Windsurf for AI-powered calculations, or call GET /v1/math/modulo directly. Essential for cyclic algorithms, hash functions, and range wrapping. Handles negative numbers using mathematical modulo definition, not programming remainder.

API Endpoint

GET /v1/math/modulo

Code Examples

curl "https://tinyfn.io/v1/math/modulo" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/math/modulo', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/math/modulo',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's math tools:

{
  "mcpServers": {
    "tinyfn-math": {
      "url": "https://tinyfn.io/mcp/math",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

What's the difference between modulo and remainder operations?

Modulo uses mathematical definition where result has same sign as divisor, while remainder (like % in many languages) can be negative. For positive numbers, they're identical.

How do I use modulo in MCP-enabled editors like Cursor?

Call the modulo tool with dividend and divisor parameters. The AI agent gets exact computation instead of potentially incorrect mental math.

What happens with modulo by zero or negative divisors?

Division by zero returns an error. Negative divisors work correctly using mathematical modulo definition, ensuring positive results.

Can I use this for array index wrapping and cyclic calculations?

Yes, perfect for circular arrays, angle normalization, and hash table indexing. Use (index + offset) mod array_length for safe wrapping.

What data types does the modulo endpoint accept?

Accepts integers and floating-point numbers. Returns precise decimal results for non-integer inputs, maintaining full mathematical accuracy.

Try Modulo Now

Get your free API key and start using Modulo in seconds.

Get Free API Key