gmp 0.5.41 → 0.5.47

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/CHANGELOG +21 -0
  2. data/FEATURES.html +37 -38
  3. data/README.html +511 -0
  4. data/README.markdown +494 -0
  5. data/benchmark/divide +0 -0
  6. data/benchmark/gcd +0 -0
  7. data/benchmark/multiply +0 -0
  8. data/benchmark/multiply.fnl +0 -0
  9. data/benchmark/multiply.gc +0 -0
  10. data/benchmark/pi +0 -0
  11. data/benchmark/rsa +0 -0
  12. data/benchmark/runbench +0 -0
  13. data/benchmark/srb.sh +0 -0
  14. data/ext/gmp.c +0 -42
  15. data/ext/gmpf.c +64 -33
  16. data/ext/gmpq.c +88 -1
  17. data/ext/gmpz.c +151 -19
  18. data/ext/ruby_gmp.h +16 -10
  19. data/manual.pdf +0 -0
  20. data/manual.tex +50 -14
  21. data/test/gmp_tgcd.rb +18 -18
  22. data/test/mpfr_tcbrt.rb +1 -1
  23. data/test/mpfr_tconst_euler.rb +10 -7
  24. data/test/mpfr_tisnan.rb +1 -1
  25. data/test/mpfr_trec_sqrt.rb +1 -1
  26. data/test/mpfr_tsqrt.rb +1 -1
  27. data/test/tc_cmp.rb +7 -2
  28. data/test/tc_constants.rb +1 -1
  29. data/test/tc_division.rb +1 -1
  30. data/test/tc_f_arithmetics_coersion.rb +1 -1
  31. data/test/tc_f_precision.rb +1 -1
  32. data/test/tc_fib_fac_nextprime.rb +1 -1
  33. data/test/tc_floor_ceil_truncate.rb +1 -1
  34. data/test/tc_hashes.rb +26 -1
  35. data/test/tc_logical_roots.rb +1 -1
  36. data/test/tc_mpfr_constants.rb +1 -1
  37. data/test/tc_mpfr_functions.rb +1 -1
  38. data/test/tc_mpfr_random.rb +1 -1
  39. data/test/tc_mpfr_rounding.rb +3 -3
  40. data/test/tc_q.rb +1 -1
  41. data/test/tc_q_basic.rb +1 -1
  42. data/test/tc_random.rb +1 -1
  43. data/test/tc_sgn_neg_abs.rb +1 -1
  44. data/test/tc_swap.rb +1 -1
  45. data/test/tc_z.rb +34 -1
  46. data/test/tc_z_addmul.rb +1 -1
  47. data/test/tc_z_basic.rb +1 -1
  48. data/test/tc_z_exponentiation.rb +1 -1
  49. data/test/tc_z_functional_mappings.rb +42 -6
  50. data/test/tc_z_gcd_lcm_invert.rb +1 -1
  51. data/test/tc_z_jac_leg_rem.rb +1 -1
  52. data/test/tc_z_logic.rb +1 -1
  53. data/test/tc_z_shifts_last_bits.rb +1 -1
  54. data/test/tc_z_submul.rb +1 -1
  55. data/test/tc_z_to_dis.rb +1 -1
  56. data/test/tc_zerodivisionexceptions.rb +1 -1
  57. data/test/test_helper.rb +2 -1
  58. data/test/unit_tests.rb +1 -1
  59. metadata +70 -89
  60. data/README.rdoc +0 -450
data/ext/gmpz.c CHANGED
@@ -249,7 +249,7 @@ FUNC_MAP__Z_ZUI__TO__Z__RETURNS__VOID(lcm,mpz_lcm)
249
249
  * FUNC_MAP__ZUI_ZUI__TO__Z__RETURNS__VOID defines a GMP::Z singleton function that takes
250
250
  * a GMP::Z as rop, a GMP::Z, Bignum, or Fixnum as op1, and a GMP::Z, Bignum, or Fixnum
251
251
  * as op2. It calls mpz_fname, whose arguments are rop (the return argument), op1, and
252
- * op2. If op1 is a Fixnum and >=0, xor if op2 is a Fixnum and >= 0, one ui variant or
252
+ * op2. If op1 is a Fixnum and >= 0, xor if op2 is a Fixnum and >= 0, one ui variant or
253
253
  * the other of mpz_fname will be used:
254
254
  *
255
255
  * op2 --> | FIXNUM >=0 | FIXNUM < 0 | BIGNUM | GMP::Z |
