gmp 0.4.3 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ #include <mprnd.h>
2
+
3
+ #ifdef MPFR
4
+
5
+ VALUE r_mprnd_initialize(int argc, VALUE *argv, VALUE self);
6
+
7
+ VALUE r_mprndsg_new(int argc, VALUE *argv, VALUE klass)
8
+ {
9
+ VALUE res;
10
+ int *res_value;
11
+ (void)klass;
12
+ res_value = 0;
13
+
14
+ mprnd_make_struct(res, res_value);
15
+ rb_obj_call_init(res, argc, argv);
16
+ return res;
17
+ }
18
+
19
+ VALUE r_mprnd_initialize(int argc, VALUE *argv, VALUE self)
20
+ {
21
+ VALUE mode, name, ieee754;
22
+ mode = argv[0];
23
+ (void)argc;
24
+ switch (FIX2INT(mode)) {
25
+ case 0:
26
+ name = rb_str_new2("GMP_RNDN");
27
+ ieee754 = rb_str_new2("roundTiesToEven");
28
+ break;
29
+ case 1:
30
+ name = rb_str_new2("GMP_RNDZ");
31
+ ieee754 = rb_str_new2("roundTowardZero");
32
+ break;
33
+ case 2:
34
+ name = rb_str_new2("GMP_RNDU");
35
+ ieee754 = rb_str_new2("roundTowardPositive");
36
+ break;
37
+ case 3:
38
+ name = rb_str_new2("GMP_RNDD");
39
+ ieee754 = rb_str_new2("roundTowardNegative");
40
+ break;
41
+ default:
42
+ name = rb_str_new2("GMP_RNDN");
43
+ ieee754 = rb_str_new2("roundTiesToEven");
44
+ }
45
+ rb_iv_set(self, "@mode", mode);
46
+ rb_iv_set(self, "@name", name);
47
+ rb_iv_set(self, "@ieee754", ieee754);
48
+ return Qnil;
49
+ }
50
+
51
+ VALUE r_mprnd_inspect(VALUE self)
52
+ {
53
+ return rb_iv_get(self, "@name");
54
+ }
55
+
56
+ void init_gmprnd()
57
+ {
58
+ mGMP = rb_define_module("GMP");
59
+ ID new_id = rb_intern("new");
60
+
61
+ cGMP_Rnd = rb_define_class_under(mGMP, "Rnd", rb_cObject);
62
+
63
+ rb_define_singleton_method(cGMP_Rnd, "new", r_mprndsg_new, -1);
64
+ rb_define_method(cGMP_Rnd, "initialize", r_mprnd_initialize, -1);
65
+ rb_define_method(cGMP_Rnd, "inspect", r_mprnd_inspect, 0);
66
+
67
+ rb_define_attr (cGMP_Rnd, "mode", 1, 0);
68
+ rb_define_attr (cGMP_Rnd, "name", 1, 0);
69
+ rb_define_attr (cGMP_Rnd, "ieee754", 1, 0);
70
+
71
+ rb_define_const(mGMP, "GMP_RNDN", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(0)));
72
+ rb_define_const(mGMP, "GMP_RNDZ", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(1)));
73
+ rb_define_const(mGMP, "GMP_RNDU", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(2)));
74
+ rb_define_const(mGMP, "GMP_RNDD", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(3)));
75
+ }
76
+
77
+ #endif /* MPFR */
@@ -0,0 +1,12 @@
1
+ #ifndef _MPRND_H_
2
+ #define _MPRND_H_
3
+
4
+ /*
5
+ * mprnd.h
6
+ *
7
+ * This file contains GMP::Z method definitions.
8
+ */
9
+
10
+ #include <ruby_gmp.h>
11
+
12
+ #endif
@@ -82,7 +82,16 @@ typedef __gmp_randstate_struct MP_RANDSTATE;
82
82
  //should change exception type
83
83
  #define not_yet rb_raise(rb_eTypeError,"Not implemented yet")
84
84
 
85
+ #ifdef MPFR
86
+ #define mprnd_get_struct(ruby_var,c_var) { Data_Get_Struct(ruby_var, int, c_var); }
87
+ #define mprnd_make_struct(ruby_var,c_var) { ruby_var = Data_Make_Struct(cGMP_Rnd, int, 0, 0, c_var); }
88
+ #define GMPRND_P(value) (rb_obj_is_instance_of(value, cGMP_Rnd) == Qtrue)
89
+ #endif /* MPFR */
90
+
85
91
  extern VALUE mGMP, cGMP_Z, cGMP_Q, cGMP_F, cGMP_RandState;
