๐ Calco: A Ready-to-Use Math Library for Python, Powered by C
If youโre looking for a math library that provides a wide range of ready-to-use functions โ and operates at speeds comparable to Pythonโs built-in math
module โ then Calco may be a suitable choice.
๐ What is Calco?
Calco is a cross-platform math library written in C and exposed as a native Python extension. It covers over 60 mathematical functions across arithmetic, trigonometry, logarithms, special functions, and more โ offering a more complete set of tools than Python's standard modules.
Calco is designed for developers who want compact, native-speed utilities without the need to write or interface with C manually.
โ๏ธ Key Features
- โก C-level performance
-
๐งฎ 60+ built-in math functions, including:
- Arithmetic:
add
,subtract
,divide
,power
, etc. - Trigonometric:
sine
,cosine
,arctangent2
, etc. - Logarithmic and exponential functions
- Hyperbolic and inverse hyperbolic functions
- Special functions:
gamma
,erf
,fma
, etc. - Rounding, flooring, truncation, etc.
- Arithmetic:
๐งฉ Cross-platform support: Windows, Linux, macOS
๐ฆ Lightweight
.pyd
/.so
package for direct Python import
๐ฆ Installation
You can install calco directly using pip:
pip install calco
Or visit the official website for full installation instructions and downloadable builds:
๐ https://calcolib.netlify.app/
๐งช Example Usage
import calco
# Arithmetic
print(calco.add(3.0, 4.5)) # 7.5
print(calco.divide(10.0, 3.0)) # ~3.333...
# Trigonometry
print(calco.sine(1.57)) # โ sin(90ยฐ)
print(calco.arctangent2(2.0, 3.0)) # atan2(y, x)
# Logarithmic
print(calco.log_base10(1000)) # 3.0
# Special functions
print(calco.gamma_function(0.5)) # โ sqrt(pi)
print(calco.fused_multiply_add(2, 3, 4)) # (2ร3)+4 = 10
๐ Available Functions (by Category)
Category | Functions |
---|---|
Arithmetic |
add , subtract , multiply , divide , power , square_root , cube_root , absolute_value , float_modulo , positive_difference , copy_sign_double , fused_multiply_add
|
Rounding |
floor_val , ceil_val , round_val , nearbyint_val , truncate_val
|
Trigonometric |
sine , cosine , tangent , arcsine , arccosine , arctangent , arctangent2
|
Hyperbolic |
hyperbolic_sine , hyperbolic_cosine , hyperbolic_tangent , inverse_hyperbolic_sine , inverse_hyperbolic_cosine , inverse_hyperbolic_tangent
|
Logarithmic |
natural_log , log_base10 , log_base2 , log_custom_base
|
Exponential |
exponential , exponential_base2 , exponential_minus_1
|
Special |
gamma_function , log_gamma_function , error_function , complementary_error_function , next_after_double
|
Constants |
get_pi , get_e
|
Converters |
degrees_to_radians , radians_to_degrees
|
Checks |
is_nan , is_infinity
|
๐ป Platform Support
OS | Architectures |
---|---|
Windows | x86 / x64 |
Linux | x86_64, ARM |
macOS | Intel, Apple Silicon (ARM64) |
๐ License
MIT License โ free to use in personal, academic, or commercial projects.
Created by gafoo.
ยฉ 2025 Calco.
๐ Resources
- ๐ Website: https://calcolib.netlify.app
- ๐งโ๐ป GitHub: https://github.com/gafoo173/calco
๐ Behind the Scenes
To use Calco, function calls in Python pass through an additional API layer before reaching the C core.
In contrast, Python's built-in math
functions are executed directly at the C level with no API overhead.
Despite this extra layer, Calco delivers nearly identical performance to the math
module, and in some cases, it performs slightly faster or marginally slower depending on the specific function and platform.
Diagram: Function call path for Calco
Python Code
|
v
[ Python Wrapper ]
|
v
[ Calco API Layer ]
|
v
[ Native C Function ]
Diagram: Function call path for math
Python Code
|
v
[ Built-in math (direct C call) ]
Top comments (0)