Method: CMath.log
- Defined in:
- lib/cmath.rb
.log(z, b = ::Math::E) ⇒ Object
Returns the natural logarithm of Complex. If a second argument is given, it will be the base of logarithm.
CMath.log(1 + 4i) #=> (1.416606672028108+1.3258176636680326i)
CMath.log(1 + 4i, 10) #=> (0.6152244606891369+0.5757952953408879i)
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cmath.rb', line 82 def log(z, b=::Math::E) begin if z.real? && z >= 0 && b >= 0 RealMath.log(z, b) else Complex(RealMath.log(z.abs), z.arg) / log(b) end rescue NoMethodError handle_no_method_error end end |