-
Notifications
You must be signed in to change notification settings - Fork 4
/
manual.tex
1675 lines (1482 loc) · 62 KB
/
manual.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[pdftex,10pt]{article}
\usepackage{amsmath,amsfonts,url}
\usepackage[pdftex]{graphicx}
\usepackage{booktabs}
\usepackage{url}
\setlength{\parindent}{0pt}
\def\cour{\fontfamily{pcr}\selectfont}
\usepackage[top=1in, bottom=0.8in, left=0.8in, right=0.8in]{geometry}
\setcounter{tocdepth}{3}
\newlength{\titrwidth}
\setlength{\titrwidth}{\textwidth}
\addtolength{\titrwidth}{-1.2in}
\newlength{\methwidth}
\setlength{\methwidth}{0.8in}
\newlength{\defnwidth}
\setlength{\defnwidth}{\textwidth}
\addtolength{\defnwidth}{-1.2in}
\addtolength{\heavyrulewidth}{\heavyrulewidth}
\def\qquad{\quad\quad}
\def\qqqquad{\quad\quad\quad\quad}
\def\cc{\colon\colon}
\def\gmpz{\textit{GMP::Z}}
\def\gmpq{\textit{GMP::Q}}
\def\gmpf{\textit{GMP::F}}
\def\gmprandstate{\textit{GMP::RandState}}
\def\gmpzs{\textit{GMP::Z}\ }
\def\gmpqs{\textit{GMP::Q}\ }
\def\gmpfs{\textit{GMP::F}\ }
\def\gmprandstates{\textit{GMP::RandState\ }}
\frenchspacing
\begin{document}
\begin{tabular}{p{1.0in} p{\titrwidth}}
\huge{gmp} &\\
\midrule[3pt]
\multicolumn{2}{r}{\large{Ruby bindings to the GMP library}}\\
\multicolumn{2}{r}{\large{Edition 0.7.19}}\\
\multicolumn{2}{r}{\large{12 March 2014}}
\end{tabular}
\vfill
\large{written by Sam Rawlins}\\
\large{with extensive quoting from the GMP Manual}
\newpage
\vfill
This manual describes how to use the gmp Ruby gem, which provides bindings to
the GNU multiple precision arithmetic library, version 4.3.x or 5.x.\\
\\
Copyright 2009, 2010, 2011, 2012, 2013 Sam Rawlins.\\
Apache License, Version 2.0
\newpage
\tableofcontents
\newpage
\section{Introduction to GNU MP}
This entire page is copied verbatim from the GMP Manual.\\\\
GNU MP is a portable library written in C for arbitrary precision arithmetic on
integers, rational numbers, and floating-point numbers. It aims to provide the
fastest possible arithmetic for all applications that need higher precision
than is directly supported by the basic C types.\\
\\
Many applications use just a few hundred bits of precision; but some
applications may need thousands or even millions of bits. GMP is designed to
give good performance for both, by choosing algorithms based on the sizes of
the operands, and by carefully keeping the overhead at a minimum.\\
\\
The speed of GMP is achieved by using fullwords as the basic arithmetic type,
by using sophisticated algorithms, by including carefully optimized assembly
code for the most common inner loops for many different CPUs, and by a general
emphasis on speed (as opposed to simplicity or elegance).\\
\\
There is assembly code for these CPUs: ARM, DEC Alpha 21064, 21164, and 21264,
AMD 29000, AMD K6, K6-2, Athlon, and Athlon64, Hitachi SuperH and SH-2, HPPA
1.0, 1.1, and 2.0, Intel Pentium, Pentium Pro/II/III, Pentium 4, generic x86,
Intel IA-64, i960, Motorola MC68000, MC68020, MC88100, and MC88110,
Motorola/IBM PowerPC 32 and 64, National NS32000, IBM POWER, MIPS R3000, R4000,
SPARCv7, SuperSPARC, generic SPARCv8, UltraSPARC, DEC VAX, and Zilog Z8000.
Some optimizations also for Cray vector systems, Clipper, IBM ROMP (RT), and
Pyramid AP/XP.\\
\\
For up-to-date information on GMP, please see the GMP web pages at
\url{http://gmplib.org/}\\
The latest version of the library is available at
\url{ftp://ftp.gnu.org/gnu/gmp/}\\
Many sites around the world mirror '\url{ftp.gnu.org}', please use a mirror
near you, see \url{http://www.gnu.org/order/ftp.html} for a full list.\\
\\
There are three public mailing lists of interest. One for release
announcements, one for general questions and discussions about usage of the GMP
library, and one for bug reports. For more information, see
\url{http://gmplib.org/mailman/listinfo/}.\\
The proper place for bug reports is gmp-bugs@gmplib.org. See Chapter 4
[Reporting Bugs], page 28 for information about reporting bugs.
\newpage
\section{Introduction to MPFR}
The gmp gem optionally interacts with the MPFR library as well. This entire page
is copied verbatim from the MPFR manual.\\\\
The MPFR library is a C library for multiple-precision floating-point
computations with correct rounding. MPFR has continuously been supported by the
INRIA and the current main authors come from the Caramel and Arénaire
project-teams at Loria (Nancy, France) and LIP (Lyon, France) respectively; see
more on the credit page. MPFR is based on the GMP multiple-precision library.\\
The main goal of MPFR is to provide a library for multiple-precision
floating-point computation which is both efficient and has a well-defined
semantics. It copies the good ideas from the ANSI/IEEE-754 standard for
double-precision floating-point arithmetic (53-bit mantissa).\\
MPFR is free. It is distributed under the GNU Lesser General Public License
(GNU Lesser GPL), version 3 or later (2.1 or later for MPFR versions until
2.4.x). The library has been registered in France by the Agence de Protection
des Programmes under the number IDDN FR 001 120020 00 R P 2000 000 10800, on 15
March 2000. This license guarantees your freedom to share and change MPFR, to
make sure MPFR is free for all its users. Unlike the ordinary General Public
License, the Lesser GPL enables developers of non-free programs to use MPFR in
their programs. If you have written a new function for MPFR or improved an
existing one, please share your work!
\newpage
\section{Introduction to the gmp gem}
The gmp Ruby gem is a Ruby library that provides bindings to GMP. The gem is
incomplete, and will likely only include a subset of the GMP functions. It is
built as a C extension for Ruby, interacting with gmp.h. The gmp gem is not
endorsed or supported by GNU or the GMP team (or MPFR team). The gmp gem also
does not ship with GMP (or MPFR), so GMP (and MPFR) must be compiled
separately.
\section{Installing the gmp gem}
\subsection{Prerequisites}
OK. First, we've got a few requirements. To install the gmp gem, you need one
of the following versions of Ruby:
\begin{itemize}
\item (MRI) Ruby 1.8.6 - tested lightly.
\item (MRI) Ruby 1.8.7 - tested lightly.
\item (MRI) Ruby 1.9.3 - tested seriously.
\item (MRI) Ruby 2.0.0 - tested seriously.
\item (REE) Ruby 1.8.7 - tested lightly.
\item (RBX) Rubinius 1.1 - tested lightly.
\end{itemize}
As you can see only Matz's Ruby Interpreter (MRI) is seriously supported. I've just
started to poke around with REE. Everything seems to work on REE 1.8.7 on Linux, x86 and
x86\_64. Also, Rubinius 1.1 seems to work great on Linux, but support won't be official
until Rubinius 1.1.1.\\
Next is the platform, the combination of the architecture (processor) and OS.
As far as I can tell, if you can compile GMP and Ruby (and optionally MPFR) on
a given platform, you can use the gmp gem there too. Please report problems
with that hypothesis.\\
Lastly, GMP (and MPFR). GMP (and MPFR) must be compiled and working. "And working" means
you ran "make check" after compiling GMP (and MPFR), and it 'check's out. The following
versions of GMP (and MPFR) have been tested:
\begin{itemize}
\item GMP 4.3.1 (with MPFR 2.4.2)
\item GMP 4.3.2 (with MPFR 2.4.2 and 3.0.0)
\item GMP 5.0.0 (with MPFR 3.0.0)
\item GMP 5.0.1 (with MPFR 3.0.0)
\end{itemize}
That's all. I don't intend to test any older versions.\\
\newpage
Here is a table of the exact environments on which I have tested the gmp gem.
The (MPFR) version denotes that the gmp gem was tested both with and without
the given version of MPFR:\\\\
\begin{tabular}{lrrr} \hline
Platform & Ruby & GMP & (MPFR) \\ \midrule[1pt]
Linux (Ubuntu NR 10.04) on x86 (32-bit) & (MRI) Ruby 1.8.7 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.8.7 & GMP 5.0.1 & (3.0.0) \\
& (MRI) Ruby 1.9.1 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.9.1 & GMP 5.0.1 & (3.0.0) \\
& (MRI) Ruby 1.9.2 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.9.2 & GMP 5.0.1 & (3.0.0) \\
& (RBX) Rubinius 1.1 & GMP 4.3.2 & (2.4.2) \\
& (RBX) Rubinius 1.1 & GMP 5.0.1 & (3.0.0) \\ \hline
Linux (Ubuntu 10.04) on x86\_64 (64-bit) & (MRI) Ruby 1.8.7 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.8.7 & GMP 5.0.1 & (3.0.0) \\
& (MRI) Ruby 1.9.1 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.9.1 & GMP 5.0.1 & (3.0.0) \\
& (MRI) Ruby 1.9.2 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.9.2 & GMP 5.0.1 & (3.0.0) \\
& (RBX) Rubinius 1.1 & GMP 4.3.2 & (2.4.2) \\
& (RBX) Rubinius 1.1 & GMP 5.0.1 & (3.0.0) \\ \hline
Mac OS X 10.6.4 on x86\_64 (64-bit) & (MRI) Ruby 1.8.7 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.8.7 & GMP 5.0.1 & (3.0.0) \\
& (MRI) Ruby 1.9.1 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.9.1 & GMP 5.0.1 & (3.0.0) \\
& (MRI) Ruby 1.9.2 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.9.2 & GMP 5.0.1 & (3.0.0) \\
& (RBX) Rubinius 1.1 & GMP 4.3.2 & (2.4.2) \\
& (RBX) Rubinius 1.1 & GMP 5.0.1 & (3.0.0) \\ \hline
Windows 7 on x86\_64 (64-bit) & (MRI) Ruby 1.8.7 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.8.7 & GMP 5.0.1 & (3.0.0) \\
& (MRI) Ruby 1.9.1 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.9.1 & GMP 5.0.1 & (3.0.0) \\
& (MRI) Ruby 1.9.2 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.9.2 & GMP 5.0.1 & (3.0.0) \\ \hline
Windows XP on x86 (32-bit) & (MRI) Ruby 1.9.1 & GMP 4.3.2 & (2.4.2) \\
& (MRI) Ruby 1.9.1 & GMP 5.0.1 & (3.0.0) \\ \hline
\end{tabular}\\\\
\newpage
In addition, I \textit{used to test} on the following environments, in versions
0.4.7 and earlier of the gmp gem:\\\\
\begin{tabular}{lrr} \hline
Platform & Ruby & GMP \\ \midrule[1pt]
Cygwin on x86 & (MRI) Ruby 1.8.7 & GMP 4.3.1 \\ \hline
Linux (LinuxMint 7) on x86 & (MRI) Ruby 1.8.7 & GMP 4.3.1 \\ \hline
Mac OS X 10.5.7 on x86 (32-bit) & (MRI) Ruby 1.8.6 & GMP 4.3.1 \\ \hline
Mac OS X 10.5.7 on x86 (32-bit) & (MRI) Ruby 1.9.1 & GMP 4.3.1 \\ \hline
\end{tabular}
\subsection{Installing}
You may clone the gmp gem's git repository with:\\
\\
\texttt{git clone git://github.com/srawlins/gmp.git}\\
Or you may install the gem from gemcutter (rubygems.org):\\
\\
\texttt{gem install gmp}\\
\newpage
At this time, the gem self-compiles. If required libraries cannot be found, you may
compile the C extensions manually with:\\
\\
\texttt{cd <gmp gem directory>/ext}\\
\texttt{ruby extconf.rb}\\
\texttt{make}\\
There shouldn't be any errors, or warnings.
\section{Testing the gmp gem}
Testing the gmp gem is quite simple. The test/unit\_tests.rb suite uses Unit::Test.
You can run this test suite with:\\
\\
\texttt{cd <gmp gem directory>/test}\\
\texttt{ruby unit\_tests.rb}\\
All tests should pass. If you don't have the test-unit gem installed, then you may
run into one error. It would look like:\\
\\
\texttt{ 1) Error:}\\
\texttt{test\_z\_div(TC\_division):}\\
\texttt{TypeError: GMP::Q can't be coerced into Float}\\
\texttt{ C:/Ruby191/devkit/msys/1.0.11/projects/gmp\_gem/test/tc\_division.rb:18:in `test\_z\_div'}\\
\section{GMP and gmp gem basics}
\subsection{Classes}
The gmp gem includes the namespace \texttt{GMP} and four classes within \texttt{GMP}:
\begin{itemize}
\item \texttt{GMP::Z} - Methods for signed integer arithmetic. There are about 64
methods here.
\item \texttt{GMP::Q} - Methods for rational number arithmetic. There are at least 11
methods here (still accounting).
\item \texttt{GMP::F} - Methods for floating-point arithmetic. There are at least 6
methods here (still accounting).
\item \texttt{GMP::RandState} - Methods for random number generation. There are 3
methods here.
\end{itemize}
In addition to the above four classes, there are also four constants within \texttt{GMP}:
\begin{itemize}
\item \texttt{GMP::GMP\_VERSION} - The version of GMP linked into the gmp gem
\item \texttt{GMP::GMP\_CC} - The compiler that compiled GMP linked into the gmp gem
\item \texttt{GMP::GMP\_CFLAGS} - The compiler flags used to compile GMP linked into
the gmp gem
\item \texttt{GMP::GMP\_BITS\_PER\_LIMB} - The number of bits per limb
\item \texttt{GMP::GMP\_NUMB\_MAX} - The maximum value that can be stored in the number
part of a limb.
\end{itemize}
\section{MPFR basics}
The gmp gem can optionally link to MPFR, the Multiple Precision Floating-Point Reliable
Library. The x86-mswin32 version of the gmp gem comes with MPFR. This library uses the
floating-point type from GMP, and thus the MPFR functions mapped in the gmp gem become
methods in \texttt{GMP::F}.
There are additional constants within \texttt{GMP} when MPFR is linked:
\begin{itemize}
\item \texttt{GMP::MPFR\_VERSION} - The version of MPFR linked into the gmp gem.
\item \texttt{GMP::MPFR\_PREC\_MIN} - The minimum precision available.
\item \texttt{GMP::MPFR\_PREC\_MAX} - The maximum precision available
\item \texttt{GMP::GMP\_RNDN} - Rounding mode representing "round to nearest."
\item \texttt{GMP::GMP\_RNDZ} - Rounding mode representing "round toward zero."
\item \texttt{GMP::GMP\_RNDU} - Rounding mode representing "round toward positive
infinity."
\item \texttt{GMP::GMP\_RNDD} - Rounding mode representing "round toward negative
infinity."
\item \texttt{GMP::MPFR\_RNDN} - Rounding mode representing "round to nearest."\\
(MPFR version 3.0.0 or higher only)
\item \texttt{GMP::MPFR\_RNDZ} - Rounding mode representing "round toward zero."\\
(MPFR version 3.0.0 or higher only)
\item \texttt{GMP::MPFR\_RNDU} - Rounding mode representing "round toward positive
infinity."\\
(MPFR version 3.0.0 or higher only)
\item \texttt{GMP::MPFR\_RNDD} - Rounding mode representing "round toward negative
infinity."\\
(MPFR version 3.0.0 or higher only)
\item \texttt{GMP::MPFR\_RNDZ} - Rounding mode representing "round away from zero."\\
(MPFR version 3.0.0 or higher only)
\end{itemize}
\newpage
\section{Integer Functions}
\subsection{Initializing, Assigning Integers}
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{new} & & GMP::Z.new $\rightarrow$ \textit{integer} \\
& & GMP::Z.new(\textit{numeric = 0}) $\rightarrow$ \textit{integer} \\
& & GMP::Z.new(\textit{str}, \textit{base = 0}) $\rightarrow$ \textit{integer} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
This method creates a new \gmpzs integer. It typically takes one optional argument for
the value of the integer. This argument can be one of several classes. If the first
argument is a String, then a second argument, the base, may be optionally supplied.
Here are some examples:\newline
\texttt{GMP::Z.new \qqqquad\qqqquad \#=> 0 (default) \newline
GMP::Z.new(1) \qqqquad\qquad\ \#=> 1 (Ruby Fixnum) \newline
GMP::Z.new("127") \qqqquad\ \#=> 127 (Ruby String)\newline
GMP::Z.new("FF", 16) \qquad\ \ \#=> 255 (Ruby String with base)\newline
GMP::Z.new("1Z", 36) \qquad\ \ \#=> 71 (Ruby String with base)\newline
GMP::Z.new(4294967296) \qquad \#=> 4294967296 (Ruby Bignum)\newline
GMP::Z.new(GMP::Z.new(31)) \#=> 31 (GMP Integer)}
}
\end{tabular}
\newline\newline
There is also a convenience method available, \texttt{GMP::Z()}.\\
\subsection{Converting Integers}
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{to\_d} & & \textit{integer}.to\_d $\rightarrow$ \textit{float} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns \textit{integer} as an Float if \textit{integer} fits in a Float.
Otherwise returns the least significant part of \texttt{integer}, with the same sign as
\textit{integer}.
If \textit{integer} is too big to fit in a Float, the returned result is probably not
very useful. To find out if the value will fit, use the function
\textit{mpz\_fits\_slong\_p} (\textbf{Unimplemented}).
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{to\_i} & & \textit{integer}.to\_i $\rightarrow$ \textit{fixnum} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns \textit{integer} as a Fixnum if \textit{integer} fits in a Fixnum.
\newline
Otherwise returns the least significant part of \textit{integer}, with the same sign as
\textit{integer}.
\newline
If \textit{integer} is too big to fit in a \textit{Fixnum}, the returned result is
probably not very useful. To find out if the value will fit, use the function
\textit{mpz\_fits\_slong\_p} (\textbf{Unimplemented}).
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{to\_s} & & \textit{integer}.to\_s(\textit{base = 10}) $\rightarrow$ \textit{str} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Converts \textit{integer} to a string of digits in base \textit{base}. The
\textit{base} argument may vary from 2 to 62 or from -2 to -36, or be a symbol, one of
\textit{:bin}, \textit{:oct}, \textit{:dec}, or \textit{:hex}.
\newline
For \textit{base} in the range 2..36, digits and lower-case letters are used; for
-2..-36 (and \textit{:bin}, \textit{:oct}, \textit{:dec}, and \textit{:hex}), digits
and upper-case letters are used; for 37..62, digits, upper-case letters, and lower-case
letters (in that significance order) are used. Here are some
examples:\newline
\texttt{GMP::Z(1).to\_s \qqqquad \#=> "1" \newline
GMP::Z(32).to\_s(2) \qquad \#=> "100000" \newline
GMP::Z(32).to\_s(4) \qquad \#=> "200" \newline
GMP::Z(10).to\_s(16) \quad\ \#=> "a" \newline
GMP::Z(10).to\_s(-16) \quad \#=> "A" \newline
GMP::Z(255).to\_s(:bin) \#=> "11111111" \newline
GMP::Z(255).to\_s(:oct) \#=> "377" \newline
GMP::Z(255).to\_s(:dec) \#=> "255" \newline
GMP::Z(255).to\_s(:hex) \#=> "ff"}
}
\end{tabular}
\subsection{Integer Arithmetic}
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{+} & & \textit{integer} + \textit{numeric} $\rightarrow$ \textit{numeric} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the sum of \textit{integer} and \textit{numeric}. \textit{numeric} can be an
instance of \gmpz, \textit{Fixnum}, \gmpq, \gmpf, or \textit{Bignum}.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{add!} & & \textit{integer}.add!(\textit{numeric}) $\rightarrow$
\textit{numeric} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Sums \textit{integer} and \textit{numeric}, in place. \textit{numeric} can be an
instance of \gmpz, \textit{Fixnum}, \gmpq, \gmpf, or \textit{Bignum}.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{-} & & \textit{integer} - \textit{numeric} $\rightarrow$ \textit{numeric} \\
& & \textit{integer}.sub!(\textit{numeric}) $\rightarrow$ \textit{numeric} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the difference of \textit{integer} and \textit{numeric}. The destructive method
calculates the difference in place. \textit{numeric} can be an instance of
\gmpz, \textit{Fixnum}, \gmpq, \gmpf, or \textit{Bignum}. Here are some
examples:\newline
\texttt{seven = GMP::Z(7) \newline
nine \ = GMP::Z(9) \newline
half \ = GMP::Q(1,2) \newline
pi \quad\ = GMP::F("3.14") \newline
nine - 5 \qquad\quad \#=> 4 (GMP Integer) \newline
nine - seven \quad \#=> 2 (GMP Integer) \newline
nine - (2**32) \#=> -4294967287 (GMP Integer) \newline
nine - nine \quad\ \#=> 0 (GMP Integer) \newline
nine - half \quad\ \#=> 8.5 (GMP Rational) \newline
nine - pi \qquad\ \#=> 5.86 (GMP Float)}
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{*} & & \textit{integer} * \textit{numeric} $\rightarrow$ \textit{numeric} \\
& & \textit{integer}.mul(\textit{numeric}) $\rightarrow$ \textit{numeric} \\
& & \textit{integer}.mul!(\textit{numeric}) $\rightarrow$ \textit{numeric} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the product of \textit{integer} and \textit{numeric}. The destructive method
calculates the product in place. \textit{numeric} can be an instance of
\gmpz, \textit{Fixnum}, \gmpq, \gmpf, or \textit{Bignum}.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{addmul!} & & \textit{integer}.addmul!(\textit{b}, \textit{c}) $\rightarrow$ \textit{numeric} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Sets \textit{integer} to the sum of \textit{integer} and the product of \textit{b} and
\textit{c}. This destructive method calculates the result in place. Both \textit{b} and
\textit{c} can be an instance of \gmpz, \textit{Fixnum}, or \textit{Bignum}.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{submul!} & & \textit{integer}.submul!(\textit{b}, \textit{c}) $\rightarrow$ \textit{numeric} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Sets \textit{integer} to the difference of \textit{integer} and the product of \textit{b} and
\textit{c}. This destructive method calculates the result in place. Both \textit{b} and
\textit{c} can be an instance of \gmpz, \textit{Fixnum}, or \textit{Bignum}.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{\textless\textless} & & \textit{integer} \textless\textless \textit{numeric} $\rightarrow$ \textit{integer} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns \textit{integer} times 2 to the \textit{numeric} power. This can also be
defined as a left shift by \textit{numeric} bits.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{-@} & & -\textit{integer}\\
& & \textit{integer}.neg\\
& & \textit{integer}.neg!\\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the negation, the additive inverse, of \textit{integer}. The destructive method
negates in place.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{abs} & & \textit{integer}.abs\\
& & \textit{integer}.abs!\\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the absolute value of \textit{integer}. The destructive method calculates the
absolute value in place.
}
\end{tabular}
\subsection{Integer Division}
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{tdiv} & & $integer$.tdiv($numeric$) $\rightarrow$ $integer$\\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the division of $integer$ by $numeric$, truncated. $numeric$ can be an instance
of \gmpz, $Fixnum$, $Bignum$. The return object's class is always \gmpz.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{fdiv} & & $integer$.fdiv($numeric$) $\rightarrow$ $integer$\\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the division of $integer$ by $numeric$, floored. $numeric$ can be an instance
of \gmpz, $Fixnum$, $Bignum$. The return object's class is always \gmpz.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{cdiv} & & $integer$.cdiv($numeric$) $\rightarrow$ $integer$\\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the ceiling division of $integer$ by $numeric$. $numeric$ can be an instance of
\gmpz, $Fixnum$, $Bignum$. The return object's class is always \gmpz.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{tmod} & & $integer$.tmod($numeric$) $\rightarrow$ $integer$\\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the remainder after truncated division of $integer$ by $numeric$. $numeric$ can
be an instance of \gmpz, $Fixnum$, or $Bignum$. The return object's class is always
\gmpz.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{fmod} & & $integer$.fmod($numeric$) $\rightarrow$ $integer$\\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the remainder after floored division of $integer$ by $numeric$. $numeric$ can
be an instance of \gmpz, $Fixnum$, or $Bignum$. The return object's class is always
\gmpz.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{cmod} & & \textit{integer}.cmod(\textit{numeric}) $\rightarrow$ \textit{integer}\\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the remainder after ceilinged division of $integer$ by $numeric$. $numeric$ can
be an instance of \gmpz, $Fixnum$, or $Bignum$. The return object's class is always
\gmpz.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{\%} & & \textit{integer} \% \textit{numeric} $\rightarrow$ \textit{integer}\\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns $integer$ modulo $numeric$. $numeric$ can be an instance of \gmpz, $Fixnum$,
or $Bignum$. The return object's class is always \gmpz.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{divisible?} & & \textit{integer}.divisible? \textit{numeric} $\rightarrow$ \textit{boolean}\\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns whether $integer$ is divisible by $numeric$. $numeric$ can be an instance of \gmpz, $Fixnum$,
or $Bignum$.
}
\end{tabular}
\newpage
\subsection{Integer Exponentiation}
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{**} & & \textit{integer} ** \textit{numeric} $\rightarrow$ \textit{numeric} \\
& & \textit{integer}.pow(\textit{numeric}) $\rightarrow$ \textit{numeric} \\
& & GMP::Z.pow(\textit{integer}, \textit{numeric}) $\rightarrow$ \textit{numeric} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns $integer$ raised to the $numeric$ power. In the singleton method (\textit{GMP::Z.pow()}),
\textit{integer} can be either a \gmpz, $Fixnum$, $Bignum$, or $String$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{powmod} & & \textit{integer}.powmod(\textit{exp}, \textit{mod}) $\rightarrow$ \textit{integer} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns $integer$ raised to the $exp$ power, modulo $mod$. Negative $exp$ is supported
if an inverse, $integer^{-1}$ modulo $mod$, exists. If an inverse doesn't exist then a
divide by zero exception is raised.
}
\end{tabular}
\subsection{Integer Roots}
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{root} & & \textit{integer}.root(\textit{numeric}) $\rightarrow$ \textit{numeric} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the integer part of the $numeric$'th root of $integer$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{sqrt} & & \textit{integer}.sqrt $\rightarrow$ \textit{numeric} \\
& & \textit{integer}.sqrt! $\rightarrow$ \textit{numeric} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the truncated integer part of the square root of $integer$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{sqrtrem} & & \textit{integer}.sqrtrem $\rightarrow$ \textit{sqrt}, \textit{rem} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the truncated integer part of the square root of $integer$ as $sqrt$ and the
remainder, $integer - sqrt * sqrt$, as $rem$, which will be zero if $integer$ is a
perfect square.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{power?} & & \textit{integer}.power? $\rightarrow$ \textit{true} \textbar\ \textit{false} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns true if $integer$ is a perfect power, i.e., if there exist integers $a$ and
$b$, with $b > 1$, such that $integer$ equals $a$ raised to the power $b$.
\newline\newline
Under this definition both 0 and 1 are considered to be perfect powers. Negative values
of integers are accepted, but of course can only be odd perfect powers.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{square?} & & \textit{integer}.square? $\rightarrow$ \textit{true} \textbar\ \textit{false} \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns true if $integer$ is a perfect square, i.e., if the square root of
$integer$ is an integer. Under this definition both 0 and 1 are considered to be
perfect squares.
}
\end{tabular}
\subsection{Number Theoretic Functions}
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{probab\_prime?} & & $integer$.probab\_prime?($reps = 5$) $\rightarrow$ 0, 1, or 2 \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Determine whether $integer$ is prime. Returns 2 if $integer$ is definitely prime,
returns 1 if $integer$ is probably prime (without being certain), or returns 0 if
$integer$ is definitely composite.
\newline\newline
This function does some trial divisions, then some Miller-Rabin probabilistic primality
tests. $reps$ controls how many such tests are done, 5 to 10 is a reasonable number,
more will reduce the chances of a composite being returned as probably prime.
\newline\newline
Miller-Rabin and similar tests can be more properly called compositeness tests. Numbers
which fail are known to be composite but those which pass might be prime or might be
composite. Only a few composites pass, hence those which pass are considered probably
prime.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{next\_prime} & & $integer$.next\_prime $\rightarrow$ $prime$ \\
& & $integer$.nextprime $\rightarrow$ $prime$ \\
& & $integer$.next\_prime! $\rightarrow$ $prime$ \\
& & $integer$.nextprime! $\rightarrow$ $prime$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the next prime greater than $integer$. The destructive method sets $integer$ to
the next prime greater than $integer$.
\newline\newline
This function uses a probabilistic algorithm to identify primes. For practical purposes
it's adequate, the chance of a composite passing will be extremely small.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{gcd} & & $a$.gcd($b$) $\rightarrow$ $g$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Computes the greatest common divisor of $a$ and $b$. $g$ will always be positive, even
if $a$ or $b$ is negative. $b$ can be an instance of \gmpz, $Fixnum$, or $Bignum$.
\newline\newline
\texttt{GMP::Z(24).gcd(GMP::Z(8)) \quad \#=> GMP::Z(8) \newline
GMP::Z(24).gcd(8) \quad \#=> GMP::Z(8) \newline
GMP::Z(24).gcd(2**32) \quad \#=> GMP::Z(8)}
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{gcdext} & & $a$.gcd($b$) $\rightarrow$ $g$, $s$, $t$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Computes the greatest common divisor of $a$ and $b$, in addition to $s$ and $t$, the
coefficients satisfying $a*s + b*t = g$. $g$ will always be positive, even if $a$ or
$b$ is negative. $s$ and $t$ are chosen such that $|s| <= |b|$ and $|t| <= |a|$. $b$
can be an instance of \gmpz, $Fixnum$, or $Bignum$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{invert} & & $a$.invert($m$) $\rightarrow$ $integer$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Computes the inverse of $a$ mod $m$. $m$ can be an instance of \gmpz, $Fixnum$, or
$Bignum$.
\newline\newline
\texttt{GMP::Z(2).invert(GMP::Z(11)) \quad \#=> GMP::Z(6) \newline
GMP::Z(3).invert(11) \quad \#=> GMP::Z(4) \newline
GMP::Z(5).invert(11) \quad \#=> GMP::Z(9)}
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{jacobi} & & $a$.jacobi($b$) $\rightarrow$ $integer$ \\
& & GMP::Z.jacobi($a$, $b$) $\rightarrow$ $integer$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the Jacobi symbol $(a/b)$. This is defined only for $b$ odd. If $b$ is even, a
range exception will be raised.
\newline\newline
\textit{GMP::Z.jacobi} (the instance method) requires $b$ to be an instance of \gmpz.
\newline
\textit{GMP::Z\#jacobi} (the class method) requires $a$ and $b$ each to be an instance of
\gmpz, $Fixnum$, or $Bignum$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{legendre} & & $a$.legendre($b$) $\rightarrow$ $integer$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns the Legendre symbol $(a/b)$. This is defined only for $p$ an odd positive
prime. If $p$ is even, negative, or composite, a range exception will be raised.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{remove} & & $n$.remove($factor$) $\rightarrow$ ($integer$, $times$) \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Remove all occurrences of the factor $factor$ from $n$. $factor$ can be an instance of
\gmpz, $Fixnum$, or $Bignum$. $integer$ is the resulting integer, an instance of
\gmpz. $times$ is how many times $factor$ was removed, a $Fixnum$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{fac} & & GMP::Z.fac($n$) $\rightarrow$ $integer$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns $n!$, or, $n$ factorial.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{fib} & & GMP::Z.fib($n$) $\rightarrow$ $integer$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns $F[n]$, the $n$th Fibonacci number.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{fib2} & & GMP::Z.fib2($n$) $\rightarrow$ $integer$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns $F[n]$ and $F[n-1]$, the $n$th and $n-1$th Fibonacci numbers.
}
\end{tabular}
\subsection{Integer Comparisons}
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{\textless=\textgreater} & & $a$ \textless=\textgreater\ $b$ $\rightarrow$ $fixnum$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns a negative Fixnum if $a$ is less than $b$.\newline
Returns 0 if $a$ is equal to $b$.\newline
Returns a positive Fixnum if $a$ is greater than $b$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{\textless} & & $a$ \textless\ $b$ $\rightarrow$ $boolean$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns true if $a$ is less than $b$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{\textless=} & & $a$ \textless=\ $b$ $\rightarrow$ $boolean$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns true if $a$ is less than or equal to $b$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{==} & & $a$ == $b$ $\rightarrow$ $boolean$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns true if $a$ is equal to $b$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{\textgreater=} & & $a$ \textgreater= $b$ $\rightarrow$ $boolean$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns true if $a$ is greater than or equal to $b$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{\textgreater} & & $a$ \textgreater\ $b$ $\rightarrow$ $boolean$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns true if $a$ is greater than $b$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{cmpabs} & & $a$.cmpabs($b$) $\rightarrow$ $fixnum$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns a negative Fixnum if abs($a$) is less than abs($b$).\newline
Returns 0 if abs($a$) is equal to abs($b$).\newline
Returns a positive Fixnum if abs($a$) is greater than abs($b$).
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{sgn} & & $a$.sgn $\rightarrow$ $-1$, $0$, or $1$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns -1 if $a$ is less than $b$.\newline
Returns 0 if $a$ is equal to $b$.\newline
Returns 1 if $a$ is greater than $b$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{eql?} & & $a$.eql?($b$) $\rightarrow$ $boolean$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Used when comparing objects as Hash keys.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{hash} & & $a$.hash $\rightarrow$ $string$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Used when comparing objects as Hash keys.
}
\end{tabular}
\subsection{Integer Logic and Bit Fiddling}
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{and} & & $a$ \& $b$ $\rightarrow$ $integer$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns $integer$, the bitwise and of $a$ and $b$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}
\toprule
\textbf{ior} & & $a$ \textbar\ $b$ $\rightarrow$ $integer$ \\
\cmidrule(r){2-3}
& \multicolumn{2}{p{\defnwidth}}{
Returns $integer$, the bitwise inclusive or of $a$ and $b$.
}
\end{tabular}
\newline\newline
\begin{tabular}{p{\methwidth} l r}