Finds the closest power of any base to a target number. Access via MCP in Cursor or Windsurf, or REST at `/v1/number/nearest-power`. Given target 100 and base 2, returns 2^7=128 (closest to 100). Essential for algorithms needing power-of-two sizing, exponential approximations, or logarithmic scaling in AI applications.
curl "https://tinyfn.io/v1/number/nearest-power" \
-H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/number/nearest-power', {
headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests
response = requests.get('https://tinyfn.io/v1/number/nearest-power',
headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)
Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's number tools:
{
"mcpServers": {
"tinyfn-number": {
"url": "https://tinyfn.io/mcp/number",
"headers": {
"X-API-Key": "YOUR_API_KEY"
}
}
}
}
Call with your target number and base=2. For target 100, it returns 2^7=128 since 128 is closer to 100 than 2^6=64.
Yes, any positive base works. Base 10 finds nearest powers of 10, base 3 finds powers of 3, etc.
If your target is already a perfect power (like 64 for base 2), it returns that exact power with zero distance.
AI agents in Cline or Claude Code can call this to find optimal power-of-2 buffer sizes, ensuring efficient memory allocation in generated code.
Works with any real target number. For negatives, it finds the nearest power by absolute distance, handling edge cases deterministically.
Get your free API key and start using Nearest Power in seconds.
Get Free API Key