92
+ #ifdef MPFR
93
+ extern VALUE cGMP_Rnd;
94
+ #endif /* MPFR */
86
95
 
87
96
  extern void r_gmpz_free(void *ptr);
88
97
  extern void r_gmpq_free(void *ptr);
@@ -110,12 +119,16 @@ extern VALUE r_gmpz_add_self(VALUE self, VALUE arg);
110
119
  extern VALUE r_gmpz_sub(VALUE self, VALUE arg);
111
120
  extern VALUE r_gmpz_sub_self(VALUE self, VALUE arg);
112
121
  extern VALUE r_gmpz_mul(VALUE self, VALUE arg);
122
+ extern VALUE r_gmpz_div(VALUE self, VALUE arg);
113
123
 
114
124
  // Integer Division
115
125
  extern VALUE r_gmpz_mod(VALUE self, VALUE arg);
116
126
 
117
127
  // Integer Exponentiation
118
128
  extern VALUE r_gmpzsg_pow(VALUE klass, VALUE base, VALUE exp);
129
+ extern VALUE r_gmpz_powm(VALUE self, VALUE exp, VALUE mod);
130
+
131
+ // Integer Roots
119
132
 
120
133
  // Number Theoretic Functions
121
134
  extern VALUE r_gmpz_is_probab_prime(int argc, VALUE* argv, VALUE self);
@@ -130,22 +143,19 @@ extern VALUE r_gmpz_remove(VALUE self, VALUE arg);
130
143
  extern VALUE r_gmpz_eq(VALUE self, VALUE arg);
131
144
  extern VALUE r_gmpz_cmp(VALUE self, VALUE arg);
132
145
  extern VALUE r_gmpz_cmpabs(VALUE self, VALUE arg);
146
+ extern VALUE r_gmpz_sgn(VALUE self);
147
+ extern int mpz_cmp_value(MP_INT *OP, VALUE arg);
133
148
 
134
- // Miscelaneous Integer Functions
135
- extern VALUE r_gmpz_sizeinbase(VALUE self, VALUE base);
136
- extern VALUE r_gmpz_size_in_bin(VALUE self);
137
-
138
- // _unsorted_
139
- extern VALUE r_gmpz_div(VALUE self, VALUE arg);
149
+ // Integer Logic and Bit Fiddling
140
150
  extern VALUE r_gmpz_popcount(VALUE self);
141
- extern VALUE r_gmpz_setbit(VALUE self, VALUE bitnr, VALUE set_to);
142
- extern VALUE r_gmpz_getbit(VALUE self, VALUE bitnr);
143
151
  extern VALUE r_gmpz_scan0(VALUE self, VALUE bitnr);
144
152
  extern VALUE r_gmpz_scan1(VALUE self, VALUE bitnr);
145
- extern VALUE r_gmpz_powm(VALUE self, VALUE exp, VALUE mod);
146
- extern VALUE r_gmpz_sgn(VALUE self);
147
- extern int mpz_cmp_value(MP_INT *OP, VALUE arg);
153
+ extern VALUE r_gmpz_setbit(VALUE self, VALUE bitnr, VALUE set_to);
154
+ extern VALUE r_gmpz_getbit(VALUE self, VALUE bitnr);
148
155
 
156
+ // Miscelaneous Integer Functions
157
+ extern VALUE r_gmpz_sizeinbase(VALUE self, VALUE base);
158
+ extern VALUE r_gmpz_size_in_bin(VALUE self);
149
159
 
150
160
 
151
161
  /* from gmpq.h */
@@ -209,36 +219,58 @@ extern int mpf_cmp_value(MP_FLOAT *OP, VALUE arg);
209
219
 
210
220
  // MPFR
211
221
  #ifdef MPFR
212
- extern VALUE r_gmpfr_sqrt(VALUE self);
222
+ extern VALUE r_gmpfr_sqrt(int argc, VALUE *argv, VALUE self);
213
223
 
