mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
a791069abd
Added complete call-seq documentation for all 17 public methods in the CMath module, improving documentation coverage from 0% to 100%. Documentation includes: - Method signatures with parameter and return types - Clear descriptions of mathematical operations - Branch cut information for complex functions - Practical examples showing real and complex number usage - Consistent formatting following mruby documentation standards Methods documented: - Exponential and logarithmic: exp, log, log2, log10, sqrt - Trigonometric: sin, cos, tan, asin, acos, atan - Hyperbolic: sinh, cosh, tanh, asinh, acosh, atanh This significantly improves maintainability and usability of the complex math functionality for developers working with mathematical computations in embedded Ruby environments. Co-authored-by: Atlassian Rovo Dev
mruby-cmath
This mrbgem provides complex number support for mruby, offering mathematical functions that can handle complex numbers, similar to Ruby's standard cmath library.
Requirements
This gem utilizes C99 _Complex features. Therefore, you will need a C compiler that supports C99 or a later version to build and use this gem.
Provided Functions
The CMath module includes the following mathematical functions:
exp(z): Computes the exponential ofz.log(z): Computes the natural logarithm ofz.log(z, b): Computes the logarithm ofzwith baseb.log2(z): Computes the base-2 logarithm ofz.log10(z): Computes the base-10 logarithm ofz.sqrt(z): Computes the square root ofz.sin(z): Computes the sine ofz.cos(z): Computes the cosine ofz.tan(z): Computes the tangent ofz.asin(z): Computes the arc sine ofz.acos(z): Computes the arc cosine ofz.atan(z): Computes the arc tangent ofz.sinh(z): Computes the hyperbolic sine ofz.cosh(z): Computes the hyperbolic cosine ofz.tanh(z): Computes the hyperbolic tangent ofz.asinh(z): Computes the inverse hyperbolic sine ofz.acosh(z): Computes the inverse hyperbolic cosine ofz.atanh(z): Computes the inverse hyperbolic tangent ofz.
Usage Example
Here's a simple example of how to use CMath to calculate the square root of a negative number:
# Assuming mruby is built with mruby-cmath
# Calculate the square root of -4
result = CMath.sqrt(-4)
# result will be a Complex number (0+2i)
puts result.real # Output: 0.0
puts result.imaginary # Output: 2.0