Math Utilities

Is Prime

Determines whether a number is prime using efficient mathematical algorithms. Available via MCP in Cursor and other AI editors at `/v1/math/is-prime`, or as a REST API. Returns boolean true/false with reasoning. Handles edge cases like negative numbers and supports integers up to JavaScript's safe limit (2^53-1).

API Endpoint

GET /v1/math/is-prime

Code Examples

curl "https://tinyfn.io/v1/math/is-prime" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/math/is-prime', {
  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/is-prime',
    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 largest number I can check for primality?

Up to JavaScript's MAX_SAFE_INTEGER (9,007,199,254,740,991). Beyond this, precision issues may occur.

How does the prime checking algorithm work?

Uses trial division with optimizations: checks divisibility up to √n, skips even numbers after 2, and handles common edge cases efficiently.

Can MCP agents use this for cryptographic key validation?

Yes, but only for educational purposes. For production cryptography, use specialized libraries with proper random prime generation and security audits.

What happens with negative numbers or zero?

Returns false. By mathematical definition, prime numbers are positive integers greater than 1.

Does it return just true/false or additional information?

Returns boolean result plus reasoning (e.g., 'divisible by 3' for composite numbers, 'definition: primes > 1' for edge cases).

Try Is Prime Now

Get your free API key and start using Is Prime in seconds.

Get Free API Key