CMath is a library that provides trigonometric and transcendental functions for complex numbers. The functions in this module accept integers, floating-point numbers or complex numbers as arguments.
Note that the selection of functions is similar, but not identical, to that in module math. The reason for having two modules is that some users aren’t interested in complex numbers, and perhaps don’t even know what they are. They would rather have Math.sqrt(-1) raise an exception than return a complex number.
To start using this library, simply require cmath library:
And after call any CMath function. For example:
CMath.sqrt(-9) #=> 0+3.0i CMath.exp(0 + 0i) #=> 1.0+0.0i CMath.log10(-5.to_c) #=> (0.6989700043360187+1.3643763538418412i)
For more information you can see Complec class.
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.