214
- extern VALUE r_gmpfr_log(VALUE self);
215
- extern VALUE r_gmpfr_log2(VALUE self);
216
- extern VALUE r_gmpfr_log10(VALUE self);
217
- extern VALUE r_gmpfr_exp(VALUE self);
224
+ extern VALUE r_gmpfr_log(int argc, VALUE *argv, VALUE self);
225
+ extern VALUE r_gmpfr_log2(int argc, VALUE *argv, VALUE self);
226
+ extern VALUE r_gmpfr_log10(int argc, VALUE *argv, VALUE self);
227
+ extern VALUE r_gmpfr_exp(int argc, VALUE *argv, VALUE self);
228
+ extern VALUE r_gmpfr_exp2(int argc, VALUE *argv, VALUE self);
229
+ extern VALUE r_gmpfr_exp10(int argc, VALUE *argv, VALUE self);
230
+ extern VALUE r_gmpfr_cos(int argc, VALUE *argv, VALUE self);
231
+ extern VALUE r_gmpfr_sin(int argc, VALUE *argv, VALUE self);
232
+ extern VALUE r_gmpfr_tan(int argc, VALUE *argv, VALUE self);
233
+ extern VALUE r_gmpfr_sec(int argc, VALUE *argv, VALUE self);
234
+ extern VALUE r_gmpfr_csc(int argc, VALUE *argv, VALUE self);
235
+ extern VALUE r_gmpfr_cot(int argc, VALUE *argv, VALUE self);
218
236
 
219
- extern VALUE r_gmpfr_cos(VALUE self);
220
- extern VALUE r_gmpfr_sin(VALUE self);
221
- extern VALUE r_gmpfr_tan(VALUE self);
222
- extern VALUE r_gmpfr_sec(VALUE self);
223
- extern VALUE r_gmpfr_csc(VALUE self);
224
- extern VALUE r_gmpfr_cot(VALUE self);
237
+ extern VALUE r_gmpfr_acos(int argc, VALUE *argv, VALUE self);
238
+ extern VALUE r_gmpfr_asin(int argc, VALUE *argv, VALUE self);
239
+ extern VALUE r_gmpfr_atan(int argc, VALUE *argv, VALUE self);
225
240
 
226
- extern VALUE r_gmpfr_acos(VALUE self);
227
- extern VALUE r_gmpfr_asin(VALUE self);
228
- extern VALUE r_gmpfr_atan(VALUE self);
241
+ extern VALUE r_gmpfr_cosh(int argc, VALUE *argv, VALUE self);
242
+ extern VALUE r_gmpfr_sinh(int argc, VALUE *argv, VALUE self);
243
+ extern VALUE r_gmpfr_tanh(int argc, VALUE *argv, VALUE self);
229
244
 
230
- extern VALUE r_gmpfr_cosh(VALUE self);
231
- extern VALUE r_gmpfr_sinh(VALUE self);
232
- extern VALUE r_gmpfr_tanh(VALUE self);
245
+ extern VALUE r_gmpfr_sech(int argc, VALUE *argv, VALUE self);
246
+ extern VALUE r_gmpfr_csch(int argc, VALUE *argv, VALUE self);
247
+ extern VALUE r_gmpfr_coth(int argc, VALUE *argv, VALUE self);
248
+ extern VALUE r_gmpfr_acosh(int argc, VALUE *argv, VALUE self);
249
+ extern VALUE r_gmpfr_asinh(int argc, VALUE *argv, VALUE self);
250
+ extern VALUE r_gmpfr_atanh(int argc, VALUE *argv, VALUE self);
233
251
 
234
- extern VALUE r_gmpfr_acosh(VALUE self);
235
- extern VALUE r_gmpfr_asinh(VALUE self);
236
- extern VALUE r_gmpfr_atanh(VALUE self);
252
+ extern VALUE r_gmpfr_log1p(int argc, VALUE *argv, VALUE self);
253
+ extern VALUE r_gmpfr_expm1(int argc, VALUE *argv, VALUE self);
254
+ extern VALUE r_gmpfr_eint(int argc, VALUE *argv, VALUE self);
255
+ extern VALUE r_gmpfr_li2(int argc, VALUE *argv, VALUE self);
256
+ extern VALUE r_gmpfr_gamma(int argc, VALUE *argv, VALUE self);
257
+ extern VALUE r_gmpfr_lngamma(int argc, VALUE *argv, VALUE self);
258
+ /*extern VALUE r_gmpfr_lgamma(int argc, VALUE *argv, VALUE self);*/
259
+ extern VALUE r_gmpfr_zeta(int argc, VALUE *argv, VALUE self);
260
+ extern VALUE r_gmpfr_erf(int argc, VALUE *argv, VALUE self);
261
+ extern VALUE r_gmpfr_erfc(int argc, VALUE *argv, VALUE self);
262
+ extern VALUE r_gmpfr_j0(int argc, VALUE *argv, VALUE self);
263
+ extern VALUE r_gmpfr_j1(int argc, VALUE *argv, VALUE self);
264
+ extern VALUE r_gmpfr_jn(int argc, VALUE *argv, VALUE self);
265
+ extern VALUE r_gmpfr_y0(int argc, VALUE *argv, VALUE self);
266
+ extern VALUE r_gmpfr_y1(int argc, VALUE *argv, VALUE self);
237
267
 
