gnu_mpc 0.8.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.
- data/COPYING.md +13 -0
- data/Gemfile +17 -0
- data/Guardfile +18 -0
- data/Makefile +12 -0
- data/README.md +47 -0
- data/Rakefile +54 -0
- data/ext/extconf.rb +46 -0
- data/ext/mpc.c +1010 -0
- data/ext/mpcrnd.c +194 -0
- data/ext/ruby_gmp.h +343 -0
- data/ext/ruby_mpc.h +63 -0
- data/lib/mpc.rb +30 -0
- data/manual.md +933 -0
- data/manual.pdf +0 -0
- data/manual_template.latex +177 -0
- data/spec/acos_spec.rb +66 -0
- data/spec/add_args_spec.rb +51 -0
- data/spec/add_fr_spec.rb +54 -0
- data/spec/add_spec.rb +32 -0
- data/spec/asin_spec.rb +66 -0
- data/spec/atan_spec.rb +109 -0
- data/spec/conj_spec.rb +56 -0
- data/spec/cos_spec.rb +54 -0
- data/spec/cosh_spec.rb +26 -0
- data/spec/exp_spec.rb +62 -0
- data/spec/hash_arguments_spec.rb +17 -0
- data/spec/log_spec.rb +37 -0
- data/spec/mpc_single_function_args_spec.rb +41 -0
- data/spec/neg_spec.rb +30 -0
- data/spec/new_spec.rb +97 -0
- data/spec/proj_spec.rb +20 -0
- data/spec/real_spec.rb +23 -0
- data/spec/rounding_spec.rb +199 -0
- data/spec/sin_spec.rb +66 -0
- data/spec/sinh_spec.rb +65 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/sqr_spec.rb +96 -0
- data/spec/sqrt_spec.rb +72 -0
- data/spec/sub_spec.rb +50 -0
- data/spec/tan_spec.rb +55 -0
- data/spec/tanh_spec.rb +53 -0
- data/spec/to_s_spec.rb +77 -0
- data/spec/version_spec.rb +7 -0
- metadata +91 -0
data/ext/mpcrnd.c
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
#include <ruby_mpc.h>
|
2
|
+
|
3
|
+
VALUE r_mpcrnd_initialize(int argc, VALUE *argv, VALUE self);
|
4
|
+
|
5
|
+
VALUE r_mpcrndsg_new(int argc, VALUE *argv, VALUE klass)
|
6
|
+
{
|
7
|
+
VALUE res;
|
8
|
+
int *res_value;
|
9
|
+
(void)klass;
|
10
|
+
res_value = 0;
|
11
|
+
|
12
|
+
mpcrnd_make_struct(res, res_value);
|
13
|
+
rb_obj_call_init(res, argc, argv);
|
14
|
+
return res;
|
15
|
+
}
|
16
|
+
|
17
|
+
/*
|
18
|
+
* MPC_RNDNN 0000 0000
|
19
|
+
* MPC_RNDNZ 0001 0000
|
20
|
+
* MPC_RNDNU 0010 0000
|
21
|
+
* MPC_RNDND 0011 0000
|
22
|
+
* MPC_RNDNA ---- ----
|
23
|
+
* MPC_RNDZN 0000 0001
|
24
|
+
* MPC_RNDZZ 0001 0001
|
25
|
+
* MPC_RNDZU 0010 0001
|
26
|
+
* MPC_RNDZD 0011 0001
|
27
|
+
* MPC_RNDZA ---- ----
|
28
|
+
* MPC_RNDUN 0000 0010
|
29
|
+
* MPC_RNDUZ 0001 0010
|
30
|
+
* MPC_RNDUU 0010 0010
|
31
|
+
* MPC_RNDUD 0011 0010
|
32
|
+
* MPC_RNDUA ---- ----
|
33
|
+
* MPC_RNDDN 0000 0011
|
34
|
+
* MPC_RNDDZ 0001 0011
|
35
|
+
* MPC_RNDDU 0010 0011
|
36
|
+
* MPC_RNDDD 0011 0011
|
37
|
+
* MPC_RNDDA ---- ----
|
38
|
+
* MPC_RNDAN ---- ----
|
39
|
+
* MPC_RNDAZ ---- ----
|
40
|
+
* MPC_RNDAU ---- ----
|
41
|
+
* MPC_RNDAD ---- ----
|
42
|
+
* MPC_RNDAA ---- ----
|
43
|
+
*/
|
44
|
+
VALUE r_mpcrnd_initialize(int argc, VALUE *argv, VALUE self)
|
45
|
+
{
|
46
|
+
VALUE mode, name, ieee754;
|
47
|
+
mode = argv[0];
|
48
|
+
(void)argc;
|
49
|
+
char name_val[12];
|
50
|
+
|
51
|
+
switch (FIX2INT(mode) % 16) {
|
52
|
+
case 0:
|
53
|
+
sprintf(name_val, "MPC_RNDN");
|
54
|
+
ieee754 = rb_str_new2("(roundTiesToEven,");
|
55
|
+
break;
|
56
|
+
case 1:
|
57
|
+
sprintf(name_val, "MPC_RNDZ");
|
58
|
+
ieee754 = rb_str_new2("(roundTowardZero,");
|
59
|
+
break;
|
60
|
+
case 2:
|
61
|
+
sprintf(name_val, "MPC_RNDU");
|
62
|
+
ieee754 = rb_str_new2("(roundTowardPositive,");
|
63
|
+
break;
|
64
|
+
case 3:
|
65
|
+
sprintf(name_val, "MPC_RNDD");
|
66
|
+
ieee754 = rb_str_new2("(roundTowardNegative,");
|
67
|
+
break;
|
68
|
+
default:
|
69
|
+
sprintf(name_val, "MPC_RNDN");
|
70
|
+
ieee754 = rb_str_new2("(roundTiesToEven,");
|
71
|
+
}
|
72
|
+
|
73
|
+
switch (FIX2INT(mode) >> 4) {
|
74
|
+
case 0:
|
75
|
+
sprintf(name_val, "%sN", name_val);
|
76
|
+
rb_str_cat(ieee754, "roundTiesToEven)", 16);
|
77
|
+
break;
|
78
|
+
case 1:
|
79
|
+
sprintf(name_val, "%sZ", name_val);
|
80
|
+
rb_str_cat(ieee754, "roundTowardZero)", 16);
|
81
|
+
break;
|
82
|
+
case 2:
|
83
|
+
sprintf(name_val, "%sU", name_val);
|
84
|
+
rb_str_cat(ieee754, "roundTowardPositive)", 20);
|
85
|
+
break;
|
86
|
+
case 3:
|
87
|
+
sprintf(name_val, "%sD", name_val);
|
88
|
+
rb_str_cat(ieee754, "roundTowardNegative)", 20);
|
89
|
+
break;
|
90
|
+
default:
|
91
|
+
sprintf(name_val, "%sN", name_val);
|
92
|
+
rb_str_cat(ieee754, "roundTiesToEven)", 16);
|
93
|
+
}
|
94
|
+
|
95
|
+
name = rb_str_new2(name_val);
|
96
|
+
rb_iv_set (self, "@mode", mode);
|
97
|
+
rb_iv_set (self, "@name", name);
|
98
|
+
rb_iv_set (self, "@ieee754", ieee754);
|
99
|
+
return Qnil;
|
100
|
+
}
|
101
|
+
|
102
|
+
VALUE r_mpcrnd_inspect(VALUE self)
|
103
|
+
{
|
104
|
+
return rb_iv_get (self, "@name");
|
105
|
+
}
|
106
|
+
|
107
|
+
mpc_rnd_t r_get_default_mpc_rounding_mode()
|
108
|
+
{
|
109
|
+
return r_get_mpc_rounding_mode (rb_const_get (cMPC, rb_intern ("MPC_RNDNN")));
|
110
|
+
}
|
111
|
+
|
112
|
+
mpc_rnd_t r_mpc_get_rounding_mode(VALUE rnd)
|
113
|
+
{
|
114
|
+
VALUE mode;
|
115
|
+
|
116
|
+
if (MPCRND_P(rnd)) {
|
117
|
+
mode = rb_funcall (rnd, rb_intern("mode"), 0);
|
118
|
+
if (FIX2INT(mode) < 0 || FIX2INT(mode) > 51) {
|
119
|
+
rb_raise(rb_eRangeError, "rounding mode must be one of the rounding mode constants.");
|
120
|
+
}
|
121
|
+
} else {
|
122
|
+
rb_raise(rb_eTypeError, "rounding mode must be one of the rounding mode constants.");
|
123
|
+
}
|
124
|
+
|
125
|
+
switch (FIX2INT (mode)) {
|
126
|
+
case 0:
|
127
|
+
return MPC_RNDNN;
|
128
|
+
case 1:
|
129
|
+
return MPC_RNDZN;
|
130
|
+
case 2:
|
131
|
+
return MPC_RNDUN;
|
132
|
+
case 3:
|
133
|
+
return MPC_RNDDN;
|
134
|
+
case 16:
|
135
|
+
return MPC_RNDNZ;
|
136
|
+
case 17:
|
137
|
+
return MPC_RNDZZ;
|
138
|
+
case 18:
|
139
|
+
return MPC_RNDUZ;
|
140
|
+
case 19:
|
141
|
+
return MPC_RNDDZ;
|
142
|
+
case 32:
|
143
|
+
return MPC_RNDNU;
|
144
|
+
case 33:
|
145
|
+
return MPC_RNDZU;
|
146
|
+
case 34:
|
147
|
+
return MPC_RNDUU;
|
148
|
+
case 35:
|
149
|
+
return MPC_RNDDU;
|
150
|
+
case 48:
|
151
|
+
return MPC_RNDND;
|
152
|
+
case 49:
|
153
|
+
return MPC_RNDZD;
|
154
|
+
case 50:
|
155
|
+
return MPC_RNDUD;
|
156
|
+
case 51:
|
157
|
+
return MPC_RNDDD;
|
158
|
+
default:
|
159
|
+
return MPC_RNDNN;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
void init_mpcrnd()
|
164
|
+
{
|
165
|
+
cMPC = rb_define_class ("MPC", rb_cNumeric);
|
166
|
+
ID new_id = rb_intern ("new");
|
167
|
+
|
168
|
+
cMPC_Rnd = rb_define_class_under (cMPC, "Rnd", rb_cObject);
|
169
|
+
|
170
|
+
rb_define_singleton_method (cMPC_Rnd, "new", r_mpcrndsg_new, -1);
|
171
|
+
rb_define_method (cMPC_Rnd, "initialize", r_mpcrnd_initialize, -1);
|
172
|
+
rb_define_method (cMPC_Rnd, "inspect", r_mpcrnd_inspect, 0);
|
173
|
+
|
174
|
+
rb_define_attr (cMPC_Rnd, "mode", 1, 0);
|
175
|
+
rb_define_attr (cMPC_Rnd, "name", 1, 0);
|
176
|
+
rb_define_attr (cMPC_Rnd, "ieee754", 1, 0);
|
177
|
+
|
178
|
+
rb_define_const(cMPC, "MPC_RNDNN", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(0)));
|
179
|
+
rb_define_const(cMPC, "MPC_RNDNZ", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(16)));
|
180
|
+
rb_define_const(cMPC, "MPC_RNDNU", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(32)));
|
181
|
+
rb_define_const(cMPC, "MPC_RNDND", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(48)));
|
182
|
+
rb_define_const(cMPC, "MPC_RNDZN", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(1)));
|
183
|
+
rb_define_const(cMPC, "MPC_RNDZZ", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(17)));
|
184
|
+
rb_define_const(cMPC, "MPC_RNDZU", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(33)));
|
185
|
+
rb_define_const(cMPC, "MPC_RNDZD", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(49)));
|
186
|
+
rb_define_const(cMPC, "MPC_RNDUN", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(2)));
|
187
|
+
rb_define_const(cMPC, "MPC_RNDUZ", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(18)));
|
188
|
+
rb_define_const(cMPC, "MPC_RNDUU", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(34)));
|
189
|
+
rb_define_const(cMPC, "MPC_RNDUD", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(50)));
|
190
|
+
rb_define_const(cMPC, "MPC_RNDDN", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(3)));
|
191
|
+
rb_define_const(cMPC, "MPC_RNDDZ", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(19)));
|
192
|
+
rb_define_const(cMPC, "MPC_RNDDU", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(35)));
|
193
|
+
rb_define_const(cMPC, "MPC_RNDDD", rb_funcall (cMPC_Rnd, new_id, 1, INT2FIX(51)));
|
194
|
+
}
|
data/ext/ruby_gmp.h
ADDED
@@ -0,0 +1,343 @@
|
|
1
|
+
#ifndef _RUBY_GMP_H_
|
2
|
+
#define _RUBY_GMP_H_
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <ruby.h>
|
6
|
+
#ifndef _GNU_SOURCE
|
7
|
+
#define _GNU_SOURCE
|
8
|
+
#endif
|
9
|
+
#include <gmp.h>
|
10
|
+
#include <mpfr.h>
|
11
|
+
#include <mpf2mpfr.h>
|
12
|
+
|
13
|
+
#include <stdlib.h>
|
14
|
+
|
15
|
+
/*
|
16
|
+
MP_INT*, MP_RAT* and MP_FLOAT* are used because they don't have side-effects
|
17
|
+
of single-element arrays mp*_t
|
18
|
+
|
19
|
+
MP_FLOAT is defined here, as it's commented out in gmp.h
|
20
|
+
*/
|
21
|
+
typedef __mpfr_struct MP_FLOAT;
|
22
|
+
|
23
|
+
#if __GNU_MP_VERSION < 5
|
24
|
+
typedef unsigned long int mp_bitcnt_t;
|
25
|
+
#endif
|
26
|
+
|
27
|
+
/*
|
28
|
+
I don't like this solution, because in gmp.h, all of these typedefs are
|
29
|
+
marked with "gmp 1 source compatibility". :(.
|
30
|
+
*/
|
31
|
+
typedef __gmp_randstate_struct MP_RANDSTATE;
|
32
|
+
|
33
|
+
#define mpz_get_struct(ruby_var,c_var) { Data_Get_Struct(ruby_var, MP_INT, c_var); }
|
34
|
+
#define mpq_get_struct(ruby_var,c_var) { Data_Get_Struct(ruby_var, MP_RAT, c_var); }
|
35
|
+
#define mpf_get_struct(ruby_var,c_var) { Data_Get_Struct(ruby_var, MP_FLOAT, c_var); }
|
36
|
+
#define mprandstate_get_struct(ruby_var,c_var) { Data_Get_Struct(ruby_var, MP_RANDSTATE, c_var); }
|
37
|
+
#define mpz_make_struct(ruby_var,c_var) { ruby_var = Data_Make_Struct(cGMP_Z, MP_INT, 0, r_gmpz_free, c_var); }
|
38
|
+
#define mpq_make_struct(ruby_var,c_var) { ruby_var = Data_Make_Struct(cGMP_Q, MP_RAT, 0, r_gmpq_free, c_var); }
|
39
|
+
#define mpf_make_struct(ruby_var,c_var) { ruby_var = Data_Make_Struct(cGMP_F, MP_FLOAT, 0, r_gmpf_free, c_var); }
|
40
|
+
#define mprandstate_make_struct(ruby_var,c_var) { ruby_var = Data_Make_Struct(cGMP_RandState, MP_RANDSTATE, 0, r_gmprandstate_free, c_var); }
|
41
|
+
#define mpz_make_struct_init(ruby_var,c_var) { mpz_make_struct(ruby_var,c_var); mpz_init (c_var); }
|
42
|
+
#define mpq_make_struct_init(ruby_var,c_var) { mpq_make_struct(ruby_var,c_var); mpq_init (c_var); }
|
43
|
+
#define BIGNUM_P(value) (TYPE(value) == T_BIGNUM)
|
44
|
+
#define FLOAT_P(value) (TYPE(value) == T_FLOAT)
|
45
|
+
#define STRING_P(value) (TYPE(value) == T_STRING)
|
46
|
+
#define ARRAY_P(value) (TYPE(value) == T_ARRAY)
|
47
|
+
#define GMPZ_P(value) (rb_obj_is_instance_of(value, cGMP_Z) == Qtrue)
|
48
|
+
#define GMPQ_P(value) (rb_obj_is_instance_of(value, cGMP_Q) == Qtrue)
|
49
|
+
#define GMPF_P(value) (rb_obj_is_instance_of(value, cGMP_F) == Qtrue)
|
50
|
+
#define mpz_set_bignum(var_mpz,var_bignum) { \
|
51
|
+
VALUE tmp = rb_funcall (rb_funcall (var_bignum, rb_intern ("to_s"), 1, INT2FIX(32)), rb_intern("upcase"), 0); \
|
52
|
+
mpz_set_str (var_mpz, StringValuePtr (tmp), 32); \
|
53
|
+
}
|
54
|
+
/*VALUE tmp = rb_funcall (var_bignum, rb_intern ("to_s"), 1, INT2FIX(32)); \*/
|
55
|
+
/*#define mpz_set_bignum(var_mpz,var_bignum) { \
|
56
|
+
VALUE tmp = rb_funcall (var_bignum, rb_intern ("to_s"), 0); \
|
57
|
+
mpz_set_str (var_mpz, StringValuePtr (tmp), 10); \
|
58
|
+
}*/
|
59
|
+
#define mpz_temp_alloc(var) { var=malloc(sizeof(MP_INT)); }
|
60
|
+
#define mpz_temp_init(var) { mpz_temp_alloc(var); mpz_init(var); }
|
61
|
+
#define mpz_temp_from_bignum(var,var_bignum) { \
|
62
|
+
mpz_temp_alloc(var); \
|
63
|
+
VALUE tmp = rb_funcall (var_bignum, rb_intern ("to_s"), 1, INT2FIX(32)); \
|
64
|
+
mpz_init_set_str (var, StringValuePtr (tmp), 32); \
|
65
|
+
}
|
66
|
+
#define mpz_temp_free(var) { mpz_clear(var); free(var); }
|
67
|
+
#define mpf_temp_alloc(var) { var=malloc(sizeof(MP_FLOAT)); }
|
68
|
+
#if defined(MPFR) && defined(HAVE_MPFR_H)
|
69
|
+
#define prec_max(prec,var) {if(mpfr_get_prec(var) > prec) prec = mpfr_get_prec(var); }
|
70
|
+
#else
|
71
|
+
#define prec_max(prec,var) {if(mpf_get_prec(var) > prec) prec = mpf_get_prec(var); }
|
72
|
+
#endif
|
73
|
+
|
74
|
+
#define mpf_get_struct_prec(ruby_var,c_var,prec) { mpf_get_struct(ruby_var,c_var); prec = mpfr_get_prec(c_var); }
|
75
|
+
#define mpf_make_struct_init(ruby_var,c_var,prec) { mpf_make_struct(ruby_var,c_var); mpfr_init2 (c_var,prec); }
|
76
|
+
#define mpf_temp_init(var,prec) { mpf_temp_alloc(var); mpfr_init2(var,prec); }
|
77
|
+
#define mpf_temp_free(var) { mpfr_clear(var); free(var); }
|
78
|
+
#define r_mpf_init(var1) (mpfr_init(var1))
|
79
|
+
#define r_mpf_init2(var1, var2) (mpfr_init2(var1, var2))
|
80
|
+
#define r_mpf_set_z(var1, var2) (mpfr_set_z(var1, var2, __gmp_default_rounding_mode))
|
81
|
+
#define r_mpf_set_q(var1, var2) (mpfr_set_q(var1, var2, __gmp_default_rounding_mode))
|
82
|
+
#define r_mpf_set_d(var1, var2) (mpfr_set_d(var1, var2, __gmp_default_rounding_mode))
|
83
|
+
#define r_mpf_set_str(var1, var2, var3) (mpfr_set_str(var1, var2, var3, __gmp_default_rounding_mode))
|
84
|
+
#define r_mpf_cmp(var1, var2) (mpfr_cmp(var1, var2))
|
85
|
+
|
86
|
+
#ifdef FIXNUM_WIDTH /* RBX check */
|
87
|
+
#if (((8*SIZEOF_INTPTR_T) - TAG_FIXNUM_SHIFT -1) == 63) /* 64-bit */
|
88
|
+
#define FIX2NUM(x) FIX2LONG(x)
|
89
|
+
#else /* 32-bit */
|
90
|
+
#define FIX2NUM(x) FIX2INT(x)
|
91
|
+
#endif
|
92
|
+
#else /* RBX check */
|
93
|
+
#if SIZEOF_INT < SIZEOF_LONG /* 64-bit */
|
94
|
+
#define FIX2NUM(x) FIX2LONG(x)
|
95
|
+
#else /* 32-bit */
|
96
|
+
#define FIX2NUM(x) FIX2INT(x)
|
97
|
+
#endif /* MRI's 32-vs-64 check */
|
98
|
+
#endif /* RBX check */
|
99
|
+
|
100
|
+
#define EXPECTED_ZQFXBD "Expected GMP::Z, GMP::Q, GMP::F, Fixnum, Bignum or Float"
|
101
|
+
#define EXPECTED_ZQFXB "Expected GMP::Z, GMP::Q, GMP::F, Fixnum or Bignum"
|
102
|
+
#define EXPECTED_ZFXBD "Expected GMP::Z, GMP::F, Fixnum, Bignum or Float"
|
103
|
+
#define EXPECTED_ZXB "Expected GMP::Z, Fixnum or Bignum"
|
104
|
+
#define EXPECTED_ZX "Expected GMP::Z or Fixnum"
|
105
|
+
#define EXPECTED_X "Expected Fixnum"
|
106
|
+
#define EXPECTED_Z "Expected GMP::Z"
|
107
|
+
#define EXPECTED_FD "Expected GMP::F or Float"
|
108
|
+
#define typeerror(expected) rb_raise(rb_eTypeError, EXPECTED_##expected)
|
109
|
+
#define typeerror_as(expected, argname) rb_raise(rb_eTypeError, EXPECTED_##expected " as " argname)
|
110
|
+
|
111
|
+
//should change exception type
|
112
|
+
#define not_yet rb_raise(rb_eTypeError,"Not implemented yet")
|
113
|
+
|
114
|
+
#define mprnd_get_struct(ruby_var,c_var) { Data_Get_Struct(ruby_var, int, c_var); }
|
115
|
+
#define mprnd_make_struct(ruby_var,c_var) { ruby_var = Data_Make_Struct(cGMP_Rnd, int, 0, 0, c_var); }
|
116
|
+
#define GMPRND_P(value) (rb_obj_is_instance_of(value, cGMP_Rnd) == Qtrue)
|
117
|
+
|
118
|
+
extern VALUE mGMP, cGMP_Z, cGMP_Q, cGMP_F, cGMP_RandState;
|
119
|
+
extern VALUE cGMP_Rnd;
|
120
|
+
|
121
|
+
extern void r_gmpz_free(void *ptr);
|
122
|
+
extern void r_gmpq_free(void *ptr);
|
123
|
+
extern void r_gmpf_free(void *ptr);
|
124
|
+
extern void r_gmprandstate_free(void *ptr);
|
125
|
+
|
126
|
+
|
127
|
+
/* from gmpz.h */
|
128
|
+
|
129
|
+
// Initializing, Assigning Integers
|
130
|
+
extern VALUE r_gmpzsg_new(int argc, VALUE *argv, VALUE klass);
|
131
|
+
extern VALUE r_gmpz_initialize(int argc, VALUE *argv, VALUE self);
|
132
|
+
extern void mpz_set_value(MP_INT *target, VALUE source);
|
133
|
+
extern VALUE r_gmpmod_z(int argc, VALUE *argv, VALUE module);
|
134
|
+
extern VALUE r_gmpz_swap(VALUE self, VALUE arg);
|
135
|
+
|
136
|
+
// Converting Integers
|
137
|
+
extern VALUE r_gmpz_to_i(VALUE self);
|
138
|
+
extern VALUE r_gmpz_to_d(VALUE self);
|
139
|
+
extern VALUE r_gmpz_to_s(int argc, VALUE *argv, VALUE self);
|
140
|
+
|
141
|
+
// Integer Arithmetic
|
142
|
+
extern VALUE r_gmpz_add(VALUE self, VALUE arg);
|
143
|
+
extern VALUE r_gmpz_add_self(VALUE self, VALUE arg);
|
144
|
+
extern VALUE r_gmpz_sub(VALUE self, VALUE arg);
|
145
|
+
extern VALUE r_gmpz_sub_self(VALUE self, VALUE arg);
|
146
|
+
extern VALUE r_gmpz_mul(VALUE self, VALUE arg);
|
147
|
+
extern VALUE r_gmpz_div(VALUE self, VALUE arg);
|
148
|
+
|
149
|
+
// Integer Division
|
150
|
+
extern VALUE r_gmpz_mod(VALUE self, VALUE arg);
|
151
|
+
|
152
|
+
// Integer Exponentiation
|
153
|
+
extern VALUE r_gmpzsg_pow(VALUE klass, VALUE base, VALUE exp);
|
154
|
+
extern VALUE r_gmpz_powm(VALUE self, VALUE exp, VALUE mod);
|
155
|
+
|
156
|
+
// Integer Roots
|
157
|
+
|
158
|
+
// Number Theoretic Functions
|
159
|
+
extern VALUE r_gmpz_is_probab_prime(int argc, VALUE* argv, VALUE self);
|
160
|
+
extern VALUE r_gmpz_gcd(VALUE self, VALUE arg);
|
161
|
+
extern VALUE r_gmpz_invert(VALUE self, VALUE arg);
|
162
|
+
extern VALUE r_gmpz_jacobi(VALUE self, VALUE b);
|
163
|
+
extern VALUE r_gmpzsg_jacobi(VALUE klass, VALUE a, VALUE b);
|
164
|
+
extern VALUE r_gmpz_legendre(VALUE self, VALUE p);
|
165
|
+
extern VALUE r_gmpz_remove(VALUE self, VALUE arg);
|
166
|
+
|
167
|
+
// Integer Comparisons
|
168
|
+
extern VALUE r_gmpz_eq(VALUE self, VALUE arg);
|
169
|
+
extern VALUE r_gmpz_cmp(VALUE self, VALUE arg);
|
170
|
+
extern VALUE r_gmpz_cmpabs(VALUE self, VALUE arg);
|
171
|
+
extern VALUE r_gmpz_sgn(VALUE self);
|
172
|
+
extern int mpz_cmp_value(MP_INT *OP, VALUE arg);
|
173
|
+
|
174
|
+
// Integer Logic and Bit Fiddling
|
175
|
+
extern VALUE r_gmpz_popcount(VALUE self);
|
176
|
+
extern VALUE r_gmpz_scan0(VALUE self, VALUE bitnr);
|
177
|
+
extern VALUE r_gmpz_scan1(VALUE self, VALUE bitnr);
|
178
|
+
extern VALUE r_gmpz_setbit(VALUE self, VALUE bitnr, VALUE set_to);
|
179
|
+
extern VALUE r_gmpz_getbit(VALUE self, VALUE bitnr);
|
180
|
+
|
181
|
+
// Miscelaneous Integer Functions
|
182
|
+
extern VALUE r_gmpz_sizeinbase(VALUE self, VALUE base);
|
183
|
+
extern VALUE r_gmpz_size_in_bin(VALUE self);
|
184
|
+
|
185
|
+
|
186
|
+
/* from gmpq.h */
|
187
|
+
|
188
|
+
// Initializing Rationals
|
189
|
+
extern VALUE r_gmpqsg_new(int argc, VALUE *argv, VALUE klass);
|
190
|
+
extern VALUE r_gmpq_initialize(int argc, VALUE *argv, VALUE self);
|
191
|
+
extern VALUE r_gmpmod_q(int argc, VALUE *argv, VALUE module);
|
192
|
+
extern VALUE r_gmpq_swap(VALUE self, VALUE arg);
|
193
|
+
|
194
|
+
// Rational Conversions
|
195
|
+
extern VALUE r_gmpq_to_d(VALUE self);
|
196
|
+
extern VALUE r_gmpq_to_s(VALUE self);
|
197
|
+
|
198
|
+
// Rational Arithmetic
|
199
|
+
extern VALUE r_gmpq_add(VALUE self, VALUE arg);
|
200
|
+
extern VALUE r_gmpq_sub(VALUE self, VALUE arg);
|
201
|
+
extern VALUE r_gmpq_mul(VALUE self, VALUE arg);
|
202
|
+
extern VALUE r_gmpq_div(VALUE self, VALUE arg);
|
203
|
+
extern VALUE r_gmpq_inv(VALUE self);
|
204
|
+
extern VALUE r_gmpq_inv_self(VALUE self);
|
205
|
+
|
206
|
+
// Comparing Rationals
|
207
|
+
extern VALUE r_gmpq_eq(VALUE self, VALUE arg);
|
208
|
+
extern VALUE r_gmpq_cmp(VALUE self, VALUE arg);
|
209
|
+
extern int mpq_cmp_value(MP_RAT *OP, VALUE arg);
|
210
|
+
extern VALUE r_gmpq_sgn(VALUE self);
|
211
|
+
|
212
|
+
// Applying Integer Functions
|
213
|
+
extern VALUE r_gmpq_num(VALUE self);
|
214
|
+
extern VALUE r_gmpq_den(VALUE self);
|
215
|
+
|
216
|
+
// _unsorted_
|
217
|
+
|
218
|
+
|
219
|
+
/* from gmpf.h */
|
220
|
+
|
221
|
+
// Initializing, Assigning Floats
|
222
|
+
extern VALUE r_gmpfsg_new(int argc, VALUE *argv, VALUE klass);
|
223
|
+
extern VALUE r_gmpf_initialize(int argc, VALUE *argv, VALUE self);
|
224
|
+
extern void mpf_set_value(MP_FLOAT *self_val, VALUE arg);
|
225
|
+
extern VALUE r_gmpmod_f(int argc, VALUE *argv, VALUE module);
|
226
|
+
extern VALUE r_gmpf_get_prec(VALUE self);
|
227
|
+
extern VALUE r_gmpf_set_prec(VALUE self, VALUE arg);
|
228
|
+
extern VALUE r_gmpf_set_prec_raw(VALUE self, VALUE arg);
|
229
|
+
|
230
|
+
// Converting Floats
|
231
|
+
extern VALUE r_gmpf_to_d(VALUE self);
|
232
|
+
extern VALUE r_gmpf_to_s(VALUE self);
|
233
|
+
|
234
|
+
// Float Arithmetic
|
235
|
+
extern VALUE r_gmpf_add(VALUE self, VALUE arg);
|
236
|
+
extern VALUE r_gmpf_mul(VALUE self, VALUE arg);
|
237
|
+
extern VALUE r_gmpf_sub(VALUE self, VALUE arg);
|
238
|
+
extern VALUE r_gmpf_div(VALUE self, VALUE arg);
|
239
|
+
|
240
|
+
// Float Comparison
|
241
|
+
extern VALUE r_gmpf_eq(VALUE self, VALUE arg);
|
242
|
+
extern VALUE r_gmpf_cmp(VALUE self, VALUE arg);
|
243
|
+
extern int mpf_cmp_value(MP_FLOAT *OP, VALUE arg);
|
244
|
+
|
245
|
+
// MPFR
|
246
|
+
extern void mpf_set_value2(MP_FLOAT *self_val, VALUE arg, int base);
|
247
|
+
|
248
|
+
extern VALUE r_gmpfr_sqrt(int argc, VALUE *argv, VALUE self);
|
249
|
+
extern VALUE r_gmpfr_rec_sqrt(int argc, VALUE *argv, VALUE self);
|
250
|
+
extern VALUE r_gmpfr_cbrt(int argc, VALUE *argv, VALUE self);
|
251
|
+
|
252
|
+
extern VALUE r_gmpfr_log(int argc, VALUE *argv, VALUE self);
|
253
|
+
extern VALUE r_gmpfr_log2(int argc, VALUE *argv, VALUE self);
|
254
|
+
extern VALUE r_gmpfr_log10(int argc, VALUE *argv, VALUE self);
|
255
|
+
extern VALUE r_gmpfr_exp(int argc, VALUE *argv, VALUE self);
|
256
|
+
extern VALUE r_gmpfr_exp2(int argc, VALUE *argv, VALUE self);
|
257
|
+
extern VALUE r_gmpfr_exp10(int argc, VALUE *argv, VALUE self);
|
258
|
+
extern VALUE r_gmpfr_cos(int argc, VALUE *argv, VALUE self);
|
259
|
+
extern VALUE r_gmpfr_sin(int argc, VALUE *argv, VALUE self);
|
260
|
+
extern VALUE r_gmpfr_tan(int argc, VALUE *argv, VALUE self);
|
261
|
+
extern VALUE r_gmpfr_sec(int argc, VALUE *argv, VALUE self);
|
262
|
+
extern VALUE r_gmpfr_csc(int argc, VALUE *argv, VALUE self);
|
263
|
+
extern VALUE r_gmpfr_cot(int argc, VALUE *argv, VALUE self);
|
264
|
+
|
265
|
+
extern VALUE r_gmpfr_acos(int argc, VALUE *argv, VALUE self);
|
266
|
+
extern VALUE r_gmpfr_asin(int argc, VALUE *argv, VALUE self);
|
267
|
+
extern VALUE r_gmpfr_atan(int argc, VALUE *argv, VALUE self);
|
268
|
+
|
269
|
+
extern VALUE r_gmpfr_cosh(int argc, VALUE *argv, VALUE self);
|
270
|
+
extern VALUE r_gmpfr_sinh(int argc, VALUE *argv, VALUE self);
|
271
|
+
extern VALUE r_gmpfr_tanh(int argc, VALUE *argv, VALUE self);
|
272
|
+
|
273
|
+
extern VALUE r_gmpfr_sech(int argc, VALUE *argv, VALUE self);
|
274
|
+
extern VALUE r_gmpfr_csch(int argc, VALUE *argv, VALUE self);
|
275
|
+
extern VALUE r_gmpfr_coth(int argc, VALUE *argv, VALUE self);
|
276
|
+
extern VALUE r_gmpfr_acosh(int argc, VALUE *argv, VALUE self);
|
277
|
+
extern VALUE r_gmpfr_asinh(int argc, VALUE *argv, VALUE self);
|
278
|
+
extern VALUE r_gmpfr_atanh(int argc, VALUE *argv, VALUE self);
|
279
|
+
|
280
|
+
extern VALUE r_gmpfr_log1p(int argc, VALUE *argv, VALUE self);
|
281
|
+
extern VALUE r_gmpfr_expm1(int argc, VALUE *argv, VALUE self);
|
282
|
+
extern VALUE r_gmpfr_eint(int argc, VALUE *argv, VALUE self);
|
283
|
+
extern VALUE r_gmpfr_li2(int argc, VALUE *argv, VALUE self);
|
284
|
+
extern VALUE r_gmpfr_gamma(int argc, VALUE *argv, VALUE self);
|
285
|
+
extern VALUE r_gmpfr_lngamma(int argc, VALUE *argv, VALUE self);
|
286
|
+
/*extern VALUE r_gmpfr_lgamma(int argc, VALUE *argv, VALUE self);*/
|
287
|
+
#if MPFR_VERSION_MAJOR > 2
|
288
|
+
extern VALUE r_gmpfr_digamma(int argc, VALUE *argv, VALUE self);
|
289
|
+
#endif
|
290
|
+
extern VALUE r_gmpfr_zeta(int argc, VALUE *argv, VALUE self);
|
291
|
+
extern VALUE r_gmpfr_erf(int argc, VALUE *argv, VALUE self);
|
292
|
+
extern VALUE r_gmpfr_erfc(int argc, VALUE *argv, VALUE self);
|
293
|
+
extern VALUE r_gmpfr_j0(int argc, VALUE *argv, VALUE self);
|
294
|
+
extern VALUE r_gmpfr_j1(int argc, VALUE *argv, VALUE self);
|
295
|
+
extern VALUE r_gmpfr_jn(int argc, VALUE *argv, VALUE self);
|
296
|
+
extern VALUE r_gmpfr_y0(int argc, VALUE *argv, VALUE self);
|
297
|
+
extern VALUE r_gmpfr_y1(int argc, VALUE *argv, VALUE self);
|
298
|
+
|
299
|
+
extern VALUE r_gmpfrsg_const_log2();
|
300
|
+
extern VALUE r_gmpfrsg_const_pi();
|
301
|
+
extern VALUE r_gmpfrsg_const_euler();
|
302
|
+
extern VALUE r_gmpfrsg_const_catalan();
|
303
|
+
|
304
|
+
extern mp_rnd_t r_get_rounding_mode(VALUE rnd);
|
305
|
+
|
306
|
+
// _unsorted_
|
307
|
+
extern VALUE r_gmpf_sgn(VALUE self);
|
308
|
+
|
309
|
+
|
310
|
+
/* from gmprandstate.h */
|
311
|
+
|
312
|
+
// Random State Initialization
|
313
|
+
extern VALUE r_gmprandstatesg_new(int argc, VALUE *argv, VALUE klass);
|
314
|
+
extern VALUE r_gmprandstate_initialize(int argc, VALUE *argv, VALUE self);
|
315
|
+
extern VALUE r_gmpmod_randstate(int argc, VALUE *argv, VALUE module);
|
316
|
+
|
317
|
+
// Random State Seeding
|
318
|
+
extern VALUE r_gmprandstate_seed(VALUE self, VALUE arg);
|
319
|
+
|
320
|
+
// Integer Random Numbers
|
321
|
+
extern VALUE r_gmprandstate_urandomb(VALUE self, VALUE arg);
|
322
|
+
extern VALUE r_gmprandstate_urandomm(VALUE self, VALUE arg);
|
323
|
+
|
324
|
+
// Float Random Numbers
|
325
|
+
extern VALUE r_gmprandstate_mpfr_urandomb(int argc, VALUE *argv, VALUE self);
|
326
|
+
|
327
|
+
|
328
|
+
/* from gmpbench_timing.c */
|
329
|
+
|
330
|
+
// GMPbench Timing
|
331
|
+
extern VALUE r_gmpmod_cputime(VALUE self);
|
332
|
+
extern VALUE r_gmpmod_time(VALUE self);
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
extern void init_gmpz();
|
337
|
+
extern void init_gmpq();
|
338
|
+
extern void init_gmpf();
|
339
|
+
extern void init_gmprandstate();
|
340
|
+
extern void init_gmpbench_timing();
|
341
|
+
extern void init_gmprnd();
|
342
|
+
|
343
|
+
#endif
|