@@ -453,6 +453,114 @@ FUNC_MAP__Z__TO__Z__RETURNS__VOID(sqrt,mpz_sqrt)
453
453
  FUNC_MAP__Z__TO__Z__RETURNS__VOID(nextprime,mpz_nextprime)
454
454
  FUNC_MAP__Z__TO__Z__RETURNS__VOID(com,mpz_com)
455
455
 
456
+ /*
457
+ * 09 mpz_t__mpz_t_or_ui__to__none__returns__int
458
+ * FUNC_MAP__Z_Z__TO__VOID__RETURNS__BOOL defines a GMP::Z singleton function that
459
+ * doesn't take a rop, a GMP::Z as op1, and a GMP::Z, Fixnum, or Bignum as op2. It calls
460
+ * mpz_fname[_ui]_p, whose arguments are op1 and op2.
461
+ *
462
+ * TODO: Accept Fixnum, Bignum as op1 and just convert to GMP::Z.
463
+ */
464
+ #define FUNC_MAP__Z_Z__TO__VOID__RETURNS__BOOL(fname,mpz_fname) \
465
+ static VALUE r_gmpzsg_##fname(VALUE klass, VALUE op1, VALUE op2) \
466
+ { \
467
+ MP_INT *op1_val, *op2_val; \
468
+ int res; \
469
+ (void)klass; \
470
+ \
471
+ if (! GMPZ_P (op1)) { \
472
+ typeerror_as (Z, "op1"); \
473
+ } \
474
+ mpz_get_struct (op1, op1_val); \
475
+ \
476
+ if (FIXNUM_P (op2)) { \
477
+ if (FIX2NUM (op2) >= 0) { \
478
+ res = mpz_fname##_ui_p (op1_val, FIX2NUM (op2)); \
479
+ } else { \
480
+ mpz_temp_alloc (op2_val); \
481
+ mpz_init_set_si (op2_val, FIX2NUM (op2)); \
482
+ res = mpz_fname##_p (op1_val, op2_val); \
483
+ mpz_temp_free (op2_val); \
484
+ } \
485
+ } else if (BIGNUM_P (op2)) { \
486
+ mpz_temp_from_bignum (op2_val, op2); \
487
+ res = mpz_fname##_p (op1_val, op2_val); \
488
+ mpz_temp_free (op2_val); \
489
+ } else if (GMPZ_P (op2)) { \
490
+ mpz_get_struct (op2, op2_val); \
491
+ res = mpz_fname##_p (op1_val, op2_val); \
492
+ } else { \
493
+ typeerror_as (ZXB, "op2"); \
494
+ } \
495
+ \
496
+ return (res ? Qtrue : Qfalse); \
497
+ }
498
+
499
+ FUNC_MAP__Z_Z__TO__VOID__RETURNS__BOOL(divisible,mpz_divisible)
500
+
501
+ /*
502
+ * 11 mpz_t__mpz_t_or_ui__mpz_t_or_ui__to__none__returns__int
503
+ * FUNC_MAP__Z_ZXB_ZXB__TO__VOID__RETURNS__BOOL defines a GMP::Z singleton function that
504
+ * doesn't take a rop, a GMP::Z as op1, and a GMP::Z, Fixnum, or Bignum as both op2 and
505
+ * op3. It calls mpz_fname[_ui]_p, whose arguments are op1, op2, and op3.
506
+ *
507
+ * TODO: Accept Fixnum, Bignum as op1 and just convert to GMP::Z.
508
+ */
509
+ #define FUNC_MAP__Z_ZXB_ZXB__TO__VOID__RETURNS__BOOL(fname,mpz_fname) \
510
+ static VALUE r_gmpzsg_##fname(VALUE klass, VALUE op1, VALUE op2, VALUE op3) \
511
+ { \
512
+ MP_INT *op1_val, *op2_val, *op3_val; \
513
+ int res; \
514
+ int free_op2_val = 0; \
515
+ int free_op3_val = 0; \
516
+ (void)klass; \
517
+ \
518
+ if (! GMPZ_P (op1)) { \
519
+ typeerror_as (Z, "op1"); \
520
+ } \
521
+ mpz_get_struct (op1, op1_val); \
522
+ \
523
+ if (FIXNUM_P (op2)) { \
524
+ if (FIX2NUM (op2) >= 0) { \
525
+ if (FIXNUM_P (op3) && FIX2NUM (op3) >= 0) { \
526
+ res = mpz_fname##_ui_p (op1_val, FIX2NUM (op2), FIX2NUM (op3)); \
527
+ return (res ? Qtrue : Qfalse); \
528
+ } \
529
+ } \
530
+ mpz_temp_alloc (op2_val); \
531
+ mpz_init_set_si (op2_val, FIX2NUM (op2)); \
532
+ free_op2_val = 1; \
533
+ } else if (BIGNUM_P (op2)) { \
534
+ mpz_temp_from_bignum (op2_val, op2); \
535
+ free_op2_val = 1; \
536
+ } else if (GMPZ_P (op2)) { \
537
+ mpz_get_struct (op2, op2_val); \
538
+ } else { \
539
+ typeerror_as (ZXB, "op2"); \
540
+ } \
541
+ \
542
+ if (FIXNUM_P (op3)) { \
543
+ mpz_temp_alloc (op3_val); \
544
+ mpz_init_set_si (op3_val, FIX2NUM (op3)); \
545
+ free_op3_val = 1; \
546
+ } else if (BIGNUM_P (op3)) { \
547
+ mpz_temp_from_bignum (op3_val, op3); \
548
+ free_op3_val = 1; \
549
+ } else if (GMPZ_P (op3)) { \
550
+ mpz_get_struct (op3, op3_val); \
551
+ } else { \
552
+ typeerror_as (ZXB, "op3"); \
553
+ } \
554
+ \
555
+ res = mpz_fname##_p (op1_val, op2_val, op3_val); \
556
+ if (free_op2_val) { free(op2_val); } \
557
+ if (free_op3_val) { free(op3_val); } \
558
+ \
559
+ return (res ? Qtrue : Qfalse); \
560
+ }
561
+
562
+ FUNC_MAP__Z_ZXB_ZXB__TO__VOID__RETURNS__BOOL(congruent,mpz_congruent)
563
+
456
564
 