238
268
  extern VALUE r_gmpfrsg_const_log2();
239
269
  extern VALUE r_gmpfrsg_const_pi();
240
270
  extern VALUE r_gmpfrsg_const_euler();
241
271
  extern VALUE r_gmpfrsg_const_catalan();
272
+
273
+ extern mp_rnd_t r_get_rounding_mode(VALUE rnd);
242
274
  #endif /* MPFR */
243
275
 
244
276
  // _unsorted_
@@ -279,5 +311,8 @@ extern void init_gmpq();
279
311
  extern void init_gmpf();
280
312
  extern void init_gmprandstate();
281
313
  extern void init_gmpbench_timing();
314
+ #ifdef MPFR
315
+ extern void init_gmprnd();
316
+ #endif /* MPFR */
282
317
 
283
318
  #endif
data/manual.pdf CHANGED
Binary file
data/manual.tex CHANGED
@@ -28,8 +28,8 @@
28
28
  \huge{gmp} &\\
29
29
  \midrule[3pt]
30
30
  \multicolumn{2}{r}{\large{Ruby bindings to the GMP library}}\\
31
- \multicolumn{2}{r}{\large{Edition 0.4.3}}\\
32
- \multicolumn{2}{r}{\large{8 March 2010}}
31
+ \multicolumn{2}{r}{\large{Edition 0.4.7}}\\
32
+ \multicolumn{2}{r}{\large{25 March 2010}}
33
33
  \end{tabular}
34
34
 
35
35
  \vfill
@@ -159,12 +159,8 @@ Or you may install the gem from gemcutter:\\
159
159
  \\
160
160
  \texttt{gem install gmp}\\
161
161
 
162
- Or you may install the gem from github (old):\\
163
- \\
164
- \texttt{gem install srawlins-gmp}\\
165
-
166
- At this time, the gem does not self-compile (how does that work?). To compile the C
167
- extensions, do the following:\\
162
+ At this time, the gem does self-compiles. If required libraries cannot be found, you may
163
+ compile the C extensions manually with:\\
168
164
  \\
169
165
  \texttt{cd <gmp gem directory>/ext}\\
170
166
  \texttt{ruby extconf.rb}\\
@@ -181,16 +177,15 @@ You can run this test suite with:\\
181
177
  \texttt{ruby unit\_tests.rb}\\
182
178
 
183
179
  All tests should pass. If you don't have the test-unit gem installed, then you may
184
- run into one error. I'm not sure why this is... I suspect a bug in Ruby's Test::Unit
185
- that the test-unit gem monkey patches.
180
+ run into one error.
186
181
 
187
182
  \section{GMP and gmp gem basics}
188
183
 
189
184
  \subsection{Classes}
190
185
  The gmp gem includes the namespace \texttt{GMP} and four classes within \texttt{GMP}:
191
186
  \begin{itemize}
192
- \item \texttt{GMP::Z} - Methods for signed integer arithmetic. There are at least 45
193
- methods here (still accounting).
187
+ \item \texttt{GMP::Z} - Methods for signed integer arithmetic. There are about 64
188
+ methods here.
194
189
  \item \texttt{GMP::Q} - Methods for rational number arithmetic. There are at least 11
195
190
  methods here (still accounting).
196
191
  \item \texttt{GMP::F} - Methods for floating-point arithmetic. There are at least 6
@@ -199,7 +194,7 @@ The gmp gem includes the namespace \texttt{GMP} and four classes within \texttt{
199
194
  methods here.
200
195
  \end{itemize}
201
196
 
202
- In addition to the above four classes, there is also one constant within \texttt{GMP}:
197
+ In addition to the above four classes, there are also four constants within \texttt{GMP}:
203
198
  \begin{itemize}
204
199
  \item \texttt{GMP::GMP\_VERSION} - The version of GMP linked into the gmp gem
205
200
  \item \texttt{GMP::GMP\_CC} - The compiler that compiled GMP linked into the gmp gem
@@ -502,6 +497,31 @@ There is also a convenience method available, \texttt{GMP::Z()}.\\
502
497
  }
