MathAPI is a simple Flask-based API that provides various mathematical functions, constants, unit conversions, and basic arithmetic operations.
GET /- Returns a welcome message and a list of available endpoints.
-
GET /math/<function>?v=number- Computes mathematical functions.
- Supported functions:
sin,cos,tan(for angles in degrees)sqrt,log,log10factorial,ceil,floor
- Example:
/math/sin?v=30
-
GET /math/radians/<function>?v=number- Computes trigonometric functions with input in radians.
- Supported functions:
sin,cos,tan
- Example:
/math/radians/sin?v=0.5235987756
-
GET /math/exp?base=number&exponent=number- Computes exponentiation.
- Example:
/math/exp?base=2&exponent=3
-
GET /math/mod?num1=number&num2=number- Computes modulus.
- Example:
/math/mod?num1=10&num2=3
-
GET /math/is_prime?n=number- Checks if a number is prime.
- Example:
/math/is_prime?n=7
-
GET /math/fibonacci?n=number- Generates Fibonacci sequence up to n numbers.
- Example:
/math/fibonacci?n=10
GET /constants- Retrieves important mathematical constants.
- Returns:
pi(π)e(Euler's number)golden_ratiosilver_ratioplanck_constantavogadro_numberspeed_of_lightgravitational_constantboltzmann_constantgas_constantelementary_charge
POST /convert- Converts between units.
- Currently supports:
- Celsius ↔ Fahrenheit
- Celsius ↔ Kelvin
- Meters ↔ Kilometers
- Meters ↔ Centimeters
- Inches ↔ Centimeters
- Feet ↔ Meters
- Yards ↔ Meters
- Miles ↔ Kilometers
- Kilograms ↔ Pounds
- Example:
{ "v": 100, "from": "c", "to": "f" }
POST /calculate- Performs basic arithmetic operations.
- Requires JSON input with
num1,num2, andoperation. - Supported operations:
add,subtract,multiply,divide
- Example:
{ "num1": 10, "num2": 5, "operation": "add" }
- Install the required dependencies:
pip install flask- Run the Flask application:
python main.py- Access the API at
http://127.0.0.1:5000/