457
565
  /**********************************************************************
458
566
  * Initializing, Assigning Integers *
@@ -471,13 +579,15 @@ FUNC_MAP__Z__TO__Z__RETURNS__VOID(com,mpz_com)
471
579
  * * Bignum
472
580
  *
473
581
  * @example
474
- * GMP::Z.new(5) #=> 5
475
- * GMP::Z.new(2**32) #=> 4_294_967_296
476
- * GMP::Z.new(2**101) #=> 2_535_301_200_456_458_802_993_406_410_752
477
- * GMP::Z.new("20") #=> 20
478
- * GMP::Z.new("0x20") #=> 32
479
- * GMP::Z.new("020") #=> 16
480
- * GMP::Z.new("0b101") #=> 5
582
+ * GMP::Z.new(5) #=> 5
583
+ * GMP::Z.new(2**32) #=> 4_294_967_296
584
+ * GMP::Z.new(2**101) #=> 2_535_301_200_456_458_802_993_406_410_752
585
+ * GMP::Z.new("20") #=> 20
586
+ * GMP::Z.new("0x20") #=> 32
587
+ * GMP::Z.new("020") #=> 16
588
+ * GMP::Z.new("0b101") #=> 5
589
+ * GMP::Z.new("20", 16) #=> 32
590
+ * GMP::Z.new("1Z", 36) #=> 71
481
591
  */
482
592
  VALUE r_gmpzsg_new(int argc, VALUE *argv, VALUE klass)