503
498
  \end{tabular}
504
499
 
500
+ \newpage
501
+ \subsection{Integer Exponentiation}
502
+
503
+ \begin{tabular}{p{\methwidth} l r}
504
+ \toprule
505
+ \textbf{**} & & \textit{integer} ** \textit{numeric} $\rightarrow$ \textit{numeric} \\
506
+ & & \textit{integer}.pow(\textit{numeric}) $\rightarrow$ \textit{numeric} \\
507
+ \cmidrule(r){2-3}
508
+ & \multicolumn{2}{p{\defnwidth}}{
509
+ Returns $integer$ raised to the $numeric$ power.
510
+ }
511
+ \end{tabular}
512
+ \newline\newline
513
+
514
+ \begin{tabular}{p{\methwidth} l r}
515
+ \toprule
516
+ \textbf{powmod} & & \textit{integer}.powmod(\textit{exp}, \textit{mod}) $\rightarrow$ \textit{integer} \\
517
+ \cmidrule(r){2-3}
518
+ & \multicolumn{2}{p{\defnwidth}}{
519
+ Returns $integer$ raised to the $exp$ power, modulo $mod$. Negative $exp$ is supported
520
+ if an inverse, $integer^{-1}$ modulo $mod$, exists. If an inverse doesn't exist then a
521
+ divide by zero exception is raised.
522
+ }
523
+ \end{tabular}
524
+
505
525
  \subsection{Integer Roots}
506
526
 
507
527
  \begin{tabular}{p{\methwidth} l r}
@@ -517,7 +537,7 @@ There is also a convenience method available, \texttt{GMP::Z()}.\\
517
537
  \begin{tabular}{p{\methwidth} l r}
518
538
  \toprule
519
539
  \textbf{sqrt} & & \textit{integer}.sqrt $\rightarrow$ \textit{numeric} \\
520
- & & \textit{integer}.sqrt!(\textit{numeric}) $\rightarrow$ \textit{numeric} \\
540
+ & & \textit{integer}.sqrt! $\rightarrow$ \textit{numeric} \\
521
541
  \cmidrule(r){2-3}
522
542
  & \multicolumn{2}{p{\defnwidth}}{
523
543
  Returns the truncated integer part of the square root of $integer$.
@@ -562,30 +582,6 @@ There is also a convenience method available, \texttt{GMP::Z()}.\\
562
582
  }
563
583
  \end{tabular}
564
584
 
565
- \subsection{Integer Exponentiation}
566
-
567
- \begin{tabular}{p{\methwidth} l r}
568
- \toprule
569
- \textbf{**} & & \textit{integer} ** \textit{numeric} $\rightarrow$ \textit{numeric} \\
570
- & & \textit{integer}.pow(\textit{numeric}) $\rightarrow$ \textit{numeric} \\
571
- \cmidrule(r){2-3}
572
- & \multicolumn{2}{p{\defnwidth}}{
573
- Returns $integer$ raised to the $numeric$ power.
574
- }
575
- \end{tabular}
576
- \newline\newline
577
-
578
- \begin{tabular}{p{\methwidth} l r}
579
- \toprule
580
- \textbf{powmod} & & \textit{integer}.powmod(\textit{exp}, \textit{mod}) $\rightarrow$ \textit{integer} \\
581
- \cmidrule(r){2-3}
582
- & \multicolumn{2}{p{\defnwidth}}{
583
- Returns $integer$ raised to the $exp$ power, modulo $mod$. Negative $exp$ is supported
584
- if an inverse, $integer^{-1}$ modulo $mod$, exists. If an inverse doesn't exist then a
585
- divide by zero exception is raised.
586
- }
587
- \end{tabular}
588
-
589
585
  \subsection{Number Theoretic Functions}
590
586
 
591
587
  \begin{tabular}{p{\methwidth} l r}
@@ -715,6 +711,113 @@ There is also a convenience method available, \texttt{GMP::Z()}.\\
715
711
  }
716
712
  \end{tabular}
717
713
 
