extmath 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ Extended math library : Remarks
2
+
3
+ extmath does not implement Bessel functions, spherical harmonics,
4
+ hypergeometric functions etc. I could implement them but the
5
+ computation of that kind of functions is quite involved and
6
+ error-prone so that in my opinion it is a bad idea to have more than
7
+ one project that does implement them (bundle forces). I strongly
8
+ suggest supporting the development of GSL (the GNU Scientific
9
+ Library) and write Ruby bindings for this library.
10
+
11
+ As far as the function names for area functions are concerned I did
12
+ interpret the principle of least surprise that it requires
13
+ consistency with the names already used by Ruby 1.8. In mathematical
14
+ formulae
15
+
16
+ * Area cosinus hyperbolicus is not called acosh but arcosh.
17
+ * Area contangens hyperbolicus is not called atanh but artanh.
18
+ * Area sinus hyperbolicus is not called asinh but arsinh.
19
+ * Area tangens hyperbolicus is not called atanh but artanh.
20
+
21
+ -----------------------------------------------------------------
22
+
23
+ Last changed: 2003-08-21
24
+ HTML to text by ELinks 0.4.3rc1 - Text WWW browser
25
+ ELinks is vailable at http://elinks.or.cz/
@@ -0,0 +1,452 @@
1
+ Extended math library : Usage examples
2
+
3
+ The following set of test cases illustrates the usage of all Extmath
4
+ functions:
5
+
6
+ require 'runit/testcase'
7
+ require 'runit/cui/testrunner'
8
+ require 'runit/testsuite'
9
+ require 'rubygems'
10
+ require 'extmath'
11
+
12
+ class Testing_class < RUNIT::TestCase
13
+
14
+ def test_constants
15
+ assert_equal(Math::E, Extmath::E)
16
+ assert_equal(Math::PI, Extmath::PI)
17
+ end
18
+
19
+ def test_sign_functions
20
+
21
+ # Check behavior of abs
22
+ assert_equal(3.1, Extmath.abs(-3.1))
23
+ assert_equal(0.0, Extmath.abs( 0.0))
24
+ assert_equal(3.1, Extmath.abs( 3.1))
25
+
26
+ # Check behavior of sign
27
+ assert_equal(-1.0, Extmath.sign(-3.1))
28
+ assert_equal( 0.0, Extmath.sign( 0.0))
29
+ assert_equal( 1.0, Extmath.sign( 3.1))
30
+
31
+ end
32
+
33
+ def test_trigonometric_functions
34
+
35
+ # Check identity of Extmath.acos and Math.acos
36
+ assert_equal(Math.acos(-1.0), Extmath.acos(-1.0))
37
+ assert_equal(Math.acos( 1.0), Extmath.acos( 1.0))
38
+
39
+ # Check behavior of acot
40
+ assert_equal_float(0.5 * Math::PI - Math.atan(-1.0), Extmath.acot(-1.0), 1.0e-6)
41
+ assert_equal_float(0.5 * Math::PI - Math.atan( 1.0), Extmath.acot( 1.0), 1.0e-6)
42
+
43
+ # Check identity of Extmath.asin and Math.asin
44
+ assert_equal(Math.asin(-1.0), Extmath.asin(-1.0))
45
+ assert_equal(Math.asin( 1.0), Extmath.asin( 1.0))
46
+
47
+ # Check identity of Extmath.atan and Math.atan
48
+ assert_equal(Math.atan(-1.0), Extmath.atan(-1.0))
49
+ assert_equal(Math.atan( 1.0), Extmath.atan( 1.0))
50
+
51
+ # Check identity of Extmath.atan2 and Math.atan2
52
+ assert_equal(Math.atan2(-3.1, 3.1), Extmath.atan2(-3.1, 3.1))
53
+ assert_equal(Math.atan2( 3.1, 3.1), Extmath.atan2( 3.1, 3.1))
54
+
55
+ # Check identity of Extmath.cos and Math.cos
56
+ assert_equal(Math.cos(-1.0), Extmath.cos(-1.0))
57
+ assert_equal(Math.cos( 1.0), Extmath.cos( 1.0))
58
+
59
+ # Check identity of Extmath.asin and 1.0 / Math.sin
60
+ assert_equal(1.0 / Math.sin(-1.0), Extmath.cosec(-1.0))
61
+ assert_equal(1.0 / Math.sin( 1.0), Extmath.cosec( 1.0))
62
+
63
+ # Check identity of Extmath.cot and 1.0 / Math.tan
64
+ assert_equal_float(1.0 / Math.tan(1.0), Extmath.cot(1.0), 1.0e-6)
65
+ assert_equal_float(1.0 / Math.tan(2.0), Extmath.cot(2.0), 1.0e-6)
66
+
67
+ # Check identity of Extmath.sec and 1.0 / Math.cos
68
+ assert_equal_float(1.0 / Math.cos(1.0), Extmath.sec(1.0), 1.0e-6)
69
+ assert_equal_float(1.0 / Math.cos(2.0), Extmath.sec(2.0), 1.0e-6)
70
+
71
+ # Check identity of Extmath.sin and Math.sin
72
+ assert_equal(Math.sin(-1.0), Extmath.sin(-1.0))
73
+ assert_equal(Math.sin( 1.0), Extmath.sin( 1.0))
74
+
75
+ # Check identity of Extmath.tan and Math.tan
76
+ assert_equal(Math.tan(-1.0), Extmath.tan(-1.0))
77
+ assert_equal(Math.tan( 1.0), Extmath.tan( 1.0))
78
+
79
+ end
80
+
81
+ def test_hyperbolic_functions
82
+
83
+ # Check identity of Extmath.acosh and Math.acosh
84
+ assert_equal(Math.acosh(1.0), Extmath.acosh(1.0))
85
+ assert_equal(Math.acosh(2.0), Extmath.acosh(2.0))
86
+
87
+ # Check behavior of acoth
88
+ assert_equal_float(0.5 * Math.log(5.0), Extmath.acoth(1.5), 1.0e-6)
89
+ assert_equal_float(0.5 * Math.log(1.5), Extmath.acoth(5.0), 1.0e-6)
90
+
91
+ # Check identity of Extmath.asinh and Math.asinh
92
+ assert_equal(Math.asinh(-1.0), Extmath.asinh(-1.0))
93
+ assert_equal(Math.asinh( 1.0), Extmath.asinh( 1.0))
94
+
95
+ # Check identity of Extmath.atanh and Math.atanh
96
+ assert_equal(Math.atanh(-0.5), Extmath.atanh(-0.5))
97
+ assert_equal(Math.atanh( 0.5), Extmath.atanh( 0.5))
98
+
99
+ # Check identity of Extmath.acosech and 1.0 / Math.sinh
100
+ assert_equal(1.0 / Math.sinh(-1.0), Extmath.cosech(-1.0))
101
+ assert_equal(1.0 / Math.sinh( 1.0), Extmath.cosech( 1.0))
102
+
103
+ # Check identity of Extmat.cosh and Math.cosh
104
+ assert_equal(Math.cosh(-1.0), Extmath.cosh(-1.0))
105
+ assert_equal(Math.cosh( 1.0), Extmath.cosh( 1.0))
106
+
107
+ # Check identity of Extmat.coth and 1.0 / Math.tanh
108
+ assert_equal_float(1.0 / Math.tanh(1.0), Extmath.coth(1.0), 1.0e-6)
109
+ assert_equal_float(1.0 / Math.tanh(2.0), Extmath.coth(2.0), 1.0e-6)
110
+
111
+ # Check identity of Extmat.sech and 1.0 / Math.cosh
112
+ assert_equal_float(1.0 / Math.cosh(1.0), Extmath.sech(1.0), 1.0e-6)
113
+ assert_equal_float(1.0 / Math.cosh(2.0), Extmath.sech(2.0), 1.0e-6)
114
+
115
+ # Check identity of Extmat.sinh and Math.sinh
116
+ assert_equal(Math.sinh(-1.0), Extmath.sinh(-1.0))
117
+ assert_equal(Math.sinh( 1.0), Extmath.sinh( 1.0))
118
+
119
+ # Check identity of Extmat.tanh and Math.tanh
120
+ assert_equal(Math.tanh(-1.0), Extmath.tanh(-1.0))
121
+ assert_equal(Math.tanh( 1.0), Extmath.tanh( 1.0))
122
+ end
123
+
124
+ def test_explog_functions
125
+
126
+ # Check behavior of exp
127
+ assert_equal_float( 1.0, Extmath.exp(0.0), 1.0e-6)
128
+ assert_equal_float(Math.sqrt(Math::E), Extmath.exp(0.5), 1.0e-6)
129
+ assert_equal_float( Math::E, Extmath.exp(1.0), 1.0e-6)
130
+
131
+ # Check behavior of exp10
132
+ assert_equal_float( 1.0, Extmath.exp10(0.0), 1.0e-6)
133
+ assert_equal_float(Math.sqrt(10.0), Extmath.exp10(0.5), 1.0e-6)
134
+ assert_equal_float( 10.0, Extmath.exp10(1.0), 1.0e-6)
135
+
136
+ # Check behavior of exp2
137
+ assert_equal_float( 1.0, Extmath.exp2(0.0), 1.0e-6)
138
+ assert_equal_float(Math.sqrt(2.0), Extmath.exp2(0.5), 1.0e-6)
139
+ assert_equal_float( 2.0, Extmath.exp2(1.0), 1.0e-6)
140
+
141
+ # Check behavior of frexp
142
+ assert_equal([-0.99609375, 8], Extmath.frexp(-255.0))
143
+ assert_equal([-0.5, 1], Extmath.frexp( -1.0))
144
+ assert_equal([ 0.0, 0], Extmath.frexp( 0.0))
145
+ assert_equal([ 0.5, 1], Extmath.frexp( 1.0))
146
+ assert_equal([ 0.99609375, 8], Extmath.frexp( 255.0))
147
+
148
+ # Check behavior of ldexp
149
+ assert_equal_float(1.0, Extmath.ldexp(0.25, 2), 1.0e-6)
150
+ assert_equal_float(1.0, Extmath.ldexp(0.5, 1), 1.0e-6)
151
+ assert_equal_float(1.0, Extmath.ldexp(2, -1), 1.0e-6)
152
+ assert_equal_float(1.0, Extmath.ldexp(4, -2), 1.0e-6)
153
+
154
+ # Check identity of Extmat.log and Math.log
155
+ assert_equal(Math.log(2.0), Extmath.log(2.0))
156
+ assert_equal(Math.log(3.0), Extmath.log(3.0))
157
+
158
+ # Check identity of Extmat.log10 and Math.log10
159
+ assert_equal(Math.log10(2.0), Extmath.log10(2.0))
160
+ assert_equal(Math.log10(3.0), Extmath.log10(3.0))
161
+
162
+ # Check behavior of log2
163
+ assert_equal_float(0.5, Extmath.log2(Math.sqrt(2.0)), 1.0e-6)
164
+ assert_equal_float(1.0, Extmath.log2(2.0), 1.0e-6)
165
+ assert_equal_float(2.0, Extmath.log2(4.0), 1.0e-6)
166
+
167
+ end
168
+
169
+ def test_pwr_functions
170
+
171
+ # Check behavior of pwr
172
+ assert_equal_float(64.0, Extmath.pwr( 4.0, 3.0), 1.0e-6)
173
+ assert_equal_float( 0.729, Extmath.pwr( 0.9, 3.0), 1.0e-6)
174
+ assert_equal_float( 0.25, Extmath.pwr(64.0, -1.0 / 3.0), 1.0e-6)
175
+ assert_equal_float( 2.0, Extmath.pwr( 0.25, -0.5), 1.0e-6)
176
+
177
+ # Check behavior of root
178
+ assert_equal_float( 4.0, Extmath.root(64.0, 3.0), 1.0e-6)
179
+ assert_equal_float( 0.9, Extmath.root( 0.729, 3.0), 1.0e-6)
180
+ assert_equal_float(64.0, Extmath.root( 0.25, -1.0 / 3.0), 1.0e-6)
181
+ assert_equal_float( 0.25, Extmath.root( 2.0, -0.5), 1.0e-6)
182
+
183
+ # Check behavior of sqr
184
+ assert_equal_float(0.81, Extmath.sqr(-0.9), 1.0e-6)
185
+ assert_equal_float(0.49, Extmath.sqr(-0.7), 1.0e-6)
186
+ assert_equal_float(0.49, Extmath.sqr(-0.7), 1.0e-6)
187
+ assert_equal_float(0.81, Extmath.sqr( 0.9), 1.0e-6)
188
+
189
+ # Check behavior of sqrt
190
+ assert_equal_float(0.7, Extmath.sqrt(0.49), 1.0e-6)
191
+ assert_equal_float(0.9, Extmath.sqrt(0.81), 1.0e-6)
192
+
193
+ end
194
+
195
+ def test_rounding_functions
196
+
197
+ # Check behavior of ceil
198
+ assert_equal( 2, Extmath.ceil( 1.99999))
199
+ assert_equal( 2, Extmath.ceil( 1.5))
200
+ assert_equal( 2, Extmath.ceil( 1.00001))
201
+ assert_equal( 1, Extmath.ceil( 0.99999))
202
+ assert_equal( 1, Extmath.ceil( 0.5))
203
+ assert_equal( 1, Extmath.ceil( 0.00001))
204
+ assert_equal( 0, Extmath.ceil(-0.00001))
205
+ assert_equal( 0, Extmath.ceil(-0.5))
206
+ assert_equal( 0, Extmath.ceil(-0.99999))
207
+ assert_equal(-1, Extmath.ceil(-1.00001))
208
+ assert_equal(-1, Extmath.ceil(-1.5))
209
+ assert_equal(-1, Extmath.ceil(-1.99999))
210
+
211
+ # Check behavior of floor
212
+ assert_equal( 1, Extmath.floor( 1.99999))
213
+ assert_equal( 1, Extmath.floor( 1.5))
214
+ assert_equal( 1, Extmath.floor( 1.00001))
215
+ assert_equal( 0, Extmath.floor( 0.99999))
216
+ assert_equal( 0, Extmath.floor( 0.5))
217
+ assert_equal( 0, Extmath.floor( 0.00001))
218
+ assert_equal(-1, Extmath.floor(-0.00001))
219
+ assert_equal(-1, Extmath.floor(-0.5))
220
+ assert_equal(-1, Extmath.floor(-0.99999))
221
+ assert_equal(-2, Extmath.floor(-1.00001))
222
+ assert_equal(-2, Extmath.floor(-1.5))
223
+ assert_equal(-2, Extmath.floor(-1.99999))
224
+ end
225
+
226
+ def test_misc_functions
227
+
228
+ # Check behavior of beta
229
+ assert_equal_float( 1.0, Extmath.beta(1.0, 1.0), 1.0e-6)
230
+ assert_equal_float( 0.5, Extmath.beta(1.0, 2.0), 1.0e-6)
231
+ assert_equal_float( 1.0 / 3.0, Extmath.beta(1.0, 3.0), 1.0e-6)
232
+ assert_equal_float( 0.5, Extmath.beta(2.0, 1.0), 1.0e-6)
233
+ assert_equal_float( 1.0 / 6.0, Extmath.beta(2.0, 2.0), 1.0e-6)
234
+ assert_equal_float( 1.0 / 12.0, Extmath.beta(2.0, 3.0), 1.0e-6)
235
+ assert_equal_float( 1.0 / 3.0, Extmath.beta(3.0, 1.0), 1.0e-6)
236
+ assert_equal_float( 1.0 / 12.0, Extmath.beta(3.0, 2.0), 1.0e-6)
237
+ assert_equal_float( 1.0 / 30.0, Extmath.beta(3.0, 3.0), 1.0e-6)
238
+
239
+ # Check behavior of erf and erfc
240
+ assert_equal_float(0.0, Extmath.erf(0.0), 1.0e-6)
241
+ assert_equal_float(1.0, Extmath.erfc(0.0), 1.0e-6)
242
+
243
+ # Check behavior of factorial
244
+ fac = 1
245
+ 1.upto(100) {|i|
246
+ fac *= i
247
+ assert_equal(fac, Extmath.factorial(i))
248
+ }
249
+
250
+ # Check behavior of gamma (assert data that can be found in Bronstein Semendjajew).
251
+ assert_equal_float(1.00000, Extmath.gamma(1.00), 1.0e-5)
252
+ assert_equal_float(0.94740, Extmath.gamma(1.11), 1.0e-5)
253
+ assert_equal_float(0.91311, Extmath.gamma(1.22), 1.0e-5)
254
+ assert_equal_float(0.89338, Extmath.gamma(1.33), 1.0e-5)
255
+ assert_equal_float(0.88581, Extmath.gamma(1.44), 1.0e-5)
256
+ assert_equal_float(0.88887, Extmath.gamma(1.55), 1.0e-5)
257
+ assert_equal_float(0.90167, Extmath.gamma(1.66), 1.0e-5)
258
+ assert_equal_float(0.92376, Extmath.gamma(1.77), 1.0e-5)
259
+ assert_equal_float(0.95507, Extmath.gamma(1.88), 1.0e-5)
260
+ assert_equal_float(0.99581, Extmath.gamma(1.99), 1.0e-5)
261
+
262
+ # Check behavior of gcd
263
+ assert_equal( 4, Extmath.gcd( 4732, 4700))
264
+ assert_equal( 1, Extmath.gcd( 3651, 5023))
265
+ assert_equal(Extmath.factorial(47), Extmath.gcd(Extmath.factorial(90), Extmath.factorial(47)))
266
+ assert_equal( 5565651, Extmath.gcd( 612221610, 67461255771))
267
+
268
+ # Check behavior of hypoth
269
+ assert_equal_float(Math.sqrt( 5.0), Extmath.hypot(1.0, 2.0), 1.0e-6)
270
+ assert_equal_float(Math.sqrt(13.0), Extmath.hypot(2.0, 3.0), 1.0e-6)
271
+ assert_equal_float( 5.0, Extmath.hypot(3.0, 4.0), 1.0e-6)
272
+
273
+ # Check behavior of lcm
274
+ assert_equal(17017, Extmath.lcm( 77, 221))
275
+ assert_equal( 2431, Extmath.lcm(143, 187))
276
+ assert_equal( 1547, Extmath.lcm( 91, 119))
277
+
278
+ # Check behavior of ln_gamma
279
+ assert_equal_float( 0.0, Extmath.ln_gamma(2.0), 1.0e-6)
280
+ assert_equal_float(Extmath.log( 2.0), Extmath.ln_gamma(3.0), 1.0e-6)
281
+ assert_equal_float(Extmath.log( 6.0), Extmath.ln_gamma(4.0), 1.0e-6)
282
+ assert_equal_float(Extmath.log( 24.0), Extmath.ln_gamma(5.0), 1.0e-6)
283
+ assert_equal_float(Extmath.log(120.0), Extmath.ln_gamma(6.0), 1.0e-6)
284
+ assert_equal_float(Extmath.log(720.0), Extmath.ln_gamma(7.0), 1.0e-6)
285
+
286
+ # Check behavior of sinc
287
+ assert_equal_float( 1.0, Extmath.sinc( 0.0), 0.0)
288
+ assert_equal_float( Math.sin(1.0), Extmath.sinc( 1.0), 0.0)
289
+ assert_equal_float( Math.sin(1.0), Extmath.sinc(-1.0), 0.0)
290
+ assert_equal_float(0.5 * Math.sin(2.0), Extmath.sinc( 2.0), 0.0)
291
+ assert_equal_float(0.5 * Math.sin(2.0), Extmath.sinc(-2.0), 0.0)
292
+
293
+ end
294
+
295
+ def test_sign_consistency
296
+
297
+ # Check complementarity of abs and sign
298
+ assert_equal_float(-2.0, Extmath.abs(-2.0) * Extmath.sign(-2.0), 1e-6)
299
+ assert_equal_float( 0.0, Extmath.abs( 0.0) * Extmath.sign( 0.0), 1e-6)
300
+ assert_equal_float( 3.0, Extmath.abs( 3.0) * Extmath.sign( 3.0), 1e-6)
301
+
302
+ end
303
+
304
+ def test_trigonometric_consistency
305
+
306
+ # Check complementarity of acos and cos
307
+ assert_equal_float( 0.5, Extmath.acos(Extmath.cos(-0.5)), 1.0e-6)
308
+ assert_equal_float(-0.5, Extmath.cos(Extmath.acos(-0.5)), 1.0e-6)
309
+ assert_equal_float( 0.5, Extmath.acos(Extmath.cos( 0.5)), 1.0e-6)
310
+ assert_equal_float( 0.5, Extmath.cos(Extmath.acos( 0.5)), 1.0e-6)
311
+
312
+ # Check complementarity of acot and cot
313
+ assert_equal_float(1.0, Extmath.acot(Extmath.cot(1.0)), 1.0e-6)
314
+ assert_equal_float(1.0, Extmath.cot(Extmath.acot(1.0)), 1.0e-6)
315
+ assert_equal_float(2.0, Extmath.acot(Extmath.cot(2.0)), 1.0e-6)
316
+ assert_equal_float(2.0, Extmath.cot(Extmath.acot(2.0)), 1.0e-6)
317
+
318
+ # Check complementarity of asin and sin
319
+ assert_equal_float( 0.5, Extmath.asin(Extmath.sin( 0.5)), 1.0e-6)
320
+ assert_equal_float( 0.5, Extmath.sin(Extmath.asin( 0.5)), 1.0e-6)
321
+ assert_equal_float(-0.5, Extmath.asin(Extmath.sin(-0.5)), 1.0e-6)
322
+ assert_equal_float(-0.5, Extmath.sin(Extmath.asin(-0.5)), 1.0e-6)
323
+
324
+ # Check consistency of atan2 and acot
325
+ assert_equal_float(Extmath.atan2(1.0, 1.0), Extmath.acot(1.0), 1.0e-6)
326
+ assert_equal_float(Extmath.atan2(1.0, 2.0), Extmath.acot(2.0), 1.0e-6)
327
+
328
+ # Check consistency of atan2 and atan
329
+ assert_equal_float(Extmath.atan2(-3.1, 3.1), Extmath.atan(-1.0), 1.0e-6)
330
+ assert_equal_float(Extmath.atan2( 3.1, 3.1), Extmath.atan( 1.0), 1.0e-6)
331
+
332
+ # Check complementarity of atan and tan
333
+ assert_equal_float( 0.5, Extmath.atan(Extmath.tan( 0.5)), 1.0e-6)
334
+ assert_equal_float( 0.5, Extmath.tan(Extmath.atan( 0.5)), 1.0e-6)
335
+ assert_equal_float(-0.5, Extmath.atan(Extmath.tan(-0.5)), 1.0e-6)
336
+ assert_equal_float(-0.5, Extmath.tan(Extmath.atan(-0.5)), 1.0e-6)
337
+
338
+ # Check complementarity of cos and sec
339
+ assert_equal_float(1.0, Extmath.sec(-2.0) * Extmath.cos(-2.0), 1.0e-6)
340
+ assert_equal_float(1.0, Extmath.sec(-1.0) * Extmath.cos(-1.0), 1.0e-6)
341
+ assert_equal_float(1.0, Extmath.sec( 1.0) * Extmath.cos( 1.0), 1.0e-6)
342
+ assert_equal_float(1.0, Extmath.sec( 2.0) * Extmath.cos( 2.0), 1.0e-6)
343
+
344
+ # Check complementarity of cosec and sin
345
+ assert_equal_float(1.0, Extmath.cosec(-2.0) * Extmath.sin(-2.0), 1.0e-6)
346
+ assert_equal_float(1.0, Extmath.cosec(-1.0) * Extmath.sin(-1.0), 1.0e-6)
347
+ assert_equal_float(1.0, Extmath.cosec( 1.0) * Extmath.sin( 1.0), 1.0e-6)
348
+ assert_equal_float(1.0, Extmath.cosec( 2.0) * Extmath.sin( 2.0), 1.0e-6)
349
+
350
+ end
351
+
352
+ def test_hyperbolic_consistency
353
+
354
+ # Check complementarity of acosh and cosh
355
+ assert_equal_float(1.5, Extmath.acosh(Extmath.cosh( 1.5)), 1.0e-6)
356
+ assert_equal_float(1.5, Extmath.cosh(Extmath.acosh( 1.5)), 1.0e-6)
357
+ assert_equal_float(1.5, Extmath.acosh(Extmath.cosh(-1.5)), 1.0e-6)
358
+
359
+ # Check complementarity of acoth and coth
360
+ assert_equal_float( 1.5, Extmath.acoth(Extmath.coth( 1.5)), 1.0e-6)
361
+ assert_equal_float( 1.5, Extmath.coth(Extmath.acoth( 1.5)), 1.0e-6)
362
+ assert_equal_float(-1.5, Extmath.acoth(Extmath.coth(-1.5)), 1.0e-6)
363
+ assert_equal_float(-1.5, Extmath.coth(Extmath.acoth(-1.5)), 1.0e-6)
364
+
365
+ # Check complementarity of asinh and sinh
366
+ assert_equal_float( 1.5, Extmath.asinh(Extmath.sinh( 1.5)), 1.0e-6)
367
+ assert_equal_float( 1.5, Extmath.sinh(Extmath.asinh( 1.5)), 1.0e-6)
368
+ assert_equal_float(-1.5, Extmath.asinh(Extmath.sinh(-1.5)), 1.0e-6)
369
+ assert_equal_float(-1.5, Extmath.sinh(Extmath.asinh(-1.5)), 1.0e-6)
370
+
371
+ # Check complementarity of atanh and tanh
372
+ assert_equal_float( 0.5, Extmath.atanh(Extmath.tanh( 0.5)), 1.0e-6)
373
+ assert_equal_float( 0.5, Extmath.tanh(Extmath.atanh( 0.5)), 1.0e-6)
374
+ assert_equal_float(-0.5, Extmath.atanh(Extmath.tanh(-0.5)), 1.0e-6)
375
+ assert_equal_float(-0.5, Extmath.tanh(Extmath.atanh(-0.5)), 1.0e-6)
376
+
377
+ # Check complementarity of cosech and sinh
378
+ assert_equal_float(1.0, Extmath.cosech(-2.0) * Extmath.sinh(-2.0), 1.0e-6)
379
+ assert_equal_float(1.0, Extmath.cosech(-1.0) * Extmath.sinh(-1.0), 1.0e-6)
380
+ assert_equal_float(1.0, Extmath.cosech( 1.0) * Extmath.sinh( 1.0), 1.0e-6)
381
+ assert_equal_float(1.0, Extmath.cosech( 2.0) * Extmath.sinh( 2.0), 1.0e-6)
382
+
383
+ # Check complementarity of cosh and sech
384
+ assert_equal_float(1.0, Extmath.sech(-2.0) * Extmath.cosh(-2.0), 1.0e-6)
385
+ assert_equal_float(1.0, Extmath.sech(-1.0) * Extmath.cosh(-1.0), 1.0e-6)
386
+ assert_equal_float(1.0, Extmath.sech( 1.0) * Extmath.cosh( 1.0), 1.0e-6)
387
+ assert_equal_float(1.0, Extmath.sech( 2.0) * Extmath.cosh( 2.0), 1.0e-6)
388
+
389
+ end
390
+
391
+ def test_explog_consistency
392
+
393
+ # Check complementarity of exp and log
394
+ assert_equal_float(0.5, Extmath.log(Extmath.exp(0.5)), 1.0e-6)
395
+ assert_equal_float(1.0, Extmath.log(Extmath.exp(1.0)), 1.0e-6)
396
+ assert_equal_float(2.0, Extmath.log(Extmath.exp(2.0)), 1.0e-6)
397
+ assert_equal_float(0.5, Extmath.exp(Extmath.log(0.5)), 1.0e-6)
398
+ assert_equal_float(1.0, Extmath.exp(Extmath.log(1.0)), 1.0e-6)
399
+ assert_equal_float(2.0, Extmath.exp(Extmath.log(2.0)), 1.0e-6)
400
+
401
+ # Check complementarity of exp10 and log10
402
+ assert_equal_float(0.5, Extmath.log10(Extmath.exp10(0.5)), 1.0e-6)
403
+ assert_equal_float(1.0, Extmath.log10(Extmath.exp10(1.0)), 1.0e-6)
404
+ assert_equal_float(2.0, Extmath.log10(Extmath.exp10(2.0)), 1.0e-6)
405
+ assert_equal_float(0.5, Extmath.exp10(Extmath.log10(0.5)), 1.0e-6)
406
+ assert_equal_float(1.0, Extmath.exp10(Extmath.log10(1.0)), 1.0e-6)
407
+ assert_equal_float(2.0, Extmath.exp10(Extmath.log10(2.0)), 1.0e-6)
408
+
409
+ # Check complementarity of exp2 and log2
410
+ assert_equal_float(0.5, Extmath.log2(Extmath.exp2(0.5)), 1.0e-6)
411
+ assert_equal_float(1.0, Extmath.log2(Extmath.exp2(1.0)), 1.0e-6)
412
+ assert_equal_float(2.0, Extmath.log2(Extmath.exp2(2.0)), 1.0e-6)
413
+ assert_equal_float(0.5, Extmath.exp2(Extmath.log2(0.5)), 1.0e-6)
414
+ assert_equal_float(1.0, Extmath.exp2(Extmath.log2(1.0)), 1.0e-6)
415
+ assert_equal_float(2.0, Extmath.exp2(Extmath.log2(2.0)), 1.0e-6)
416
+
417
+ end
418
+
419
+ def test_pwr_consistency
420
+
421
+ # Check complementarity of pwr and root
422
+ assert_equal_float( 4.0, Extmath.root(Extmath.pwr(2.0, 6.0), 3.0), 1.0e-6)
423
+ assert_equal_float( 2.0, Extmath.root(Extmath.pwr(4.0, 4.0), 8.0), 1.0e-6)
424
+ assert_equal_float(Math.sqrt(2.0), Extmath.pwr(Extmath.root(2.0, 6.0), 3.0), 1.0e-6)
425
+ assert_equal_float( 16.0, Extmath.pwr(Extmath.root(4.0, 4.0), 8.0), 1.0e-6)
426
+
427
+ # Check complementarity of sqrt and sqr
428
+ assert_equal_float(0.3, Extmath.sqrt(Extmath.sqr( 0.3)), 1.0e-6)
429
+ assert_equal_float(0.3, Extmath.sqrt(Extmath.sqr(-0.3)), 1.0e-6)
430
+ assert_equal_float(0.3, Extmath.sqr(Extmath.sqrt( 0.3)), 1.0e-6)
431
+
432
+ end
433
+
434
+ def test_misc_consistency
435
+
436
+ # Check complimentarity of erf and erfc
437
+ assert_equal_float(1.0, Extmath.erf(1.0) + Extmath.erfc(1.0), 1.0e-6)
438
+ assert_equal_float(1.0, Extmath.erf(2.0) + Extmath.erfc(2.0), 1.0e-6)
439
+ assert_equal_float(1.0, Extmath.erf(3.0) + Extmath.erfc(3.0), 1.0e-6)
440
+ assert_equal_float(1.0, Extmath.erf(4.0) + Extmath.erfc(4.0), 1.0e-6)
441
+
442
+ end
443
+
444
+ end
445
+
446
+ RUNIT::CUI::TestRunner.run(Testing_class.suite)
447
+
448
+ -----------------------------------------------------------------
449
+
450
+ Last changed: 2003-08-21
451
+ HTML to text by ELinks 0.4.3rc1 - Text WWW browser
452
+ ELinks is vailable at http://elinks.or.cz/