Module: CMath

Includes:
Math
Defined in:
lib/rubysl/cmath/cmath.rb

Class Method Summary collapse

Class Method Details

.acos(z) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/rubysl/cmath/cmath.rb', line 155

def acos(z)
  if z.real? and z >= -1 and z <= 1
    acos!(z)
  else
    (-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z))
  end
end

.acos!Object



21
# File 'lib/rubysl/cmath/cmath.rb', line 21

alias acos! acos

.acosh(z) ⇒ Object



187
188
189
190
191
192
193
# File 'lib/rubysl/cmath/cmath.rb', line 187

def acosh(z)
  if z.real? and z >= 1
    acosh!(z)
  else
    log(z + sqrt(z * z - 1.0))
  end
end

.acosh!Object



26
# File 'lib/rubysl/cmath/cmath.rb', line 26

alias acosh! acosh

.asin(z) ⇒ Object



147
148
149
150
151
152
153
# File 'lib/rubysl/cmath/cmath.rb', line 147

def asin(z)
  if z.real? and z >= -1 and z <= 1
    asin!(z)
  else
    (-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z))
  end
end

.asin!Object



20
# File 'lib/rubysl/cmath/cmath.rb', line 20

alias asin! asin

.asinh(z) ⇒ Object



179
180
181
182
183
184
185
# File 'lib/rubysl/cmath/cmath.rb', line 179

def asinh(z)
  if z.real?
    asinh!(z)
  else
    log(z + sqrt(1.0 + z * z))
  end
end

.asinh!Object



25
# File 'lib/rubysl/cmath/cmath.rb', line 25

alias asinh! asinh

.atan(z) ⇒ Object



163
164
165
166
167
168
169
# File 'lib/rubysl/cmath/cmath.rb', line 163

def atan(z)
  if z.real?
    atan!(z)
  else
    1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0
  end
end

.atan!Object



22
# File 'lib/rubysl/cmath/cmath.rb', line 22

alias atan! atan

.atan2(y, x) ⇒ Object



171
172
173
174
175
176
177
# File 'lib/rubysl/cmath/cmath.rb', line 171

def atan2(y,x)
  if y.real? and x.real?
    atan2!(y,x)
  else
    (-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y))
  end
end

.atan2!Object



23
# File 'lib/rubysl/cmath/cmath.rb', line 23

alias atan2! atan2

.atanh(z) ⇒ Object



195
196
197
198
199
200
201
# File 'lib/rubysl/cmath/cmath.rb', line 195

def atanh(z)
  if z.real? and z >= -1 and z <= 1
    atanh!(z)
  else
    log((1.0 + z) / (1.0 - z)) / 2.0
  end
end

.atanh!Object



27
# File 'lib/rubysl/cmath/cmath.rb', line 27

alias atanh! atanh

.cbrt(z) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/rubysl/cmath/cmath.rb', line 87

def cbrt(z)
  if z.real?
    cbrt!(z)
  else
    Complex(z) ** (1.0/3)
  end
end

.cbrt!Object



10
# File 'lib/rubysl/cmath/cmath.rb', line 10

alias cbrt! cbrt

.cos(z) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/rubysl/cmath/cmath.rb', line 104

def cos(z)
  if z.real?
    cos!(z)
  else
    Complex(cos!(z.real) * cosh!(z.imag),
     -sin!(z.real) * sinh!(z.imag))
  end
end

.cos!Object



13
# File 'lib/rubysl/cmath/cmath.rb', line 13

alias cos! cos

.cosh(z) ⇒ Object



130
131
132
133
134
135
136
137
# File 'lib/rubysl/cmath/cmath.rb', line 130

def cosh(z)
  if z.real?
    cosh!(z)
  else
    Complex(cosh!(z.real) * cos!(z.imag),
     sinh!(z.real) * sin!(z.imag))
  end
end

.cosh!Object



17
# File 'lib/rubysl/cmath/cmath.rb', line 17

alias cosh! cosh

.erfObject

.erfcObject

.exp(z) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/rubysl/cmath/cmath.rb', line 29

def exp(z)
  if z.real?
    exp!(z)
  else
    ere = exp!(z.real)
    Complex(ere * cos!(z.imag),
     ere * sin!(z.imag))
  end
end

.exp!Object



5
# File 'lib/rubysl/cmath/cmath.rb', line 5

alias exp! exp

.frexpObject

.gammaObject

.hypotObject

.ldexpObject

.lgammaObject

.log(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rubysl/cmath/cmath.rb', line 39

def log(*args)
  z, b = args
  if z.real? and z >= 0 and (b.nil? or b >= 0)
    log!(*args)
  else
    a = Complex(log!(z.abs), z.arg)
    if b
  a /= log(b)
    end
    a
  end
end

.log!Object



6
# File 'lib/rubysl/cmath/cmath.rb', line 6

alias log! log

.log10(z) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/rubysl/cmath/cmath.rb', line 60

def log10(z)
  if z.real? and z >= 0
    log10!(z)
  else
    log(z) / log!(10)
  end
end

.log10!Object



8
# File 'lib/rubysl/cmath/cmath.rb', line 8

alias log10! log10

.log2(z) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/rubysl/cmath/cmath.rb', line 52

def log2(z)
  if z.real? and z >= 0
    log2!(z)
  else
    log(z) / log!(2)
  end
end

.log2!Object



7
# File 'lib/rubysl/cmath/cmath.rb', line 7

alias log2! log2

.sin(z) ⇒ Object



95
96
97
98
99
100
101
102
# File 'lib/rubysl/cmath/cmath.rb', line 95

def sin(z)
  if z.real?
    sin!(z)
  else
    Complex(sin!(z.real) * cosh!(z.imag),
     cos!(z.real) * sinh!(z.imag))
  end
end

.sin!Object



12
# File 'lib/rubysl/cmath/cmath.rb', line 12

alias sin! sin

.sinh(z) ⇒ Object



121
122
123
124
125
126
127
128
# File 'lib/rubysl/cmath/cmath.rb', line 121

def sinh(z)
  if z.real?
    sinh!(z)
  else
    Complex(sinh!(z.real) * cos!(z.imag),
     cosh!(z.real) * sin!(z.imag))
  end
end

.sinh!Object



16
# File 'lib/rubysl/cmath/cmath.rb', line 16

alias sinh! sinh

.sqrt(z) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rubysl/cmath/cmath.rb', line 68

def sqrt(z)
  if z.real?
    if z < 0
  Complex(0, sqrt!(-z))
    else
  sqrt!(z)
    end
  else
    if z.imag < 0 ||
 (z.imag == 0 && z.imag.to_s[0] == '-')
  sqrt(z.conjugate).conjugate
    else
  r = z.abs
  x = z.real
  Complex(sqrt!((r + x) / 2), sqrt!((r - x) / 2))
    end
  end
end

.sqrt!Object



9
# File 'lib/rubysl/cmath/cmath.rb', line 9

alias sqrt! sqrt

.tan(z) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/rubysl/cmath/cmath.rb', line 113

def tan(z)
  if z.real?
    tan!(z)
  else
    sin(z) / cos(z)
  end
end

.tan!Object



14
# File 'lib/rubysl/cmath/cmath.rb', line 14

alias tan! tan

.tanh(z) ⇒ Object



139
140
141
142
143
144
145
# File 'lib/rubysl/cmath/cmath.rb', line 139

def tanh(z)
  if z.real?
    tanh!(z)
  else
    sinh(z) / cosh(z)
  end
end

.tanh!Object



18
# File 'lib/rubysl/cmath/cmath.rb', line 18

alias tanh! tanh