714
+ \subsection{Integer Comparisons}
715
+
716
+ \begin{tabular}{p{\methwidth} l r}
717
+ \toprule
718
+ \textbf{\textless=\textgreater} & & $a$ \textless=\textgreater\ $b$ $\rightarrow$ $fixnum$ \\
719
+ \cmidrule(r){2-3}
720
+ & \multicolumn{2}{p{\defnwidth}}{
721
+ Returns a negative Fixnum if $a$ is less than $b$.\newline
722
+ Returns 0 if $a$ is equal to $b$.\newline
723
+ Returns a positive Fixnum if $a$ is greater than $b$.
724
+ }
725
+ \end{tabular}
726
+ \newline\newline
727
+
728
+ \begin{tabular}{p{\methwidth} l r}
729
+ \toprule
730
+ \textbf{\textless} & & $a$ \textless\ $b$ $\rightarrow$ $boolean$ \\
731
+ \cmidrule(r){2-3}
732
+ & \multicolumn{2}{p{\defnwidth}}{
733
+ Returns true if $a$ is less than $b$.
734
+ }
735
+ \end{tabular}
736
+ \newline\newline
737
+
738
+ \begin{tabular}{p{\methwidth} l r}
739
+ \toprule
740
+ \textbf{\textless=} & & $a$ \textless=\ $b$ $\rightarrow$ $boolean$ \\
741
+ \cmidrule(r){2-3}
742
+ & \multicolumn{2}{p{\defnwidth}}{
743
+ Returns true if $a$ is less than or equal to $b$.
744
+ }
745
+ \end{tabular}
746
+ \newline\newline
747
+
748
+ \begin{tabular}{p{\methwidth} l r}
749
+ \toprule
750
+ \textbf{==} & & $a$ == $b$ $\rightarrow$ $boolean$ \\
751
+ \cmidrule(r){2-3}
752
+ & \multicolumn{2}{p{\defnwidth}}{
753
+ Returns true if $a$ is equal to $b$.
754
+ }
755
+ \end{tabular}
756
+ \newline\newline
757
+
758
+ \begin{tabular}{p{\methwidth} l r}
759
+ \toprule
760
+ \textbf{\textgreater=} & & $a$ \textgreater= $b$ $\rightarrow$ $boolean$ \\
761
+ \cmidrule(r){2-3}
762
+ & \multicolumn{2}{p{\defnwidth}}{
763
+ Returns true if $a$ is greater than or equal to $b$.
764
+ }
765
+ \end{tabular}
766
+ \newline\newline
767
+
768
+ \begin{tabular}{p{\methwidth} l r}
769
+ \toprule
770
+ \textbf{\textgreater} & & $a$ \textgreater\ $b$ $\rightarrow$ $boolean$ \\
771
+ \cmidrule(r){2-3}
772
+ & \multicolumn{2}{p{\defnwidth}}{
773
+ Returns true if $a$ is greater than $b$.
774
+ }
775
+ \end{tabular}
776
+ \newline\newline
777
+
778
+ \begin{tabular}{p{\methwidth} l r}
779
+ \toprule
780
+ \textbf{cmpabs} & & $a$.cmpabs($b$) $\rightarrow$ $fixnum$ \\
781
+ \cmidrule(r){2-3}
782
+ & \multicolumn{2}{p{\defnwidth}}{
783
+ Returns a negative Fixnum if abs($a$) is less than abs($b$).\newline
784
+ Returns 0 if abs($a$) is equal to abs($b$).\newline
785
+ Returns a positive Fixnum if abs($a$) is greater than abs($b$).
786
+ }
787
+ \end{tabular}
788
+ \newline\newline
789
+
790
+ \begin{tabular}{p{\methwidth} l r}
791
+ \toprule
792
+ \textbf{sgn} & & $a$.sgn $\rightarrow$ $-1$, $0$, or $1$ \\
793
+ \cmidrule(r){2-3}
794
+ & \multicolumn{2}{p{\defnwidth}}{
795
+ Returns -1 if $a$ is less than $b$.\newline
796
+ Returns 0 if $a$ is equal to $b$.\newline
797
+ Returns 1 if $a$ is greater than $b$.
798
+ }
799
+ \end{tabular}
800
+ \newline\newline
801
+
802
+ \begin{tabular}{p{\methwidth} l r}
803
+ \toprule
804
+ \textbf{eql?} & & $a$.eql?($b$) $\rightarrow$ $boolean$ \\
805
+ \cmidrule(r){2-3}
806
+ & \multicolumn{2}{p{\defnwidth}}{
807
+ Used when comparing objects as Hash keys.
808
+ }
809
+ \end{tabular}
810
+ \newline\newline
811
+
812
+ \begin{tabular}{p{\methwidth} l r}
813
+ \toprule
814
+ \textbf{hash} & & $a$.hash $\rightarrow$ $string$ \\
815
+ \cmidrule(r){2-3}
816
+ & \multicolumn{2}{p{\defnwidth}}{
817
+ Used when comparing objects as Hash keys.
818
+ }
819
+ \end{tabular}
820
+
718
821
  \subsection{Integer Logic and Bit Fiddling}
