Constrains numeric values within specified minimum and maximum bounds via GET /v1/math/clamp. Essential for input validation, UI range controls, and data normalization. If value < min, returns min; if value > max, returns max; otherwise returns the original value unchanged.
curl "https://tinyfn.io/v1/math/clamp" \
-H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/math/clamp', {
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/clamp',
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"
}
}
}
}
Returns the original value if it's within bounds, min if below minimum, max if above maximum. Handles negative numbers, decimals, and zero correctly.
Yes, works with any numeric type including floats. Clamping 3.7 between 1.0 and 3.5 returns 3.5.
Behavior depends on implementation but typically returns one of the bounds. Always ensure min ≤ max for predictable results.
AI agents can clamp user inputs in real-time, ensuring values stay within valid ranges for sliders, numeric inputs, or configuration parameters.
Essentially yes - clamp(value, min, max) equals Math.min(Math.max(value, min), max), but as a single deterministic operation.