DEV Community

gafoo
gafoo

Posted on • Edited on

Calco: Lightweight, High-Speed Mathematical Library for Python

๐Ÿš€ 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.
  • ๐Ÿงฉ 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“š 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


๐ŸŒŽ 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 ]
Enter fullscreen mode Exit fullscreen mode

Diagram: Function call path for math

Python Code
   |
   v
[ Built-in math (direct C call) ]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)