719
822
 
720
823
  \begin{tabular}{p{\methwidth} l r}
@@ -747,6 +850,30 @@ There is also a convenience method available, \texttt{GMP::Z()}.\\
747
850
  \end{tabular}
748
851
  \newline\newline
749
852
 
853
+ \begin{tabular}{p{\methwidth} l r}
854
+ \toprule
855
+ \textbf{com} & & $integer$.com $\rightarrow$ $complement$ \\
856
+ & & $integer$.com! $\rightarrow$ $complement$ \\
857
+ \cmidrule(r){2-3}
858
+ & \multicolumn{2}{p{\defnwidth}}{
859
+ Returns the one's complement of $integer$. The destructive method sets $integer$ to
860
+ the one's complement of $integer$.
861
+ }
862
+ \end{tabular}
863
+ \newline\newline
864
+
865
+ \begin{tabular}{p{\methwidth} l r}
866
+ \toprule
867
+ \textbf{popcount} & & $n$.popcount $\rightarrow$ $fixnum$ \\
868
+ \cmidrule(r){2-3}
869
+ & \multicolumn{2}{p{\defnwidth}}{
870
+ If $n>=0$, return the population count of $n$, which is the number of 1 bits in the
871
+ binary representation. If $n<0$, the number of 1s is infinite, and the return value
872
+ is the largest possible $mp\_bitcnt\_t$.
873
+ }
874
+ \end{tabular}
875
+ \newline\newline
876
+
750
877
  \begin{tabular}{p{\methwidth} l r}
751
878
  \toprule
752
879
  \textbf{scan0} & & $n$.scan0($i$) $\rightarrow$ $integer$ \\
@@ -761,6 +888,84 @@ There is also a convenience method available, \texttt{GMP::Z()}.\\
761
888
  scan0 past the end of a negative number.
762
889
  }
763
890
  \end{tabular}
891
+ \newline\newline
892
+
893
+ \begin{tabular}{p{\methwidth} l r}
894
+ \toprule
895
+ \textbf{scan1} & & $n$.scan1($i$) $\rightarrow$ $integer$ \\
896
+ \cmidrule(r){2-3}
897
+ & \multicolumn{2}{p{\defnwidth}}{
898
+ Scans $n$, starting from bit $i$, towards more significant bits, until the first 1 bit
899
+ is found. Return the index of the found bit.
900
+ \newline\newline
901
+ If the bit at $i$ is already what's sought, then $i$ is returned.
902
+ \newline\newline
903
+ If there's no bit found, then $INT2FIX(ULONG\_MAX)$ is returned. This will happen in
904
+ scan1 past the end of a negative number.
905
+ }
906
+ \end{tabular}
907
+ \newline\newline
908
+
909
+ \begin{tabular}{p{\methwidth} l r}
910
+ \toprule
911
+ \textbf{[]} & & $n$[$bit\_index$] $\rightarrow$ $0$ or $1$ \\
912
+ \cmidrule(r){2-3}
913
+ & \multicolumn{2}{p{\defnwidth}}{
914
+ Tests bit $bit\_index$ in $n$ and return $0$ or $1$ accordingly.
915
+ }
916
+ \end{tabular}
917
+ \newline\newline
918
+
919
+ \begin{tabular}{p{\methwidth} l r}
920
+ \toprule
921
+ \textbf{[]=} & & $n$[$bit\_index$]=$i$ $\rightarrow$ $nil$ \\
922
+ \cmidrule(r){2-3}
923
+ & \multicolumn{2}{p{\defnwidth}}{
924
+ Sets bit $bit\_index$ in $n$ to $i$.
925
+ }
926
+ \end{tabular}
927
+
928
+ \newpage
929
+ \subsection{Miscellaneous Integer Functions}
930
+
931
+ \begin{tabular}{p{\methwidth} l r}
932
+ \toprule
933
+ \textbf{odd?} & & $n$.odd? $\rightarrow$ $boolean$ \\
934
+ \cmidrule(r){2-3}
935
+ & \multicolumn{2}{p{\defnwidth}}{
936
+ Returns whether $n$ is odd.
937
+ }
938
+ \end{tabular}
939
+ \newline\newline
940
+
941
+ \begin{tabular}{p{\methwidth} l r}
942
+ \toprule
943
+ \textbf{even?} & & $n$.even? $\rightarrow$ $boolean$ \\
944
+ \cmidrule(r){2-3}
945
+ & \multicolumn{2}{p{\defnwidth}}{
946
+ Returns whether $n$ is even.
947
+ }
948
+ \end{tabular}
949
+ \newline\newline
950
+
951
+ \begin{tabular}{p{\methwidth} l r}
952
+ \toprule
953
+ \textbf{sizeinbase} & & $n$.sizeinbase($b$) $\rightarrow$ $digits$ \\
954
+ \cmidrule(r){2-3}
955
+ & \multicolumn{2}{p{\defnwidth}}{
956
+ Returns the number of digits in base $b$. $b$ can vary between 2 and 62.
957
+ }
958
+ \end{tabular}
959
+ \newline\newline
960
+
961
+ \begin{tabular}{p{\methwidth} l r}
962
+ \toprule
963
+ \textbf{size\_in\_bin} & & $n$.size\_in\_bin $\rightarrow$ $digits$ \\
964
+ \cmidrule(r){2-3}
965
+ & \multicolumn{2}{p{\defnwidth}}{
966
+ Returns the number of digits in $n$'s binary representation.
967
+ }
968
+ \end{tabular}
764
969
 
