Math Utilities

Cos

Calculate the cosine of an angle using GET /v1/math/cos. Returns precise floating-point results for angles in radians. Example: cos(π/3) = 0.5. Essential for trigonometric calculations in AI agents working with geometry, physics simulations, or signal processing via MCP in Cursor and other editors.

API Endpoint

GET /v1/math/cos

Code Examples

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

What input format does the cosine function expect?

The function expects angles in radians. For degrees, convert first: radians = degrees × π/180.

How can MCP agents use cosine calculations in coding workflows?

AI agents can generate trigonometric calculations for game development, 3D graphics, wave functions, or geometric transformations directly in your editor without approximation errors.

What's the precision and range of the cosine output?

Returns standard IEEE 754 double-precision floating-point values. Output range is always [-1, 1] for any finite input angle.

Does the cosine function handle special values like infinity or NaN?

Yes, follows IEEE 754 standards. cos(±∞) returns NaN, cos(NaN) returns NaN, maintaining mathematical consistency.

How does this compare to built-in math.cos() in programming languages?

Provides identical IEEE 754 compliance but accessible via REST API and MCP, enabling consistent results across different environments and AI agent integrations.

Try Cos Now

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

Get Free API Key