483
593
  {
@@ -485,8 +595,8 @@ VALUE r_gmpzsg_new(int argc, VALUE *argv, VALUE klass)
485
595
  VALUE res;
486
596
  (void)klass;
487
597
 
488
- if (argc > 1)
489
- rb_raise(rb_eArgError, "wrong # of arguments (%d for 0 or 1)", argc);
598
+ if (argc > 2)
599
+ rb_raise(rb_eArgError, "wrong # of arguments (%d for 0, 1, or 2)", argc);
490
600
 
491
601
  mpz_make_struct(res, res_val);
492
602
  mpz_init(res_val);
@@ -498,10 +608,30 @@ VALUE r_gmpzsg_new(int argc, VALUE *argv, VALUE klass)
498
608
  VALUE r_gmpz_initialize(int argc, VALUE *argv, VALUE self)
499
609
  {
500
610
  MP_INT *self_val;
611
+ int base = 0;
612
+
613
+ // Set up the base if 2 arguments are passed
614
+ if (argc == 2) { // only ok if String, Fixnum
615
+ if (STRING_P(argv[0])) { // first arg must be a String
616
+ if (FIXNUM_P(argv[1])) { // second arg must be a Fixnum
617
+ base = FIX2INT(argv[1]);
618
+ if ( base != 0 && ( base < 2 || base > 62) )
619
+ rb_raise (rb_eRangeError, "base must be either 0 or between 2 and 62");
620
+ } else {
621
+ rb_raise (rb_eTypeError, "base must be a Fixnum between 2 and 62, not a %s.", rb_class2name (rb_class_of (argv[1])));
622
+ }
623
+ } else {
624
+ rb_raise(
625
+ rb_eTypeError,
626
+ "GMP::Z.new() must be passed a String as the 1st argument (not a %s), if a base is passed as the 2nd argument.",
627
+ rb_class2name (rb_class_of (argv[0]))
628
+ );
629
+ }
630
+ }
501
631
 
502
632
  if (argc != 0) {
503
- mpz_get_struct(self,self_val);
504
- mpz_set_value (self_val, argv[0]);
633
+ mpz_get_struct (self,self_val);
634
+ mpz_set_value (self_val, argv[0], base);
505
635
  }
506
636
  return Qnil;
507
637
  }
@@ -518,7 +648,7 @@ VALUE r_gmpz_initialize(int argc, VALUE *argv, VALUE self)
518
648
  * * String
519
649
  * * Bignum
520
650
  */
521
- void mpz_set_value(MP_INT *target, VALUE source)
651
+ void mpz_set_value(MP_INT *target, VALUE source, int base)
522
652
  {
523
653
  MP_INT *source_val;
524
654
 
@@ -528,7 +658,7 @@ void mpz_set_value(MP_INT *target, VALUE source)
528
658
  } else if (FIXNUM_P(source)) {
529
659
  mpz_set_si(target, FIX2NUM(source));
530
660
  } else if (STRING_P(source)) {
531
- mpz_set_str(target, StringValuePtr(source), 0);
661
+ mpz_set_str(target, StringValuePtr(source), base);
532
662
  } else if (BIGNUM_P(source)) {
533
663
  mpz_set_bignum(target, source);
534
664
  } else {
@@ -661,8 +791,8 @@ VALUE r_gmpz_to_s(int argc, VALUE *argv, VALUE self)
661
791
  ID bin_base_id = rb_intern(bin_base);
662
792
  ID oct_base_id = rb_intern(oct_base);
663
793
  ID dec_base_id = rb_intern(dec_base);
664
- ID hex_base_id = rb_intern(hex_base);
665
-
794
+ ID hex_base_id = rb_intern(hex_base);
795
+
666
796
  rb_scan_args(argc, argv, "01", &base);
667
797
  if (NIL_P(base)) { base = INT2FIX(10); } /* default value */
668
798
  if (FIXNUM_P(base)) {
@@ -2093,7 +2223,7 @@ VALUE r_gmpz_sgn(VALUE self)
2093
2223
  *
2094
2224
  * Returns true if _a_ is equal to _b_. _a_ and _b_ must then be equal in cardinality,
2095
2225
  * and both be instances of GMP::Z. Otherwise, returns false. a.eql?(b) if and only if
2096
- * a.hash == b.hash.
2226
+ * b.class == GMP::Z, and a.hash == b.hash.
2097
2227
  */
2098
2228
  VALUE r_gmpz_eql(VALUE self, VALUE arg)
2099
2229
  {
@@ -2117,7 +2247,7 @@ VALUE r_gmpz_eql(VALUE self, VALUE arg)
2117
2247
  *
2118
2248
  * Returns the computed hash value of _a_. This method first converts _a_ into a String
2119
2249
  * (base 10), then calls String#hash on the result, returning the hash value. a.eql?(b)
2120
- * if and only if a.hash == b.hash.
2250
+ * if and only if b.class == GMP::Z, and a.hash == b.hash.
2121
2251
  */
2122
2252
  VALUE r_gmpz_hash(VALUE self)
2123
2253
  {
@@ -2452,13 +2582,15 @@ void init_gmpz()
2452
2582
  rb_define_method(cGMP_Z, "%", r_gmpz_mod, 1);
2453
2583
  rb_define_method(cGMP_Z, "divisible?", r_gmpz_divisible, 1);
2454
2584
  // Functional Mappings
2455
- rb_define_singleton_method(cGMP_Z, "divexact", r_gmpzsg_divexact, 3);
2585
+ rb_define_singleton_method(cGMP_Z, "divexact", r_gmpzsg_divexact, 3);
2456
2586
  rb_define_singleton_method(cGMP_Z, "cdiv_q_2exp", r_gmpzsg_cdiv_q_2exp, 3);
2457
2587
  rb_define_singleton_method(cGMP_Z, "cdiv_r_2exp", r_gmpzsg_cdiv_r_2exp, 3);
2458
2588
  rb_define_singleton_method(cGMP_Z, "fdiv_q_2exp", r_gmpzsg_fdiv_q_2exp, 3);
2459
2589
  rb_define_singleton_method(cGMP_Z, "fdiv_r_2exp", r_gmpzsg_fdiv_r_2exp, 3);
2460
2590
  rb_define_singleton_method(cGMP_Z, "tdiv_q_2exp", r_gmpzsg_tdiv_q_2exp, 3);
2461
2591
  rb_define_singleton_method(cGMP_Z, "tdiv_r_2exp", r_gmpzsg_tdiv_r_2exp, 3);
2592
+ rb_define_singleton_method(cGMP_Z, "divisible?", r_gmpzsg_divisible, 2);
2593
+ rb_define_singleton_method(cGMP_Z, "congruent?", r_gmpzsg_congruent, 3);
2462
2594
 
2463
2595
  // Integer Exponentiation
2464
2596
  rb_define_singleton_method(cGMP_Z, "pow", r_gmpzsg_pow, 2);
@@ -66,9 +66,14 @@ typedef __gmp_randstate_struct MP_RANDSTATE;
66
66
  #define GMPQ_P(value) (rb_obj_is_instance_of(value, cGMP_Q) == Qtrue)
67
67
  #define GMPF_P(value) (rb_obj_is_instance_of(value, cGMP_F) == Qtrue)
68
68
  #define mpz_set_bignum(var_mpz,var_bignum) { \
69
- VALUE tmp = rb_funcall (var_bignum, rb_intern ("to_s"), 1, INT2FIX(32)); \
69
+ VALUE tmp = rb_funcall (rb_funcall (var_bignum, rb_intern ("to_s"), 1, INT2FIX(32)), rb_intern("upcase"), 0); \
70
70
  mpz_set_str (var_mpz, StringValuePtr (tmp), 32); \
71
71
  }
72
+ /*VALUE tmp = rb_funcall (var_bignum, rb_intern ("to_s"), 1, INT2FIX(32)); \*/
73
+ /*#define mpz_set_bignum(var_mpz,var_bignum) { \
74
+ VALUE tmp = rb_funcall (var_bignum, rb_intern ("to_s"), 0); \
75
+ mpz_set_str (var_mpz, StringValuePtr (tmp), 10); \
76
+ }*/
72
77
  #define mpz_temp_alloc(var) { var=malloc(sizeof(MP_INT)); }
73
78
  #define mpz_temp_init(var) { mpz_temp_alloc(var); mpz_init(var); }
74
79
  #define mpz_temp_from_bignum(var,var_bignum) { \
@@ -160,7 +165,7 @@ extern void r_gmprandstate_free(void *ptr);
160
165
  // Initializing, Assigning Integers
161
166
  extern VALUE r_gmpzsg_new(int argc, VALUE *argv, VALUE klass);
162
167
  extern VALUE r_gmpz_initialize(int argc, VALUE *argv, VALUE self);
163
- extern void mpz_set_value(MP_INT *target, VALUE source);
168
+ extern void mpz_set_value(MP_INT *target, VALUE source, int base);
164
169
  extern VALUE r_gmpmod_z(int argc, VALUE *argv, VALUE module);
165
170
  extern VALUE r_gmpz_swap(VALUE self, VALUE arg);
166
171
 
@@ -218,6 +223,7 @@ extern VALUE r_gmpz_size_in_bin(VALUE self);
218
223
 
219
224
  // Initializing Rationals
220
225
  extern VALUE r_gmpqsg_new(int argc, VALUE *argv, VALUE klass);
226
+ extern VALUE r_gmpq_initialize(int argc, VALUE *argv, VALUE self);
221
227
  extern VALUE r_gmpmod_q(int argc, VALUE *argv, VALUE module);
222
228
  extern VALUE r_gmpq_swap(VALUE self, VALUE arg);
223
229
 
@@ -280,11 +286,11 @@ extern int mpf_cmp_value(MP_FLOAT *OP, VALUE arg);
280
286
  // MPFR
281
287
  #ifdef MPFR
282
288
  extern void mpf_set_value2(MP_FLOAT *self_val, VALUE arg, int base);
283
-
289
+
284
290
  extern VALUE r_gmpfr_sqrt(int argc, VALUE *argv, VALUE self);
285
291
  extern VALUE r_gmpfr_rec_sqrt(int argc, VALUE *argv, VALUE self);
286
292
  extern VALUE r_gmpfr_cbrt(int argc, VALUE *argv, VALUE self);
287
-
293
+
288
294
  extern VALUE r_gmpfr_log(int argc, VALUE *argv, VALUE self);
289
295
  extern VALUE r_gmpfr_log2(int argc, VALUE *argv, VALUE self);
290
296
  extern VALUE r_gmpfr_log10(int argc, VALUE *argv, VALUE self);
@@ -297,22 +303,22 @@ extern int mpf_cmp_value(MP_FLOAT *OP, VALUE arg);
297
303
  extern VALUE r_gmpfr_sec(int argc, VALUE *argv, VALUE self);
298
304
  extern VALUE r_gmpfr_csc(int argc, VALUE *argv, VALUE self);
299
305
  extern VALUE r_gmpfr_cot(int argc, VALUE *argv, VALUE self);
300
-
306
+
301
307
  extern VALUE r_gmpfr_acos(int argc, VALUE *argv, VALUE self);
302
308
  extern VALUE r_gmpfr_asin(int argc, VALUE *argv, VALUE self);
303
309
  extern VALUE r_gmpfr_atan(int argc, VALUE *argv, VALUE self);
304
-
310
+
305
311
  extern VALUE r_gmpfr_cosh(int argc, VALUE *argv, VALUE self);
306
312
  extern VALUE r_gmpfr_sinh(int argc, VALUE *argv, VALUE self);
307
313
  extern VALUE r_gmpfr_tanh(int argc, VALUE *argv, VALUE self);
308
-
314
+
309
315
  extern VALUE r_gmpfr_sech(int argc, VALUE *argv, VALUE self);
310
316
  extern VALUE r_gmpfr_csch(int argc, VALUE *argv, VALUE self);
311
317
  extern VALUE r_gmpfr_coth(int argc, VALUE *argv, VALUE self);
312
318
  extern VALUE r_gmpfr_acosh(int argc, VALUE *argv, VALUE self);
313
319
  extern VALUE r_gmpfr_asinh(int argc, VALUE *argv, VALUE self);
314
320
  extern VALUE r_gmpfr_atanh(int argc, VALUE *argv, VALUE self);
315
-
321
+
316
322
  extern VALUE r_gmpfr_log1p(int argc, VALUE *argv, VALUE self);
317
323
  extern VALUE r_gmpfr_expm1(int argc, VALUE *argv, VALUE self);
318
324
  extern VALUE r_gmpfr_eint(int argc, VALUE *argv, VALUE self);
@@ -331,12 +337,12 @@ extern int mpf_cmp_value(MP_FLOAT *OP, VALUE arg);
331
337
  extern VALUE r_gmpfr_jn(int argc, VALUE *argv, VALUE self);
332
338
  extern VALUE r_gmpfr_y0(int argc, VALUE *argv, VALUE self);
333
339
  extern VALUE r_gmpfr_y1(int argc, VALUE *argv, VALUE self);
334
-
340
+
335
341
  extern VALUE r_gmpfrsg_const_log2();
336
342
  extern VALUE r_gmpfrsg_const_pi();
337
343
  extern VALUE r_gmpfrsg_const_euler();
338
344
  extern VALUE r_gmpfrsg_const_catalan();
339
-
345
+
340
346
  extern mp_rnd_t r_get_rounding_mode(VALUE rnd);
341
347
  #endif /* MPFR */
342
348
 
data/manual.pdf CHANGED
Binary file
data/manual.tex CHANGED
@@ -34,8 +34,8 @@
34
34
  \huge{gmp} &\\
35
35
  \midrule[3pt]
36
36
  \multicolumn{2}{r}{\large{Ruby bindings to the GMP library}}\\
37
- \multicolumn{2}{r}{\large{Edition 0.5.41}}\\
38
- \multicolumn{2}{r}{\large{17 November 2010}}
37
+ \multicolumn{2}{r}{\large{Edition 0.5.47}}\\
38
+ \multicolumn{2}{r}{\large{10 November 2011}}
39
39
  \end{tabular}
40
40
 
41
41
  \vfill
@@ -47,7 +47,7 @@
47
47
  This manual describes how to use the gmp Ruby gem, which provides bindings to
48
48
  the GNU multiple precision arithmetic library, version 4.3.x or 5.0.x.\\
49
49
  \\
50
- Copyright 2009, 2010 Sam Rawlins.\\
50
+ Copyright 2009, 2010, 2011 Sam Rawlins.\\
51
51
  No license yet.
52
52
  \newpage
53
53
 
@@ -93,7 +93,7 @@ near you, see \url{http://www.gnu.org/order/ftp.html} for a full list.\\
93
93
  \\
94
94
  There are three public mailing lists of interest. One for release
95
95
  announcements, one for general questions and discussions about usage of the GMP
96
- library, and one for bug reports. For more information, see
96
+ library, and one for bug reports. For more information, see
97
97
  \url{http://gmplib.org/mailman/listinfo/}.\\
98
98
 
99
99
  The proper place for bug reports is gmp-bugs@gmplib.org. See Chapter 4
@@ -326,16 +326,19 @@ There are additional constants within \texttt{GMP} when MPFR is linked:
326
326
  \toprule
327
327
  \textbf{new} & & GMP::Z.new $\rightarrow$ \textit{integer} \\
328
328
  & & GMP::Z.new(\textit{numeric = 0}) $\rightarrow$ \textit{integer} \\
329
- & & GMP::Z.new(\textit{str}) $\rightarrow$ \textit{integer} \\
329
+ & & GMP::Z.new(\textit{str}, \textit{base = 0}) $\rightarrow$ \textit{integer} \\
330
330
  \cmidrule(r){2-3}
331
331
  & \multicolumn{2}{p{\defnwidth}}{
332
- This method creates a new \gmpzs integer. It takes one optional argument for the value
333
- of the integer. This argument can be one of several classes. Here are some
334
- examples:\newline
335
-
332
+ This method creates a new \gmpzs integer. It typically takes one optional argument for
333
+ the value of the integer. This argument can be one of several classes. If the first
334
+ argument is a String, then a second argument, the base, may be optionally supplied.
335
+ Here are some examples:\newline
336
+
336
337
  \texttt{GMP::Z.new \qqqquad\qqqquad \#=> 0 (default) \newline
337
338
  GMP::Z.new(1) \qqqquad\qquad\ \#=> 1 (Ruby Fixnum) \newline
338
339
  GMP::Z.new("127") \qqqquad\ \#=> 127 (Ruby String)\newline
340
+ GMP::Z.new("FF", 16) \qquad\ \ \#=> 255 (Ruby String with base)\newline
341
+ GMP::Z.new("1Z", 36) \qquad\ \ \#=> 71 (Ruby String with base)\newline
339
342
  GMP::Z.new(4294967296) \qquad \#=> 4294967296 (Ruby Bignum)\newline
340
343
  GMP::Z.new(GMP::Z.new(31)) \#=> 31 (GMP Integer)}
341
344
  }
@@ -958,7 +961,7 @@ There is also a convenience method available, \texttt{GMP::Z()}.\\
958
961
  \textbf{hash} & & $a$.hash $\rightarrow$ $string$ \\
959
962
  \cmidrule(r){2-3}
960
963
  & \multicolumn{2}{p{\defnwidth}}{
961
- Used when comparing objects as $Hash$ keys.
964
+ Used when comparing objects as Hash keys.
962
965
  }
963
966
  \end{tabular}
964
967
 
@@ -1139,7 +1142,7 @@ There is also a convenience method available, \texttt{GMP::Z()}.\\
1139
1142
  arguments for the value of the numerator and denominator. These arguments can each be
1140
1143
  an instance of several classes. Here are some
1141
1144
  examples:\newline
1142
-
1145
+
1143
1146
  \texttt{GMP::Q.new \qqqquad\qqqquad \#=> 0 (default) \newline
1144
1147
  GMP::Q.new(1) \qqqquad\qquad\ \#=> 1 (Ruby Fixnum) \newline
1145
1148
  GMP::Q.new(1,3) \qqqquad\quad\ \#=> 1/3 (Ruby Fixnums) \newline
@@ -1163,7 +1166,7 @@ There is also a convenience method available, \texttt{GMP::Q()}.\\
1163
1166
 
1164
1167
  Otherwise returns the least significant part of \texttt{rational}, with the same sign as
1165
1168
  \textit{rational}.
1166
-
1169
+
1167
1170
  If \textit{rational} is too big to fit in a Float, the returned result is probably not
1168
1171
  very useful.
1169
1172
  }
@@ -1178,6 +1181,15 @@ There is also a convenience method available, \texttt{GMP::Q()}.\\
1178
1181
  Converts \textit{rational} to a string.
1179
1182
  }
1180
1183
  \end{tabular}
1184
+ \newline\newline
1185
+
1186
+ \subsection{Rational Arithmetic}
1187
+
1188
+ \begin{tabular}{p{\methwidth} l r}
1189
+ \toprule
1190
+ \textbf{+} & & \textit{rational} + \text{numeric} $\rightarrow$ \textit{numeric} \\
1191
+ \end{tabular}
1192
+ \newline\newline
1181
1193
 
1182
1194
  \newpage
1183
1195
  \section{Floating-point Functions}
@@ -1186,7 +1198,7 @@ There is also a convenience method available, \texttt{GMP::Q()}.\\
1186
1198
 
1187
1199
  \subsection{Floating-point Special Functions (MPFR Only)}
1188
1200
 
1189
- Every method below accepts two additional parameters in addition to any required parameters. These are $rnd_mode$, the rounding mode to use in calculation, which defaults to \textit{GMP::GMP\_RNDN}, and $res_prec$, the precision of the result, which defaults to the \textit{f.prec}, the precision of $f$.\\
1201
+ Every method below accepts two additional parameters in addition to any required parameters. These are $rnd\_mode$, the rounding mode to use in calculation, which defaults to \textit{GMP::GMP\_RNDN}, and $res\_prec$, the precision of the result, which defaults to the \textit{f.prec}, the precision of $f$.\\
1190
1202
 
1191
1203
  \begin{tabular}{p{\methwidth} l r}
1192
1204
  \toprule
@@ -1442,7 +1454,7 @@ Every method below accepts two additional parameters in addition to any required
1442
1454
  \textit{:lc\_2exp\_size}. This initializer instead takes just one argument, $size$. $a$, $c$,
1443
1455
  and $m2exp$ are then chosen from a table, with $m2exp/2 > size$. The maximum size
1444
1456
  currently supported is 128.\newline
1445
-
1457
+
1446
1458
  \texttt{GMP::RandState.new \newline
1447
1459
  GMP::RandState.new(:mt) \newline
1448
1460
  GMP::RandState.new(:lc\_2exp, 1103515245, 12345, 15) \quad \#=> Perl's old rand() \newline
@@ -1485,6 +1497,30 @@ Every method below accepts two additional parameters in addition to any required
1485
1497
  }
1486
1498
  \end{tabular}
1487
1499
 
1500
+ \subsection{Floating-point Miscellaneous Functions (MPFR Only)}
1501
+
1502
+ \begin{tabular}{p{\methwidth} l r}
1503
+ \toprule
1504
+ \textbf{mpfr\_buildopt\_tls\_p} & & GMP::F.mpfr\_buildopt\_tls\_p() $\rightarrow$ $integer$ \\
1505
+ \cmidrule(r){2-3}
1506
+ & \multicolumn{2}{p{\defnwidth}}{
1507
+ Available only in MPFR 3.0.0 and greater.
1508
+ \newline\newline
1509
+ From the MPFR Manual: Return a non-zero value if MPFR was compiled as thread safe using compiler-level Thread Local Storage (that is, MPFR was built with the \texttt{--enable-thread-safe} configure option, see INSTALL file), return zero otherwise.
1510
+ }
1511
+ \end{tabular}
1512
+ \newline\newline
1513
+
1514
+ \begin{tabular}{p{\methwidth} l r}
1515
+ \toprule
1516
+ \textbf{mpfr\_buildopt\_decimal\_p} & & GMP::F.mpfr\_buildopt\_decimal\_p() $\rightarrow$ $integer$ \\
1517
+ \cmidrule(r){2-3}
1518
+ & \multicolumn{2}{p{\defnwidth}}{
1519
+ Available only in MPFR 3.0.0 and greater.
1520
+ \newline\newline
1521
+ From the MPFR Manual: Return a non-zero value if MPFR was compiled with decimal float support (that is, MPFR was built with the \texttt{--enable-decimal-float} configure option), return zero otherwise.
1522
+ }
1523
+ \end{tabular}
1488
1524
 
1489
1525
  \newpage
1490
1526
  \section{Benchmarking}