rubysl-cmath 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8cb255743e775e61287cce512ddda2e95bc7c779
4
+ data.tar.gz: 9c38e600527f952a76ef43721e55e789ff96a28c
5
+ SHA512:
6
+ metadata.gz: ebe02b1c263adcd3e0632f517803fe32acada50bf00bce8a0ac15683d537b905aec124f91b75ee6ae61fe05f5b081c04bb822b762a81c20b80f5d85e4846e193
7
+ data.tar.gz: d9ef90da6c9e4ad7933b94fddeeb675f07d0fcea5ef7e8bff2587f47d4a02f73d38baebb234f929eefa4801f3197f8bc3d8f15fed4bb00e642f0291c8c17a740
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ env:
3
+ - RUBYLIB=lib
4
+ script: bundle exec mspec
5
+ rvm:
6
+ - 1.9.3
7
+ - rbx-nightly-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubysl-cmath.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2013, Brian Shirai
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ 3. Neither the name of the library nor the names of its contributors may be
13
+ used to endorse or promote products derived from this software without
14
+ specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
20
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,29 @@
1
+ # Rubysl::Cmath
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rubysl-cmath'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rubysl-cmath
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ require "rubysl/cmath"
@@ -0,0 +1,2 @@
1
+ require "rubysl/cmath/cmath"
2
+ require "rubysl/cmath/version"
@@ -0,0 +1,254 @@
1
+ module CMath
2
+
3
+ include Math
4
+
5
+ alias exp! exp
6
+ alias log! log
7
+ alias log2! log2
8
+ alias log10! log10
9
+ alias sqrt! sqrt
10
+ alias cbrt! cbrt
11
+
12
+ alias sin! sin
13
+ alias cos! cos
14
+ alias tan! tan
15
+
16
+ alias sinh! sinh
17
+ alias cosh! cosh
18
+ alias tanh! tanh
19
+
20
+ alias asin! asin
21
+ alias acos! acos
22
+ alias atan! atan
23
+ alias atan2! atan2
24
+
25
+ alias asinh! asinh
26
+ alias acosh! acosh
27
+ alias atanh! atanh
28
+
29
+ def exp(z)
30
+ if z.real?
31
+ exp!(z)
32
+ else
33
+ ere = exp!(z.real)
34
+ Complex(ere * cos!(z.imag),
35
+ ere * sin!(z.imag))
36
+ end
37
+ end
38
+
39
+ def log(*args)
40
+ z, b = args
41
+ if z.real? and z >= 0 and (b.nil? or b >= 0)
42
+ log!(*args)
43
+ else
44
+ a = Complex(log!(z.abs), z.arg)
45
+ if b
46
+ a /= log(b)
47
+ end
48
+ a
49
+ end
50
+ end
51
+
52
+ def log2(z)
53
+ if z.real? and z >= 0
54
+ log2!(z)
55
+ else
56
+ log(z) / log!(2)
57
+ end
58
+ end
59
+
60
+ def log10(z)
61
+ if z.real? and z >= 0
62
+ log10!(z)
63
+ else
64
+ log(z) / log!(10)
65
+ end
66
+ end
67
+
68
+ def sqrt(z)
69
+ if z.real?
70
+ if z < 0
71
+ Complex(0, sqrt!(-z))
72
+ else
73
+ sqrt!(z)
74
+ end
75
+ else
76
+ if z.imag < 0 ||
77
+ (z.imag == 0 && z.imag.to_s[0] == '-')
78
+ sqrt(z.conjugate).conjugate
79
+ else
80
+ r = z.abs
81
+ x = z.real
82
+ Complex(sqrt!((r + x) / 2), sqrt!((r - x) / 2))
83
+ end
84
+ end
85
+ end
86
+
87
+ def cbrt(z)
88
+ if z.real?
89
+ cbrt!(z)
90
+ else
91
+ Complex(z) ** (1.0/3)
92
+ end
93
+ end
94
+
95
+ def sin(z)
96
+ if z.real?
97
+ sin!(z)
98
+ else
99
+ Complex(sin!(z.real) * cosh!(z.imag),
100
+ cos!(z.real) * sinh!(z.imag))
101
+ end
102
+ end
103
+
104
+ def cos(z)
105
+ if z.real?
106
+ cos!(z)
107
+ else
108
+ Complex(cos!(z.real) * cosh!(z.imag),
109
+ -sin!(z.real) * sinh!(z.imag))
110
+ end
111
+ end
112
+
113
+ def tan(z)
114
+ if z.real?
115
+ tan!(z)
116
+ else
117
+ sin(z) / cos(z)
118
+ end
119
+ end
120
+
121
+ def sinh(z)
122
+ if z.real?
123
+ sinh!(z)
124
+ else
125
+ Complex(sinh!(z.real) * cos!(z.imag),
126
+ cosh!(z.real) * sin!(z.imag))
127
+ end
128
+ end
129
+
130
+ def cosh(z)
131
+ if z.real?
132
+ cosh!(z)
133
+ else
134
+ Complex(cosh!(z.real) * cos!(z.imag),
135
+ sinh!(z.real) * sin!(z.imag))
136
+ end
137
+ end
138
+
139
+ def tanh(z)
140
+ if z.real?
141
+ tanh!(z)
142
+ else
143
+ sinh(z) / cosh(z)
144
+ end
145
+ end
146
+
147
+ def asin(z)
148
+ if z.real? and z >= -1 and z <= 1
149
+ asin!(z)
150
+ else
151
+ (-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z))
152
+ end
153
+ end
154
+
155
+ def acos(z)
156
+ if z.real? and z >= -1 and z <= 1
157
+ acos!(z)
158
+ else
159
+ (-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z))
160
+ end
161
+ end
162
+
163
+ def atan(z)
164
+ if z.real?
165
+ atan!(z)
166
+ else
167
+ 1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0
168
+ end
169
+ end
170
+
171
+ def atan2(y,x)
172
+ if y.real? and x.real?
173
+ atan2!(y,x)
174
+ else
175
+ (-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y))
176
+ end
177
+ end
178
+
179
+ def asinh(z)
180
+ if z.real?
181
+ asinh!(z)
182
+ else
183
+ log(z + sqrt(1.0 + z * z))
184
+ end
185
+ end
186
+
187
+ def acosh(z)
188
+ if z.real? and z >= 1
189
+ acosh!(z)
190
+ else
191
+ log(z + sqrt(z * z - 1.0))
192
+ end
193
+ end
194
+
195
+ def atanh(z)
196
+ if z.real? and z >= -1 and z <= 1
197
+ atanh!(z)
198
+ else
199
+ log((1.0 + z) / (1.0 - z)) / 2.0
200
+ end
201
+ end
202
+
203
+ module_function :exp!
204
+ module_function :exp
205
+ module_function :log!
206
+ module_function :log
207
+ module_function :log2!
208
+ module_function :log2
209
+ module_function :log10!
210
+ module_function :log10
211
+ module_function :sqrt!
212
+ module_function :sqrt
213
+ module_function :cbrt!
214
+ module_function :cbrt
215
+
216
+ module_function :sin!
217
+ module_function :sin
218
+ module_function :cos!
219
+ module_function :cos
220
+ module_function :tan!
221
+ module_function :tan
222
+
223
+ module_function :sinh!
224
+ module_function :sinh
225
+ module_function :cosh!
226
+ module_function :cosh
227
+ module_function :tanh!
228
+ module_function :tanh
229
+
230
+ module_function :asin!
231
+ module_function :asin
232
+ module_function :acos!
233
+ module_function :acos
234
+ module_function :atan!
235
+ module_function :atan
236
+ module_function :atan2!
237
+ module_function :atan2
238
+
239
+ module_function :asinh!
240
+ module_function :asinh
241
+ module_function :acosh!
242
+ module_function :acosh
243
+ module_function :atanh!
244
+ module_function :atanh
245
+
246
+ module_function :frexp
247
+ module_function :ldexp
248
+ module_function :hypot
249
+ module_function :erf
250
+ module_function :erfc
251
+ module_function :gamma
252
+ module_function :lgamma
253
+
254
+ end
@@ -0,0 +1,5 @@
1
+ module RubySL
2
+ module CMath
3
+ VERSION = "2.0.0"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ require './lib/rubysl/cmath/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "rubysl-cmath"
6
+ spec.version = RubySL::CMath::VERSION
7
+ spec.authors = ["Brian Shirai"]
8
+ spec.email = ["brixen@gmail.com"]
9
+ spec.description = %q{Ruby standard library cmath.}
10
+ spec.summary = %q{Ruby standard library cmath.}
11
+ spec.homepage = "https://github.com/rubysl/rubysl-cmath"
12
+ spec.license = "BSD"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "mspec", "~> 1.5"
22
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubysl-cmath
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Shirai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ description: Ruby standard library cmath.
56
+ email:
57
+ - brixen@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - lib/cmath.rb
69
+ - lib/rubysl/cmath.rb
70
+ - lib/rubysl/cmath/cmath.rb
71
+ - lib/rubysl/cmath/version.rb
72
+ - rubysl-cmath.gemspec
73
+ homepage: https://github.com/rubysl/rubysl-cmath
74
+ licenses:
75
+ - BSD
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.7
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Ruby standard library cmath.
97
+ test_files: []