765
970
  \newpage
766
971
  \section{Rational Functions}
@@ -781,7 +986,7 @@ There is also a convenience method available, \texttt{GMP::Z()}.\\
781
986
 
782
987
  \texttt{GMP::Q.new \qqqquad\qqqquad \#=> 0 (default) \newline
783
988
  GMP::Q.new(1) \qqqquad\qquad\ \#=> 1 (Ruby Fixnum) \newline
784
- GMP::Q.new(1,3) \qqqquad\ \#=> 1/3 (Ruby Fixnums) \newline
989
+ GMP::Q.new(1,3) \qqqquad\quad\ \#=> 1/3 (Ruby Fixnums) \newline
785
990
  GMP::Q.new("127") \qqqquad\ \#=> 127 (Ruby String)\newline
786
991
  GMP::Q.new(4294967296) \qquad \#=> 4294967296 (Ruby Bignum)\newline
787
992
  GMP::Q.new(GMP::Z.new(31)) \#=> 31 (GMP Integer)}
@@ -791,6 +996,33 @@ There is also a convenience method available, \texttt{GMP::Z()}.\\
791
996
 
792
997
  There is also a convenience method available, \texttt{GMP::Q()}.\\
793
998
 
999
+ \subsection{Converting Rationals}
1000
+
1001
+ \begin{tabular}{p{\methwidth} l r}
1002
+ \toprule
1003
+ \textbf{to\_d} & & \textit{rational}.to\_d $\rightarrow$ \textit{float} \\
1004
+ \cmidrule(r){2-3}
1005
+ & \multicolumn{2}{p{\defnwidth}}{
1006
+ Returns \textit{rational} as an Float if \textit{rational} fits in a Float.
1007
+
1008
+ Otherwise returns the least significant part of \texttt{rational}, with the same sign as
1009
+ \textit{rational}.
1010
+
1011
+ If \textit{rational} is too big to fit in a Float, the returned result is probably not
1012
+ very useful.
1013
+ }
1014
+ \end{tabular}
1015
+ \newline\newline
1016
+
1017
+ \begin{tabular}{p{\methwidth} l r}
1018
+ \toprule
1019
+ \textbf{to\_s} & & \textit{rational}.to\_s $\rightarrow$ \textit{str} \\
1020
+ \cmidrule(r){2-3}
1021
+ & \multicolumn{2}{p{\defnwidth}}{
1022
+ Converts \textit{rational} to a string.
1023
+ }
1024
+ \end{tabular}
1025
+
794
1026
  \newpage
795
1027
  \section{Random Number Functions}
796
1028