Math Utilities

Average

Calculate the arithmetic mean of any list of numbers via GET /v1/math/average or MCP integration. Pass numbers as comma-separated values or array — returns precise decimal result. Essential for data analysis in Claude Code and Cursor workflows where statistical calculations need deterministic accuracy over AI approximations.

API Endpoint

GET /v1/math/average

Code Examples

curl "https://tinyfn.io/v1/math/average" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/math/average', {
  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/average',
    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

How do I calculate average of numbers using TinyFn?

Send GET request to /v1/math/average with numbers parameter as comma-separated values (e.g., ?numbers=10,20,30) or use the MCP tool in supported editors.

What happens when I pass an empty list to the average function?

Empty arrays return an error since mathematical average is undefined for zero elements. Always validate your dataset has at least one number.

Does TinyFn average handle decimal precision correctly?

Yes, returns exact decimal results without floating-point errors. For example, average of 0.1, 0.2, 0.3 returns 0.2 precisely, not 0.19999999.

Can I use average calculation in MCP-enabled AI coding assistants?

Absolutely. Cursor, Windsurf, and Claude Code can invoke this tool directly for statistical analysis, avoiding hallucinated math in data processing scripts.

How does TinyFn average compare to built-in language functions?

Provides consistent results across platforms and eliminates the need to import math libraries. Especially useful for quick calculations in AI agent workflows.

Try Average Now

Get your free API key and start using Average in seconds.

Get Free API Key