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).
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)
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"
}
}
}
}
Up to JavaScript's MAX_SAFE_INTEGER (9,007,199,254,740,991). Beyond this, precision issues may occur.
Uses trial division with optimizations: checks divisibility up to √n, skips even numbers after 2, and handles common edge cases efficiently.
Yes, but only for educational purposes. For production cryptography, use specialized libraries with proper random prime generation and security audits.
Returns false. By mathematical definition, prime numbers are positive integers greater than 1.
Returns boolean result plus reasoning (e.g., 'divisible by 3' for composite numbers, 'definition: primes > 1' for edge cases).