Calculates the base-2 logarithm of any positive number with mathematical precision. Access via MCP in AI coding assistants like Cursor or Windsurf, or call GET /v1/math/log2 directly. Essential for bit manipulation, algorithm complexity analysis, and binary calculations. Returns exact floating-point results where spreadsheet functions might introduce rounding errors.
curl "https://tinyfn.io/v1/math/log2" \
-H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/math/log2', {
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/log2',
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"
}
}
}
}
Use the log2 MCP tool available in Cursor, Windsurf, Claude Code, and other supported editors. It provides mathematically precise base-2 logarithm calculations for any positive input.
The function returns an error for zero and negative inputs since log₂(x) is only defined for positive real numbers. Always validate your input is greater than zero.
TinyFn's log2 ensures consistent results across different programming environments and eliminates floating-point precision variations that can occur with language-specific implementations.
Log2 uses base 2 (log₂(8) = 3), while natural log uses base e (ln(8) ≈ 2.08). Log2 is essential for computer science applications like binary tree depth and bit operations.
Yes, log2 is perfect for analyzing divide-and-conquer algorithms. For example, log₂(1000000) ≈ 19.93 tells you a binary search needs about 20 steps maximum.