gnu_mpc 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/.yardopts +2 -0
- data/CHANGELOG +27 -5
- data/Gemfile +3 -1
- data/README.md +61 -5
- data/Rakefile +11 -3
- data/ext/extconf.rb +5 -1
- data/ext/gmprandstate.c +54 -0
- data/ext/mpc.c +358 -186
- data/ext/mpcrnd.c +3 -3
- data/ext/ruby_gmp.h +4 -4
- data/ext/ruby_mpc.h +2 -0
- data/manual.md +40 -14
- data/manual.pdf +0 -0
- data/spec/acos_spec.rb +15 -15
- data/spec/add_args_spec.rb +21 -21
- data/spec/add_fr_spec.rb +22 -22
- data/spec/add_spec.rb +12 -12
- data/spec/arg_spec.rb +14 -0
- data/spec/asin_spec.rb +12 -12
- data/spec/atan_spec.rb +26 -26
- data/spec/fma_spec.rb +20 -0
- data/spec/imag_spec.rb +23 -0
- data/spec/log10_spec.rb +21 -13
- data/spec/mpc_single_function_args_spec.rb +6 -6
- data/spec/new_spec.rb +54 -23
- data/spec/pow_spec.rb +79 -0
- data/spec/prec_arguments_spec.rb +40 -0
- data/spec/prec_spec.rb +17 -0
- data/spec/sub_spec.rb +35 -2
- data/spec/urandom_spec.rb +14 -0
- metadata +16 -5
data/ext/mpcrnd.c
CHANGED
@@ -44,9 +44,9 @@ VALUE r_mpcrndsg_new(int argc, VALUE *argv, VALUE klass)
|
|
44
44
|
VALUE r_mpcrnd_initialize(int argc, VALUE *argv, VALUE self)
|
45
45
|
{
|
46
46
|
VALUE mode, name, ieee754;
|
47
|
-
mode = argv[0];
|
48
|
-
(void)argc;
|
49
47
|
char name_val[12];
|
48
|
+
(void)argc;
|
49
|
+
mode = argv[0];
|
50
50
|
|
51
51
|
switch (FIX2INT(mode) % 16) {
|
52
52
|
case 0:
|
@@ -162,8 +162,8 @@ mpc_rnd_t r_mpc_get_rounding_mode(VALUE rnd)
|
|
162
162
|
|
163
163
|
void init_mpcrnd()
|
164
164
|
{
|
165
|
-
cMPC = rb_define_class ("MPC", rb_cNumeric);
|
166
165
|
ID new_id = rb_intern ("new");
|
166
|
+
cMPC = rb_define_class ("MPC", rb_cNumeric);
|
167
167
|
|
168
168
|
cMPC_Rnd = rb_define_class_under (cMPC, "Rnd", rb_cObject);
|
169
169
|
|
data/ext/ruby_gmp.h
CHANGED
@@ -58,10 +58,10 @@ typedef __gmp_randstate_struct MP_RANDSTATE;
|
|
58
58
|
}*/
|
59
59
|
#define mpz_temp_alloc(var) { var=malloc(sizeof(MP_INT)); }
|
60
60
|
#define mpz_temp_init(var) { mpz_temp_alloc(var); mpz_init(var); }
|
61
|
-
#define mpz_temp_from_bignum(var,var_bignum) {
|
62
|
-
|
63
|
-
|
64
|
-
mpz_init_set_str (var, StringValuePtr (tmp), 32);
|
61
|
+
#define mpz_temp_from_bignum(var,var_bignum) { \
|
62
|
+
VALUE tmp = rb_funcall (var_bignum, rb_intern ("to_s"), 1, INT2FIX (32)); \
|
63
|
+
mpz_temp_alloc(var); \
|
64
|
+
mpz_init_set_str (var, StringValuePtr (tmp), 32); \
|
65
65
|
}
|
66
66
|
#define mpz_temp_free(var) { mpz_clear(var); free(var); }
|
67
67
|
#define mpf_temp_alloc(var) { var=malloc(sizeof(MP_FLOAT)); }
|
data/ext/ruby_mpc.h
CHANGED
@@ -39,6 +39,7 @@ typedef __mpc_struct MP_COMPLEX;
|
|
39
39
|
|
40
40
|
/* EXPECTED_Cxxx macros */
|
41
41
|
#define EXPECTED_FXC "Expected GMP::F, Fixnum, or MPC"
|
42
|
+
#define EXPECTED_XBZFC "Expected Fixnum, Bignum, GMP::Z, Float, GMP::F, or MPC"
|
42
43
|
|
43
44
|
// MPC Rounding Modes
|
44
45
|
#define mpcrnd_get_struct(ruby_var,c_var) { Data_Get_Struct(ruby_var, int, c_var); }
|
@@ -59,5 +60,6 @@ extern mpc_rnd_t r_get_mpc_rounding_mode(VALUE rnd);
|
|
59
60
|
extern mpc_rnd_t r_get_default_mpc_rounding_mode();
|
60
61
|
extern mpc_rnd_t r_mpc_get_rounding_mode(VALUE rnd);
|
61
62
|
extern void init_mpcrnd();
|
63
|
+
extern void init_gmprandstate_mpc();
|
62
64
|
|
63
65
|
#endif /* _RUBY_MPC_H_ */
|
data/manual.md
CHANGED
@@ -208,19 +208,19 @@ for optional arguments, after any required arguments. For example, since
|
|
208
208
|
be supplied like so:
|
209
209
|
|
210
210
|
MPC.new([1,1]).pow(2, {})
|
211
|
-
MPC.new([
|
211
|
+
MPC.new([1,1]).sin({})
|
212
212
|
|
213
213
|
Here are the keys typically accepted by an `MPC` instance method.
|
214
214
|
|
215
215
|
`:rnd`, `:round`, `:rounding`, `:rounding_mode`
|
216
|
-
:
|
216
|
+
: rounding mode for the operation
|
217
217
|
`:prec`, `:precision`
|
218
|
-
:
|
218
|
+
: precision used when initializing the return value; This precision will be
|
219
219
|
used for both the real and imaginary parts of the returned complex value.
|
220
220
|
`:real_prec`, `:real_precision`
|
221
|
-
:
|
221
|
+
: precision used for the real part of the return value
|
222
222
|
`:imag_prec`, `:imag_precision`
|
223
|
-
:
|
223
|
+
: precision used for the imaginary part of the return value
|
224
224
|
|
225
225
|
### Precision of Returned Values
|
226
226
|
|
@@ -241,7 +241,8 @@ of three ways:
|
|
241
241
|
|
242
242
|
* The user can also specify the precision of the real part, and the imaginary
|
243
243
|
part, individually, using the options hash as well. The `:real_prec`,
|
244
|
-
`:real_precision
|
244
|
+
(or `:real_precision`) and `:imag_prec` (or `:imag_precision`) keys can be
|
245
|
+
used:
|
245
246
|
|
246
247
|
MPC.new(72).sin(:real_prec => 17, :imag_prec => 53)
|
247
248
|
The broad `:prec` and `:precision` values are parsed before the real- and
|
@@ -356,7 +357,8 @@ MPC.new(GMP::Z.new(31)) #=> 31 (GMP Integer)
|
|
356
357
|
\begin{tabular}{p{\methwidth} l r p{\returnwidth}}
|
357
358
|
\toprule
|
358
359
|
\textbf{real} & & MPC\#real() & $\rightarrow$ \textit{GMP::F} \\
|
359
|
-
& & MPC\#real(\textit{rounding\_mode} = MPC::MPC\_RNDNN
|
360
|
+
& & MPC\#real(\textit{rounding\_mode} = MPC::MPC\_RNDNN, & \\
|
361
|
+
& & \textit{precision} = \textit{mpfr\_default\_precision}) & $\rightarrow$ \textit{GMP::F} \\
|
360
362
|
\cmidrule(r){2-4}
|
361
363
|
& \multicolumn{3}{p{\defnwidth}}{
|
362
364
|
Return the real part of the receiver, rounded according to
|
@@ -365,7 +367,8 @@ MPC.new(GMP::Z.new(31)) #=> 31 (GMP Integer)
|
|
365
367
|
|
366
368
|
\toprule
|
367
369
|
\textbf{imag} & & MPC\#imag() & $\rightarrow$ \textit{GMP::F} \\
|
368
|
-
& & MPC\#imag(\textit{rounding\_mode} = MPC::MPC\_RNDNN
|
370
|
+
& & MPC\#imag(\textit{rounding\_mode} = MPC::MPC\_RNDNN, & \\
|
371
|
+
& & \textit{precision} = \textit{mpfr\_default\_precision}) & $\rightarrow$ \textit{GMP::F} \\
|
369
372
|
\cmidrule(r){2-4}
|
370
373
|
& \multicolumn{3}{p{\defnwidth}}{
|
371
374
|
Return the imaginary part of the receiver, rounded according to
|
@@ -373,10 +376,19 @@ MPC.new(GMP::Z.new(31)) #=> 31 (GMP Integer)
|
|
373
376
|
} \\
|
374
377
|
|
375
378
|
\toprule
|
376
|
-
\textbf{
|
377
|
-
& & MPC\#
|
379
|
+
\textbf{arg} & & MPC\#arg() & $\rightarrow$ \textit{GMP::F} \\
|
380
|
+
& & MPC\#arg(\textit{rounding\_mode} = MPC::MPC\_RNDNN, & \\
|
378
381
|
& & \textit{precision} = \textit{mpfr\_default\_precision}) & $\rightarrow$ \textit{GMP::F} \\
|
379
382
|
\cmidrule(r){2-4}
|
383
|
+
& \multicolumn{3}{p{\defnwidth}}{
|
384
|
+
Return the argument of the receiver, rounded according to $rounding\_mode$.
|
385
|
+
} \\
|
386
|
+
|
387
|
+
\toprule
|
388
|
+
\textbf{proj} & & MPC\#proj() & $\rightarrow$ \textit{MPC} \\
|
389
|
+
& & MPC\#proj(\textit{rounding\_mode} = MPC::MPC\_RNDNN, & \\
|
390
|
+
& & \textit{precision} = \textit{mpfr\_default\_precision}) & $\rightarrow$ \textit{MPC} \\
|
391
|
+
\cmidrule(r){2-4}
|
380
392
|
& \multicolumn{3}{p{\defnwidth}}{
|
381
393
|
Return the projection of the receiver onto the Riemann sphere, rounded according to
|
382
394
|
$rounding\_mode$.
|
@@ -389,7 +401,7 @@ MPC.new(GMP::Z.new(31)) #=> 31 (GMP Integer)
|
|
389
401
|
<th>real</th><th>`MPC#real()` $\rightarrow$ _GMP::F_
|
390
402
|
</tr>
|
391
403
|
<tr class="last-header">
|
392
|
-
<th></th> <th><code>MPC#real(_rounding_mode_ = MPC::MPC_RNDNN)</code> $\rightarrow$ _GMP::F_
|
404
|
+
<th></th> <th><code>MPC#real(_rounding_mode_ = MPC::MPC_RNDNN, _precision_ = _mpfr_default_)</code> $\rightarrow$ _GMP::F_
|
393
405
|
</th>
|
394
406
|
</tr>
|
395
407
|
<tr>
|
@@ -403,7 +415,7 @@ Return the real part of the receiver, rounded according to $rounding\_mode$.
|
|
403
415
|
<th>imag</th><th>`MPC#imag()` $\rightarrow$ _GMP::F_
|
404
416
|
</tr>
|
405
417
|
<tr class="last-header">
|
406
|
-
<th></th> <th><code>MPC#imag(_rounding_mode_ = MPC::MPC_RNDNN)</code> $\rightarrow$ _GMP::F_
|
418
|
+
<th></th> <th><code>MPC#imag(_rounding_mode_ = MPC::MPC_RNDNN, _precision_ = _mpfr_default_)</code> $\rightarrow$ _GMP::F_
|
407
419
|
</th>
|
408
420
|
</tr>
|
409
421
|
<tr>
|
@@ -414,10 +426,24 @@ Return the imaginary part of the receiver, rounded according to $rounding\_mode$
|
|
414
426
|
</tr>
|
415
427
|
|
416
428
|
<tr class="new-method">
|
417
|
-
<th>
|
429
|
+
<th>arg</th><th>`MPC#arg()` $\rightarrow$ _GMP::F_
|
430
|
+
</tr>
|
431
|
+
<tr class="last-header">
|
432
|
+
<th></th> <th><code>MPC#arg(_rounding_mode_ = MPC::MPC_RNDNN, _precision_ = _mpfr_default_)</code> $\rightarrow$ _GMP::F_
|
433
|
+
</th>
|
434
|
+
</tr>
|
435
|
+
<tr>
|
436
|
+
<td></td>
|
437
|
+
<td>
|
438
|
+
Return the argument of the receiver, rounded according to $rounding\_mode$.
|
439
|
+
</td>
|
440
|
+
</tr>
|
441
|
+
|
442
|
+
<tr class="new-method">
|
443
|
+
<th>proj</th><th>`MPC#proj()` $\rightarrow$ _MPC_
|
418
444
|
</tr>
|
419
445
|
<tr>
|
420
|
-
<th></th> <th><code>MPC#proj(_rounding_mode_ = MPC::MPC_RNDNN, _precision_ = _mpfr_default_)</code> $\rightarrow$
|
446
|
+
<th></th> <th><code>MPC#proj(_rounding_mode_ = MPC::MPC_RNDNN, _precision_ = _mpfr_default_)</code> $\rightarrow$ _MPC_
|
421
447
|
</th>
|
422
448
|
</tr>
|
423
449
|
<tr class="last-header">
|
data/manual.pdf
CHANGED
Binary file
|
data/spec/acos_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
2
2
|
|
3
3
|
# All tests adapted from MPC 1.0.1's tests/acos.dat
|
4
4
|
describe MPC, '#acos' do
|
5
|
-
it '
|
5
|
+
it 'calculates the inverse cosine of a pure real argument' do
|
6
6
|
data = [
|
7
7
|
[[ "0x1921FB54442D18p-51", 53, 16], [ "0x13D2B7539DBA4Cp-51", 53, 16], MPC.new([GMP::F(-6 ), -GMP::F(0)])],
|
8
8
|
[[ "0x1921FB54442D18p-51", 53, 16], ["-0x13D2B7539DBA4Cp-51", 53, 16], MPC.new([GMP::F(-6 ), GMP::F(0)])],
|
@@ -23,12 +23,12 @@ describe MPC, '#acos' do
|
|
23
23
|
]
|
24
24
|
data.each do |expected_real, expected_imag, input|
|
25
25
|
actual = input.acos
|
26
|
-
actual.real.
|
27
|
-
actual.imag.
|
26
|
+
expect(actual.real).to eq GMP::F.new(*expected_real)
|
27
|
+
expect(actual.imag).to eq GMP::F.new(*expected_imag)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
it '
|
31
|
+
it 'calculates the inverse cosine of a pure imaginary argument' do
|
32
32
|
data = [
|
33
33
|
[["0x1921FB54442D18p-52", 53, 16], [ "0x1D185B507EDC0Ep-52", 53, 16], MPC.new([-GMP::F(0), GMP::F(-3 )])],
|
34
34
|
[["0x1921FB54442D18p-52", 53, 16], [ "0x1D185B507EDC0Ep-52", 53, 16], MPC.new([ GMP::F(0), GMP::F(-3 )])],
|
@@ -41,26 +41,26 @@ describe MPC, '#acos' do
|
|
41
41
|
]
|
42
42
|
data.each do |expected_real, expected_imag, input|
|
43
43
|
actual = input.acos
|
44
|
-
actual.real.
|
45
|
-
actual.imag.
|
44
|
+
expect(actual.real).to eq GMP::F.new(*expected_real)
|
45
|
+
expect(actual.imag).to eq GMP::F.new(*expected_imag)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
it '
|
49
|
+
it 'calculates the inverse cosine with other precisions' do
|
50
50
|
actual = MPC.new([GMP::F.new(2), GMP::F.new(1)]).acos(MPC::MPC_RNDNZ, 2)
|
51
|
-
actual.real.
|
52
|
-
actual.imag.
|
51
|
+
expect(actual.real).to eq GMP::F.new( 0.5, 2)
|
52
|
+
expect(actual.imag).to eq GMP::F.new(-1, 2)
|
53
53
|
end
|
54
54
|
|
55
|
-
it '
|
55
|
+
it 'calculates the inverse cosine with other precisions' do
|
56
56
|
actual = MPC.new([GMP::F.new(8.5), GMP::F.new(-71)]).acos(MPC::MPC_RNDNU, 9)
|
57
|
-
actual.real.
|
58
|
-
actual.imag.
|
57
|
+
expect(actual.real).to eq GMP::F.new("0x5Dp-6", 9, 16)
|
58
|
+
expect(actual.imag).to eq GMP::F.new("0x9Fp-5", 9, 16)
|
59
59
|
end
|
60
60
|
|
61
|
-
it '
|
61
|
+
it 'calculates the inverse cosine with other precisions' do
|
62
62
|
actual = MPC.new([GMP::F.new("0x3243F6A8885A3p-48", 53, 16), GMP::F.new("0x162E42FEFA39EFp-53", 53, 16)]).acos
|
63
|
-
actual.real.
|
64
|
-
actual.imag.
|
63
|
+
expect(actual.real).to eq GMP::F.new("0x74C141310E695p-53", 53, 16)
|
64
|
+
expect(actual.imag).to eq GMP::F.new("-0x1D6D2CFA9F3F11p-52", 53, 16)
|
65
65
|
end
|
66
66
|
end
|
data/spec/add_args_spec.rb
CHANGED
@@ -1,51 +1,51 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
3
|
describe MPC, '#add' do
|
4
|
-
it '
|
4
|
+
it 'calculate the sum of an MPC and a Fixnum' do
|
5
5
|
op1 = MPC.new([7, 16])
|
6
6
|
actual = op1.add(0)
|
7
|
-
actual.real.
|
8
|
-
actual.imag.
|
7
|
+
expect(actual.real).to eq 7
|
8
|
+
expect(actual.imag).to eq 16
|
9
9
|
|
10
10
|
actual = op1.add(6)
|
11
|
-
actual.real.
|
12
|
-
actual.imag.
|
11
|
+
expect(actual.real).to eq 13
|
12
|
+
expect(actual.imag).to eq 16
|
13
13
|
|
14
14
|
actual = op1.add(-1000)
|
15
|
-
actual.real.
|
16
|
-
actual.imag.
|
15
|
+
expect(actual.real).to eq -993
|
16
|
+
expect(actual.imag).to eq 16
|
17
17
|
|
18
18
|
op1 = MPC.new([GMP::F(3.1), GMP::F(16)])
|
19
19
|
actual = op1.add(3)
|
20
|
-
actual.real.
|
21
|
-
actual.imag.
|
20
|
+
expect(actual.real).to eq GMP::F(6.1)
|
21
|
+
expect(actual.imag).to eq 16
|
22
22
|
end
|
23
23
|
|
24
|
-
it '
|
24
|
+
it 'calculates the sum of an MPC and a GMP::Z' do
|
25
25
|
op1 = MPC.new([7, 16])
|
26
26
|
actual = op1.add(GMP::Z(0))
|
27
|
-
actual.real.
|
28
|
-
actual.imag.
|
27
|
+
expect(actual.real).to eq 7
|
28
|
+
expect(actual.imag).to eq 16
|
29
29
|
|
30
30
|
actual = op1.add(GMP::Z(-1000))
|
31
|
-
actual.real.
|
32
|
-
actual.imag.
|
31
|
+
expect(actual.real).to eq -993
|
32
|
+
expect(actual.imag).to eq 16
|
33
33
|
|
34
34
|
op1 = MPC.new([GMP::F(3.1), GMP::F(16)])
|
35
35
|
actual = op1.add(GMP::Z(3))
|
36
|
-
actual.real.
|
37
|
-
actual.imag.
|
36
|
+
expect(actual.real).to eq GMP::F(6.1)
|
37
|
+
expect(actual.imag).to eq 16
|
38
38
|
end
|
39
39
|
|
40
|
-
it '
|
40
|
+
it 'calculates the sum of an MPC and a Bignum' do
|
41
41
|
op1 = MPC.new([7, 16])
|
42
42
|
actual = op1.add(2**65) # 36893488147419103232
|
43
|
-
actual.real.
|
44
|
-
actual.imag.
|
43
|
+
expect(actual.real).to eq 36893488147419103239
|
44
|
+
expect(actual.imag).to eq 16
|
45
45
|
|
46
46
|
op1 = MPC.new([GMP::F(3.1), GMP::F(16)])
|
47
47
|
actual = op1.add(2**65) # 36893488147419103232
|
48
|
-
actual.real.
|
49
|
-
actual.imag.
|
48
|
+
expect(actual.real).to eq GMP::F("36893488147419103235.1")
|
49
|
+
expect(actual.imag).to eq 16
|
50
50
|
end
|
51
51
|
end
|
data/spec/add_fr_spec.rb
CHANGED
@@ -2,53 +2,53 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
2
2
|
|
3
3
|
# All tests adapted from MPC 1.0.1's tests/add.dat
|
4
4
|
describe MPC, '#add' do
|
5
|
-
it '
|
5
|
+
it 'calculates the sum of two real MPCs' do
|
6
6
|
op1 = MPC.new([1, 0])
|
7
7
|
op2_106 = GMP::F("0x10000000000001p-106", 53, 16)
|
8
8
|
actual = op1.add(op2_106, MPC::MPC_RNDNN)
|
9
|
-
actual.real.
|
10
|
-
actual.imag.
|
9
|
+
expect(actual.real).to eq GMP::F("0x10000000000000p-52", 53, 16)
|
10
|
+
expect(actual.imag).to eq GMP::F(0)
|
11
11
|
|
12
12
|
op2_105 = GMP::F("0x10000000000001p-105", 53, 16)
|
13
13
|
actual = op1.add(op2_105, MPC::MPC_RNDNN)
|
14
|
-
actual.real.
|
15
|
-
actual.imag.
|
14
|
+
expect(actual.real).to eq GMP::F("0x10000000000001p-52", 53, 16)
|
15
|
+
expect(actual.imag).to eq GMP::F(0)
|
16
16
|
|
17
17
|
op2_104 = GMP::F("0x10000000000001p-104", 53, 16)
|
18
18
|
actual = op1.add(op2_104, MPC::MPC_RNDNN)
|
19
|
-
actual.real.
|
20
|
-
actual.imag.
|
19
|
+
expect(actual.real).to eq GMP::F("0x10000000000001p-52", 53, 16)
|
20
|
+
expect(actual.imag).to eq GMP::F(0)
|
21
21
|
|
22
22
|
actual = op1.add(op2_105, MPC::MPC_RNDZZ)
|
23
|
-
actual.real.
|
24
|
-
actual.imag.
|
23
|
+
expect(actual.real).to eq GMP::F("0x10000000000000p-52", 53, 16)
|
24
|
+
expect(actual.imag).to eq GMP::F(0)
|
25
25
|
|
26
26
|
actual = op1.add(op2_105, MPC::MPC_RNDUU)
|
27
|
-
actual.real.
|
28
|
-
actual.imag.
|
27
|
+
expect(actual.real).to eq GMP::F("0x10000000000001p-52", 53, 16)
|
28
|
+
expect(actual.imag).to eq GMP::F(0)
|
29
29
|
|
30
30
|
actual = op1.add(op2_105, MPC::MPC_RNDDD)
|
31
|
-
actual.real.
|
32
|
-
actual.imag.
|
31
|
+
expect(actual.real).to eq GMP::F("0x10000000000000p-52", 53, 16)
|
32
|
+
expect(actual.imag).to eq GMP::F(0)
|
33
33
|
end
|
34
34
|
|
35
|
-
it '
|
35
|
+
it 'calculates the sum of an imaginary argument with a complex one.' do
|
36
36
|
op1 = MPC.new([0, 1])
|
37
37
|
op2 = GMP::F(1)
|
38
38
|
actual = op1.add(op2, MPC::MPC_RNDNN)
|
39
|
-
actual.real.
|
40
|
-
actual.imag.
|
39
|
+
expect(actual.real).to eq GMP::F(1)
|
40
|
+
expect(actual.imag).to eq GMP::F(1)
|
41
41
|
|
42
42
|
actual = op1.add(op2, MPC::MPC_RNDZZ)
|
43
|
-
actual.real.
|
44
|
-
actual.imag.
|
43
|
+
expect(actual.real).to eq GMP::F(1)
|
44
|
+
expect(actual.imag).to eq GMP::F(1)
|
45
45
|
|
46
46
|
actual = op1.add(op2, MPC::MPC_RNDUU)
|
47
|
-
actual.real.
|
48
|
-
actual.imag.
|
47
|
+
expect(actual.real).to eq GMP::F(1)
|
48
|
+
expect(actual.imag).to eq GMP::F(1)
|
49
49
|
|
50
50
|
actual = op1.add(op2, MPC::MPC_RNDDD)
|
51
|
-
actual.real.
|
52
|
-
actual.imag.
|
51
|
+
expect(actual.real).to eq GMP::F(1)
|
52
|
+
expect(actual.imag).to eq GMP::F(1)
|
53
53
|
end
|
54
54
|
end
|
data/spec/add_spec.rb
CHANGED
@@ -2,31 +2,31 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
2
2
|
|
3
3
|
# All tests adapted from MPC 1.0.1's tests/add.dat
|
4
4
|
describe MPC, '#add' do
|
5
|
-
it '
|
5
|
+
it 'calculates the sum of two real MPCs' do
|
6
6
|
op1 = MPC.new([1, 0])
|
7
7
|
op2 = MPC.new([GMP::F("0x10000000000001p-105", 53, 16), GMP::F(0)])
|
8
8
|
actual = op1.add(op2, MPC::MPC_RNDNN)
|
9
|
-
actual.real.
|
10
|
-
actual.imag.
|
9
|
+
expect(actual.real).to eq GMP::F("0x10000000000001p-52", 53, 16)
|
10
|
+
expect(actual.imag).to eq GMP::F(0)
|
11
11
|
|
12
12
|
actual = op1.add(op2, MPC::MPC_RNDZZ)
|
13
|
-
actual.real.
|
14
|
-
actual.imag.
|
13
|
+
expect(actual.real).to eq GMP::F("0x10000000000000p-52", 53, 16)
|
14
|
+
expect(actual.imag).to eq GMP::F(0)
|
15
15
|
|
16
16
|
actual = op1.add(op2, MPC::MPC_RNDUU)
|
17
|
-
actual.real.
|
18
|
-
actual.imag.
|
17
|
+
expect(actual.real).to eq GMP::F("0x10000000000001p-52", 53, 16)
|
18
|
+
expect(actual.imag).to eq GMP::F(0)
|
19
19
|
|
20
20
|
actual = op1.add(op2, MPC::MPC_RNDDD)
|
21
|
-
actual.real.
|
22
|
-
actual.imag.
|
21
|
+
expect(actual.real).to eq GMP::F("0x10000000000000p-52", 53, 16)
|
22
|
+
expect(actual.imag).to eq GMP::F(0)
|
23
23
|
end
|
24
24
|
|
25
|
-
it '
|
25
|
+
it 'calculates the sum of two real MPCs' do
|
26
26
|
op2 = MPC.new([GMP::F(0), GMP::F("0x10000000000001p-105", 53, 16)])
|
27
27
|
op1 = MPC.new([0, 1])
|
28
28
|
actual = op1.add(op2, MPC::MPC_RNDNN)
|
29
|
-
actual.real.
|
30
|
-
actual.imag.
|
29
|
+
expect(actual.real).to eq GMP::F(0)
|
30
|
+
expect(actual.imag).to eq GMP::F("0x10000000000001p-52", 53, 16)
|
31
31
|
end
|
32
32
|
end
|
data/spec/arg_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe MPC, "#arg" do
|
4
|
+
it "returns the argument of an MPC generated with a Fixnum" do
|
5
|
+
expect(MPC.new(0).arg).to eq GMP::F(0)
|
6
|
+
expect(MPC.new(1).arg).to eq GMP::F(0)
|
7
|
+
expect(MPC.new([0, 1]).arg).to eq((2*Math::PI) / 4)
|
8
|
+
expect(MPC.new([1, 1]).arg).to eq((2*Math::PI) / 8)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the argument an MPC generated with a Float" do
|
12
|
+
expect(MPC.new([1.0, Math.sqrt(3)]).arg).to eq((2*Math::PI) / 6)
|
13
|
+
end
|
14
|
+
end
|
data/spec/asin_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
2
2
|
|
3
3
|
# All tests adapted from MPC 1.0.1's tests/asin.dat
|
4
4
|
describe MPC, '#sin' do
|
5
|
-
it '
|
5
|
+
it 'calculates the inverse sine of a pure real argument' do
|
6
6
|
data = [
|
7
7
|
[["-0x1921FB54442D18p-52", 53, 16], ["-0x1ECC2CAEC5160Ap-53", 53, 16], MPC.new([GMP::F(-1.5), -GMP::F(0)])],
|
8
8
|
[["-0x1921FB54442D18p-52", 53, 16], [ "0x1ECC2CAEC5160Ap-53", 53, 16], MPC.new([GMP::F(-1.5), GMP::F(0)])],
|
@@ -19,12 +19,12 @@ describe MPC, '#sin' do
|
|
19
19
|
]
|
20
20
|
data.each do |expected_real, expected_imag, input|
|
21
21
|
actual = input.asin
|
22
|
-
actual.real.
|
23
|
-
actual.imag.
|
22
|
+
expect(actual.real).to eq GMP::F.new(*expected_real)
|
23
|
+
expect(actual.imag).to eq GMP::F.new(*expected_imag)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it '
|
27
|
+
it 'calculates the inverse sine of a pure imaginary argument' do
|
28
28
|
data = [
|
29
29
|
[[-GMP::F(0)], ["-0x131DC0090B63D8p-52", 53, 16], MPC.new([-GMP::F(0), GMP::F(-1.5)])],
|
30
30
|
[[ GMP::F(0)], ["-0x131DC0090B63D8p-52", 53, 16], MPC.new([ GMP::F(0), GMP::F(-1.5)])],
|
@@ -41,26 +41,26 @@ describe MPC, '#sin' do
|
|
41
41
|
]
|
42
42
|
data.each do |expected_real, expected_imag, input|
|
43
43
|
actual = input.asin
|
44
|
-
actual.real.
|
45
|
-
actual.imag.
|
44
|
+
expect(actual.real).to eq GMP::F.new(*expected_real)
|
45
|
+
expect(actual.imag).to eq GMP::F.new(*expected_imag)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should calculate the inverse sine of ieee-754 double precision numbers' do
|
50
50
|
actual = MPC.new([GMP::F.new(17), GMP::F.new(42)]).asin(MPC::MPC_RNDNN)
|
51
|
-
actual.real.
|
52
|
-
actual.imag.
|
51
|
+
expect(actual.real).to eq GMP::F.new("0x189BF9EC7FCD5Bp-54", 53, 16)
|
52
|
+
expect(actual.imag).to eq GMP::F.new("0x1206ECFA94614Bp-50", 53, 16)
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'should calculate the inverse sine with other precisions' do
|
56
56
|
actual = MPC.new([GMP::F.new(96), GMP::F.new("0x1p-8", 2, 16)]).asin(MPC::MPC_RNDNN, 2)
|
57
|
-
actual.real.
|
58
|
-
actual.imag.
|
57
|
+
expect(actual.real).to eq GMP::F.new(1.5, 2)
|
58
|
+
expect(actual.imag).to eq GMP::F.new(6, 2)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should calculate the inverse sine with other precisions' do
|
62
62
|
actual = MPC.new([GMP::F.new(96), GMP::F.new("0x1p-8", 2, 16)]).asin(MPC::MPC_RNDNN, 8)
|
63
|
-
actual.real.
|
64
|
-
actual.imag.
|
63
|
+
expect(actual.real).to eq GMP::F.new("0xC9p-7", 8, 16)
|
64
|
+
expect(actual.imag).to eq GMP::F.new("0x15p-2", 8, 16)
|
65
65
|
end
|
66
66
|
end
|