ruby-mpfr 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,13 @@
1
+ === 0.0.8
2
+ * 2 major enhancements:
3
+ * Support MPFR v3.
4
+ * Add some methods.
5
+ * Note that ruby-mpfr does not support MPFR v2.
6
+ * Support Marshal.dump and Marshal.load.
7
+ * 1 minor enhancements:
8
+ * Support rspec v2.
9
+ * some bug fixes.
10
+
1
11
  === 0.0.7
2
12
  * 1 bug fix:
3
13
  * Fix bugs of Methods MPFR::SquareMatrix, MPFR::ColumnVector, and MPFR::RowVector.
@@ -27,6 +27,7 @@ spec/mpfr/conversion_spec.rb
27
27
  spec/mpfr/exception_spec.rb
28
28
  spec/mpfr/functions_spec.rb
29
29
  spec/mpfr/generate_number_modulue.rb
30
+ spec/mpfr/marshal_spec.rb
30
31
  spec/mpfr/precision_roundmode_spec.rb
31
32
  spec/mpfr/rounding_spec.rb
32
33
  spec/mpfr/set_value_spec.rb
@@ -35,9 +36,9 @@ spec/mpfr/string_spec.rb
35
36
  spec/mpfr_matrix/generate_matrix_arguments.rb
36
37
  spec/mpfr_matrix/mpfr_matrix_alloc_spec.rb
37
38
  spec/mpfr_matrix/mpfr_matrix_arithmetic_spec.rb
39
+ spec/mpfr_matrix/mpfr_matrix_marshal_spec.rb
38
40
  spec/mpfr_matrix/mpfr_matrix_set_element_spec.rb
39
41
  spec/mpfr_matrix/mpfr_matrix_string_spec.rb
40
42
  spec/mpfr_matrix/mpfr_square_matrix_spec.rb
41
43
  spec/mpfr_matrix/spec_helper.rb
42
- spec/spec.opts
43
44
  tasks/extconf.rake
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ gem 'hoe', '>= 2.1.0'
3
3
  require 'hoe'
4
4
  require 'fileutils'
5
5
  require './lib/mpfr/version.rb'
6
+ # require 'rake/clean'
6
7
 
7
8
  Hoe.plugin :newgem
8
9
  # Hoe.plugin :website
@@ -2,8 +2,19 @@ require 'mkmf'
2
2
 
3
3
  $CFLAGS += " -Wall"
4
4
 
5
+ REQUIRE_VERSION = 3
6
+
5
7
  dir_config("mpfr")
6
8
  dir_config("gmp")
7
9
  if have_header('mpfr.h') && have_library('mpfr') && have_header('gmp.h') && have_library('gmp')
8
- create_makefile("mpfr")
10
+ if have_macro('MPFR_VERSION_MAJOR', 'mpfr.h') do |src|
11
+ src + <<SRC
12
+ #if MPFR_VERSION_MAJOR < #{REQUIRE_VERSION}
13
+ # error
14
+ >>>>>> MPFR_VERSION_MAJOR requires larger than #{REQUIRE_VERSION} <<<<<<
15
+ #endif
16
+ SRC
17
+ end
18
+ create_makefile("mpfr")
19
+ end
9
20
  end
@@ -1,10 +1,17 @@
1
1
  #include "ruby_mpfr.h"
2
2
 
3
+ #define MPFR_DUMP_NUMBER 'A'
4
+ #define MPFR_DUMP_PZERO 'B'
5
+ #define MPFR_DUMP_MZERO 'C'
6
+ #define MPFR_DUMP_PINF 'D'
7
+ #define MPFR_DUMP_MINF 'E'
8
+ #define MPFR_DUMP_NAN 'F'
9
+
3
10
  static ID eqq, to_s, new, class, method_defined, object_id;
4
11
  static VALUE __mpfr_class__, __sym_to_s__, __sym_to_str__;
5
12
 
6
13
  /* ------------------------------ Precision and Rounding Mode Start ------------------------------ */
7
- #define VALID_RND(rnd) (rnd >= 0 && rnd <= 3)
14
+ #define VALID_RND(rnd_mode) (rnd_mode >= MPFR_RNDN && rnd_mode < ((MPFR_RNDA)+1))
8
15
  #define SPECIAL_FUNC_STATE "@@special_func_state"
9
16
 
10
17
  /* Convert VALUE rnd (rounding mode number) to C integer and */
@@ -456,6 +463,21 @@ static VALUE r_mpfr_nan(int argc, VALUE *argv, VALUE self)
456
463
  return val_ret;
457
464
  }
458
465
 
466
+ /* Return zero. This method takes one optional argument meaning precision. */
467
+ static VALUE r_mpfr_zero(int argc, VALUE *argv, VALUE self)
468
+ {
469
+ mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 2, argc, argv);
470
+ MPFR *ptr_return;
471
+ VALUE val_ret;
472
+ int sign = 1;
473
+ if (argc >= 1) {
474
+ sign = NUM2INT(argv[0]);
475
+ }
476
+ r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
477
+ mpfr_set_zero(ptr_return, sign);
478
+ return val_ret;
479
+ }
480
+
459
481
  /* Return plus infinity. This method takes one optional argument meaning precision. */
460
482
  static VALUE r_mpfr_pinf(int argc, VALUE *argv, VALUE self)
461
483
  {
@@ -543,6 +565,21 @@ static VALUE r_mpfr_set_nan(VALUE self)
543
565
  return self;
544
566
  }
545
567
 
568
+ /* Set the value of self to zero. */
569
+ static VALUE r_mpfr_set_zero(int argc, VALUE *argv, VALUE self)
570
+ {
571
+ int sign = 1;
572
+ MPFR *ptr_self;
573
+ r_mpfr_get_struct(ptr_self, self);
574
+ if (argc == 1) {
575
+ sign = NUM2INT(argv[0]);
576
+ } else if (argc > 1) {
577
+ rb_raise(rb_eArgError, "Invalid number of arguments.");
578
+ }
579
+ mpfr_set_zero(ptr_self, sign);
580
+ return self;
581
+ }
582
+
546
583
  /* Swap the values self and p1 efficiently. p1 must be MPFR object. */
547
584
  static VALUE r_mpfr_swap(VALUE self, VALUE other)
548
585
  {
@@ -1197,6 +1234,14 @@ static VALUE r_mpfr_nonzero_p(VALUE self)
1197
1234
  return (mpfr_zero_p(ptr_self) == 0 ? Qtrue : Qfalse);
1198
1235
  }
1199
1236
 
1237
+ /* Return true if self is regular number, nil otherwise. */
1238
+ static VALUE r_mpfr_regular_p(VALUE self)
1239
+ {
1240
+ MPFR *ptr_self;
1241
+ r_mpfr_get_struct(ptr_self, self);
1242
+ return (mpfr_regular_p(ptr_self) != 0 ? Qtrue : Qfalse);
1243
+ }
1244
+
1200
1245
  /* mpfr_sgn(self). */
1201
1246
  static VALUE r_mpfr_sgn(VALUE self)
1202
1247
  {
@@ -1280,7 +1325,7 @@ static VALUE r_mpfr_unordered_p(VALUE self, VALUE other)
1280
1325
  /* ------------------------------ Integer Related Functions Start ------------------------------ */
1281
1326
 
1282
1327
  /* mpfr_rint(ret, self, rnd) */
1283
- static VALUE r_mpfr_m_rint(int argc, VALUE *argv, VALUE self)
1328
+ static VALUE r_mpfr_fr_rint(int argc, VALUE *argv, VALUE self)
1284
1329
  {
1285
1330
  mp_rnd_t rnd;
1286
1331
  mp_prec_t prec;
@@ -1294,7 +1339,7 @@ static VALUE r_mpfr_m_rint(int argc, VALUE *argv, VALUE self)
1294
1339
  }
1295
1340
 
1296
1341
  /* mpfr_ceil(ret, self) */
1297
- static VALUE r_mpfr_m_ceil(int argc, VALUE *argv, VALUE self)
1342
+ static VALUE r_mpfr_fr_ceil(int argc, VALUE *argv, VALUE self)
1298
1343
  {
1299
1344
  mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv);
1300
1345
  MPFR *ptr_self, *ptr_return;
@@ -1306,7 +1351,7 @@ static VALUE r_mpfr_m_ceil(int argc, VALUE *argv, VALUE self)
1306
1351
  }
1307
1352
 
1308
1353
  /* mpfr_floor(ret, self) */
1309
- static VALUE r_mpfr_m_floor(int argc, VALUE *argv, VALUE self)
1354
+ static VALUE r_mpfr_fr_floor(int argc, VALUE *argv, VALUE self)
1310
1355
  {
1311
1356
  mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv);
1312
1357
  MPFR *ptr_self, *ptr_return;
@@ -1318,7 +1363,7 @@ static VALUE r_mpfr_m_floor(int argc, VALUE *argv, VALUE self)
1318
1363
  }
1319
1364
 
1320
1365
  /* mpfr_round(ret, self) */
1321
- static VALUE r_mpfr_m_round(int argc, VALUE *argv, VALUE self)
1366
+ static VALUE r_mpfr_fr_round(int argc, VALUE *argv, VALUE self)
1322
1367
  {
1323
1368
  mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv);
1324
1369
  MPFR *ptr_self, *ptr_return;
@@ -1330,7 +1375,7 @@ static VALUE r_mpfr_m_round(int argc, VALUE *argv, VALUE self)
1330
1375
  }
1331
1376
 
1332
1377
  /* mpfr_trunc(ret, self) */
1333
- static VALUE r_mpfr_m_trunc(int argc, VALUE *argv, VALUE self)
1378
+ static VALUE r_mpfr_fr_trunc(int argc, VALUE *argv, VALUE self)
1334
1379
  {
1335
1380
  mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv);
1336
1381
  MPFR *ptr_self, *ptr_return;
@@ -1609,7 +1654,7 @@ static VALUE r_mpfr_prec_round(int argc, VALUE *argv, VALUE self)
1609
1654
  return val_ret;
1610
1655
  }
1611
1656
 
1612
- /* mpfr_prec_round(ret, prec, rnd) */
1657
+ /* mpfr_prec_round(self, prec, rnd) */
1613
1658
  static VALUE r_mpfr_prec_round2(int argc, VALUE *argv, VALUE self)
1614
1659
  {
1615
1660
  mp_rnd_t rnd;
@@ -1621,6 +1666,26 @@ static VALUE r_mpfr_prec_round2(int argc, VALUE *argv, VALUE self)
1621
1666
  return self;
1622
1667
  }
1623
1668
 
1669
+ /* mpfr_can_round(self, err, rnd1, rnd2, prec) */
1670
+ static VALUE r_mpfr_can_round(VALUE self, VALUE err, VALUE rnd1, VALUE rnd2, VALUE prec)
1671
+ {
1672
+ MPFR *ptr_self;
1673
+ r_mpfr_get_struct(ptr_self, self);
1674
+ if (mpfr_can_round(ptr_self, NUM2INT(err), NUM2INT(rnd1), NUM2INT(rnd2), NUM2INT(prec))) {
1675
+ return Qtrue;
1676
+ }
1677
+ return Qnil;
1678
+ }
1679
+
1680
+ /* mpfr_min_prec(self) */
1681
+ static VALUE r_mpfr_min_prec(VALUE self)
1682
+ {
1683
+ MPFR *ptr_self;
1684
+ r_mpfr_get_struct(ptr_self, self);
1685
+ return INT2NUM(mpfr_min_prec(ptr_self));
1686
+ }
1687
+
1688
+
1624
1689
  /* ------------------------------ Rounding Mode Related Functions End ------------------------------ */
1625
1690
 
1626
1691
  /* ------------------------------ Special Functions Start ------------------------------ */
@@ -1960,6 +2025,51 @@ static VALUE r_mpfr_math_sinh_cosh(int argc, VALUE *argv, VALUE self)
1960
2025
  return rb_ary_new3(2, val_ret1, val_ret2);
1961
2026
  }
1962
2027
 
2028
+ /* mpfr_sech(ret, p1, rnd). */
2029
+ static VALUE r_mpfr_math_sech(int argc, VALUE *argv, VALUE self)
2030
+ {
2031
+ mp_rnd_t rnd;
2032
+ mp_prec_t prec;
2033
+ r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv);
2034
+ MPFR *ptr_arg1, *ptr_return;
2035
+ VALUE val_ret;
2036
+ volatile VALUE tmp_argv0 = r_mpfr_new_fr_obj(argv[0]);
2037
+ r_mpfr_get_struct(ptr_arg1, tmp_argv0);
2038
+ r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
2039
+ r_mpfr_set_special_func_state(mpfr_sech(ptr_return, ptr_arg1, rnd));
2040
+ return val_ret;
2041
+ }
2042
+
2043
+ /* mpfr_csch(ret, p1, rnd). */
2044
+ static VALUE r_mpfr_math_csch(int argc, VALUE *argv, VALUE self)
2045
+ {
2046
+ mp_rnd_t rnd;
2047
+ mp_prec_t prec;
2048
+ r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv);
2049
+ MPFR *ptr_arg1, *ptr_return;
2050
+ VALUE val_ret;
2051
+ volatile VALUE tmp_argv0 = r_mpfr_new_fr_obj(argv[0]);
2052
+ r_mpfr_get_struct(ptr_arg1, tmp_argv0);
2053
+ r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
2054
+ r_mpfr_set_special_func_state(mpfr_csch(ptr_return, ptr_arg1, rnd));
2055
+ return val_ret;
2056
+ }
2057
+
2058
+ /* mpfr_coth(ret, p1, rnd). */
2059
+ static VALUE r_mpfr_math_coth(int argc, VALUE *argv, VALUE self)
2060
+ {
2061
+ mp_rnd_t rnd;
2062
+ mp_prec_t prec;
2063
+ r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv);
2064
+ MPFR *ptr_arg1, *ptr_return;
2065
+ VALUE val_ret;
2066
+ volatile VALUE tmp_argv0 = r_mpfr_new_fr_obj(argv[0]);
2067
+ r_mpfr_get_struct(ptr_arg1, tmp_argv0);
2068
+ r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
2069
+ r_mpfr_set_special_func_state(mpfr_coth(ptr_return, ptr_arg1, rnd));
2070
+ return val_ret;
2071
+ }
2072
+
1963
2073
  /* mpfr_acosh(ret, p1, rnd). */
1964
2074
  static VALUE r_mpfr_math_acosh(int argc, VALUE *argv, VALUE self)
1965
2075
  {
@@ -2129,6 +2239,21 @@ static VALUE r_mpfr_math_lgamma(int argc, VALUE *argv, VALUE self)
2129
2239
  return rb_ary_new3(2, val_ret, INT2FIX(singp));
2130
2240
  }
2131
2241
 
2242
+ /* mpfr_digamma(ret, p1, rnd). */
2243
+ static VALUE r_mpfr_math_digamma(int argc, VALUE *argv, VALUE self)
2244
+ {
2245
+ mp_rnd_t rnd;
2246
+ mp_prec_t prec;
2247
+ r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv);
2248
+ MPFR *ptr_arg1, *ptr_return;
2249
+ VALUE val_ret;
2250
+ volatile VALUE tmp_argv0 = r_mpfr_new_fr_obj(argv[0]);
2251
+ r_mpfr_get_struct(ptr_arg1, tmp_argv0);
2252
+ r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
2253
+ r_mpfr_set_special_func_state(mpfr_digamma(ptr_return, ptr_arg1, rnd));
2254
+ return val_ret;
2255
+ }
2256
+
2132
2257
  /* mpfr_zeta(ret, p1, rnd). */
2133
2258
  static VALUE r_mpfr_math_zeta(int argc, VALUE *argv, VALUE self)
2134
2259
  {
@@ -2346,6 +2471,21 @@ static VALUE r_mpfr_math_hypot(int argc, VALUE *argv, VALUE self)
2346
2471
  return val_ret;
2347
2472
  }
2348
2473
 
2474
+ /* mpfr_ai(ret, p1, rnd). */
2475
+ static VALUE r_mpfr_math_ai(int argc, VALUE *argv, VALUE self)
2476
+ {
2477
+ mp_rnd_t rnd;
2478
+ mp_prec_t prec;
2479
+ r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv);
2480
+ MPFR *ptr_arg1, *ptr_return;
2481
+ VALUE val_ret;
2482
+ volatile VALUE tmp_argv0 = r_mpfr_new_fr_obj(argv[0]);
2483
+ r_mpfr_get_struct(ptr_arg1, tmp_argv0);
2484
+ r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
2485
+ r_mpfr_set_special_func_state(mpfr_ai(ptr_return, ptr_arg1, rnd));
2486
+ return val_ret;
2487
+ }
2488
+
2349
2489
  /* mpfr_const_log2(ret, rnd). */
2350
2490
  static VALUE r_mpfr_math_const_log2(int argc, VALUE *argv, VALUE self)
2351
2491
  {
@@ -2465,7 +2605,110 @@ static VALUE r_mpfr_math_max(int argc, VALUE *argv, VALUE self)
2465
2605
  return val_ret;
2466
2606
  }
2467
2607
 
2608
+ /* Version string which mpfr_get_version() returns. */
2609
+ static VALUE r_mpfr_get_version(VALUE self)
2610
+ {
2611
+ return rb_str_new2(mpfr_get_version());
2612
+ }
2613
+
2614
+ /* String which mpfr_get_patches() returns. */
2615
+ static VALUE r_mpfr_get_patches(VALUE self)
2616
+ {
2617
+ return rb_str_new2(mpfr_get_patches());
2618
+ }
2619
+
2620
+ /* Return true if MPFR was compiled as thread safe using compiler-level Thread Local Storage. Otherwise, nil. */
2621
+ static VALUE r_mpfr_buildopt_tls_p(VALUE self)
2622
+ {
2623
+ return mpfr_buildopt_tls_p() == 0 ? Qnil : Qtrue;
2624
+ }
2625
+
2626
+ /* Return true if MPFR was compiled with decimal float support. Otherwise, nil. */
2627
+ static VALUE r_mpfr_buildopt_decimal_p(VALUE self)
2628
+ {
2629
+ return mpfr_buildopt_decimal_p() == 0 ? Qnil : Qtrue;
2630
+ }
2631
+
2632
+ static VALUE r_mpfr_marshal_dump(VALUE self)
2633
+ {
2634
+ MPFR *ptr_s;
2635
+ r_mpfr_get_struct(ptr_s, self);
2636
+ char *ret_str;
2637
+ if (mpfr_regular_p(ptr_s)) {
2638
+ mpz_t m;
2639
+ mp_exp_t e;
2640
+ mpz_init(m);
2641
+ e = mpfr_get_z_2exp(m, ptr_s);
2642
+ mpfr_asprintf(&ret_str, "%c%ld\t%ld\t%Zd", MPFR_DUMP_NUMBER, mpfr_get_prec(ptr_s), (long int)e, m);
2643
+ mpz_clear(m);
2644
+ } else {
2645
+ char type;
2646
+ if (mpfr_zero_p(ptr_s)) {
2647
+ if (mpfr_sgn(ptr_s) >= 0) {
2648
+ type = MPFR_DUMP_PZERO;
2649
+ } else {
2650
+ type = MPFR_DUMP_MZERO;
2651
+ }
2652
+ } else if (mpfr_nan_p(ptr_s)) {
2653
+ type = MPFR_DUMP_NAN;
2654
+ } else if (mpfr_sgn(ptr_s) >= 0) {
2655
+ type = MPFR_DUMP_PINF;
2656
+ } else {
2657
+ type = MPFR_DUMP_MINF;
2658
+ }
2659
+ mpfr_asprintf(&ret_str, "%c%ld", type, mpfr_get_prec(ptr_s));
2660
+ }
2661
+ VALUE ret_val = rb_str_new2(ret_str);
2662
+ mpfr_free_str(ret_str);
2663
+ return ret_val;
2664
+ }
2468
2665
 
2666
+ static VALUE r_mpfr_marshal_load(VALUE self, VALUE dump_string)
2667
+ {
2668
+ long int prec;
2669
+ MPFR *ptr_s;
2670
+ r_mpfr_get_struct(ptr_s, self);
2671
+ Check_Type(dump_string, T_STRING);
2672
+ char *dump, type;
2673
+ dump = RSTRING_PTR(dump_string);
2674
+ type = dump[0];
2675
+ dump++;
2676
+ if (type == MPFR_DUMP_NUMBER) {
2677
+ mpz_t m;
2678
+ long int e;
2679
+ mpz_init(m);
2680
+ sscanf(dump, "%ld\t%ld\t", &prec, &e);
2681
+ int i;
2682
+ i = 0;
2683
+ while (i < 2) {
2684
+ if (dump[0] == '\t') {
2685
+ i++;
2686
+ }
2687
+ dump++;
2688
+ }
2689
+ mpz_set_str(m, dump, 10);
2690
+ mpfr_init2(ptr_s, prec);
2691
+ mpfr_set_z_2exp(ptr_s, m, e, MPFR_RNDN);
2692
+ mpz_clear(m);
2693
+ } else {
2694
+ sscanf(dump, "%ld", &prec);
2695
+ mpfr_init2(ptr_s, prec);
2696
+ if (type == MPFR_DUMP_PZERO) {
2697
+ mpfr_set_zero(ptr_s, +1);
2698
+ } else if (type == MPFR_DUMP_MZERO){
2699
+ mpfr_set_zero(ptr_s, -1);
2700
+ } else if (type == MPFR_DUMP_NAN) {
2701
+ mpfr_set_nan(ptr_s);
2702
+ } else if (type == MPFR_DUMP_PINF) {
2703
+ mpfr_set_inf(ptr_s, +1);
2704
+ } else if (type == MPFR_DUMP_MINF) {
2705
+ mpfr_set_inf(ptr_s, -1);
2706
+ } else {
2707
+ rb_raise(rb_eArgError, "Invalid dumped data for marshal_load.");
2708
+ }
2709
+ }
2710
+ return self;
2711
+ }
2469
2712
 
2470
2713
  void Init_mpfr()
2471
2714
  {
@@ -2494,7 +2737,7 @@ void Init_mpfr()
2494
2737
  Except for some methods,
2495
2738
  the names of methods inherit that of MPFR functions in C language and
2496
2739
  each name of method is removed 'mpfr_' from that of correspnding MPFR function in C language.
2497
- The methods m_rint, m_ceil, m_floor, m_round and m_trunc are exceptions and
2740
+ The methods fr_rint, fr_ceil, fr_floor, fr_round and fr_trunc are exceptions and
2498
2741
  respectively corresponts to mpfr_rint, mpfr_ceil, mpfr_floor, mpfr_round and mpfr_trunc.
2499
2742
  Note that there are also methods rint, ceil, floor, round and trunc
2500
2743
  which have respectively defferent actions
@@ -2535,41 +2778,44 @@ void Init_mpfr()
2535
2778
 
2536
2779
  /* ------------------------------ Constants Start ------------------------------ */
2537
2780
 
2538
- /* Version string which mpfr_get_version() returns. */
2539
- rb_define_const(r_mpfr_class, "MPFR_VERSION", rb_str_new2(mpfr_get_version()));
2540
- /* String which mpfr_get_patches() returns. */
2541
- rb_define_const(r_mpfr_class, "MPFR_PATCHES", rb_str_new2(mpfr_get_patches()));
2542
- /* Integer which is macro MPFR_VERSION. */
2543
- rb_define_const(r_mpfr_class, "MPFR_VERSION2", INT2NUM(MPFR_VERSION));
2544
- /* Integer which is macro MPFR_VERSION_MAJOR. */
2781
+ /* Integer that is macro MPFR_VERSION. */
2782
+ rb_define_const(r_mpfr_class, "MPFR_VERSION", INT2NUM(MPFR_VERSION));
2783
+ /* Integer that is macro MPFR_VERSION_MAJOR. */
2545
2784
  rb_define_const(r_mpfr_class, "MPFR_VERSION_MAJOR", INT2NUM(MPFR_VERSION_MAJOR));
2546
- /* Integer which is macro MPFR_VERSION_MINOR. */
2785
+ /* Integer that is macro MPFR_VERSION_MINOR. */
2547
2786
  rb_define_const(r_mpfr_class, "MPFR_VERSION_MINOR", INT2NUM(MPFR_VERSION_MINOR));
2548
- /* Integer which is macro MPFR_VERSION_PATCHLEVEL. */
2787
+ /* Integer that is macro MPFR_VERSION_PATCHLEVEL. */
2549
2788
  rb_define_const(r_mpfr_class, "MPFR_VERSION_PATCHLEVEL", INT2NUM(MPFR_VERSION_PATCHLEVEL));
2550
- /* String whichi is macro MPFR_VERSION_STRING. */
2789
+ /* String that is macro MPFR_VERSION_STRING. */
2551
2790
  rb_define_const(r_mpfr_class, "MPFR_VERSION_STRING", rb_str_new2(MPFR_VERSION_STRING));
2552
2791
 
2553
- /* Integer which is macro MPFR_PREC_MAX. */
2792
+ /* Integer that is macro MPFR_PREC_MAX. */
2554
2793
  rb_define_const(r_mpfr_class, "PREC_MAX", INT2NUM(MPFR_PREC_MAX));
2555
- /* Integer which is macro MPFR_PREC_MIN. */
2794
+ /* Integer that is macro MPFR_PREC_MIN. */
2556
2795
  rb_define_const(r_mpfr_class, "PREC_MIN", INT2NUM(MPFR_PREC_MIN));
2557
- /* Integer which is macro MPFR_EMAX_DEFAULT. */
2796
+ /* Integer that is macro MPFR_EMAX_DEFAULT. */
2558
2797
  rb_define_const(r_mpfr_class, "EMAX_DEFAULT", INT2NUM(MPFR_EMAX_DEFAULT));
2559
2798
  /* Integer whichi is MPFR_EMIN_DEFAULT. */
2560
2799
  rb_define_const(r_mpfr_class, "EMIN_DEFAULT", INT2NUM(MPFR_EMIN_DEFAULT));
2561
2800
 
2562
- /* Integer which is macro GMP_RNDN. */
2563
- rb_define_const(r_mpfr_class, "RNDN", INT2NUM(GMP_RNDN));
2564
- /* Integer which is macro GMP_RNDZ. */
2565
- rb_define_const(r_mpfr_class, "RNDZ", INT2NUM(GMP_RNDZ));
2566
- /* Integer which is macro GMP_RNDU. */
2567
- rb_define_const(r_mpfr_class, "RNDU", INT2NUM(GMP_RNDU));
2568
- /* Integer which is macro GMP_RNDD. */
2569
- rb_define_const(r_mpfr_class, "RNDD", INT2NUM(GMP_RNDD));
2801
+ /* Integer that is macro MPFR_RNDN. */
2802
+ rb_define_const(r_mpfr_class, "RNDN", INT2NUM(MPFR_RNDN));
2803
+ /* Integer that is macro MPFR_RNDZ. */
2804
+ rb_define_const(r_mpfr_class, "RNDZ", INT2NUM(MPFR_RNDZ));
2805
+ /* Integer that is macro MPFR_RNDU. */
2806
+ rb_define_const(r_mpfr_class, "RNDU", INT2NUM(MPFR_RNDU));
2807
+ /* Integer that is macro MPFR_RNDD. */
2808
+ rb_define_const(r_mpfr_class, "RNDD", INT2NUM(MPFR_RNDD));
2809
+ /* Integer that is macro MPFR_RNDD. */
2810
+ rb_define_const(r_mpfr_class, "RNDA", INT2NUM(MPFR_RNDA));
2570
2811
 
2571
2812
  /* ------------------------------ Constants End ------------------------------ */
2572
2813
 
2814
+ rb_define_singleton_method(r_mpfr_class, "get_version", r_mpfr_get_version, 0);
2815
+ rb_define_singleton_method(r_mpfr_class, "get_patches", r_mpfr_get_patches, 0);
2816
+ rb_define_singleton_method(r_mpfr_class, "buildopt_tls?", r_mpfr_buildopt_tls_p, 0);
2817
+ rb_define_singleton_method(r_mpfr_class, "buildopt_decimal?", r_mpfr_buildopt_decimal_p, 0);
2818
+
2573
2819
  /* ------------------------------ Precision and Rounding Mode Start ------------------------------ */
2574
2820
 
2575
2821
  rb_define_singleton_method(r_mpfr_class, "set_default_prec", r_mpfr_set_default_prec, 1);
@@ -2620,6 +2866,7 @@ void Init_mpfr()
2620
2866
  rb_define_method(r_mpfr_class, "coerce", r_mpfr_coerce, 1);
2621
2867
 
2622
2868
  rb_define_singleton_method(r_mpfr_class, "nan", r_mpfr_nan, -1);
2869
+ rb_define_singleton_method(r_mpfr_class, "zero", r_mpfr_zero, -1);
2623
2870
  rb_define_singleton_method(r_mpfr_class, "pinf", r_mpfr_pinf, -1);
2624
2871
  rb_define_singleton_method(r_mpfr_class, "minf", r_mpfr_minf, -1);
2625
2872
 
@@ -2633,6 +2880,7 @@ void Init_mpfr()
2633
2880
  rb_define_method(r_mpfr_class, "set_fixnum_2exp", r_mpfr_set_fixnum_2exp, -1);
2634
2881
  rb_define_method(r_mpfr_class, "set_inf", r_mpfr_set_inf, 1);
2635
2882
  rb_define_method(r_mpfr_class, "set_nan", r_mpfr_set_nan, 0);
2883
+ rb_define_method(r_mpfr_class, "set_zero", r_mpfr_set_zero, -1);
2636
2884
  rb_define_method(r_mpfr_class, "swap", r_mpfr_swap, 1);
2637
2885
 
2638
2886
  /* ------------------------------ Assignment Functions End ------------------------------ */
@@ -2642,6 +2890,9 @@ void Init_mpfr()
2642
2890
  rb_define_method(r_mpfr_class, "to_strf", r_mpfr_to_strf, 1);
2643
2891
  rb_define_method(r_mpfr_class, "to_s", r_mpfr_to_s, 0);
2644
2892
  rb_define_method(r_mpfr_class, "inspect", r_mpfr_inspect, 0);
2893
+
2894
+ rb_define_method(r_mpfr_class, "marshal_dump", r_mpfr_marshal_dump, 0);
2895
+ rb_define_method(r_mpfr_class, "marshal_load", r_mpfr_marshal_load, 1);
2645
2896
  /* ------------------------------ Methods related to string End ------------------------------ */
2646
2897
 
2647
2898
  /* ------------------------------ Conversion functions Start ------------------------------ */
@@ -2699,16 +2950,17 @@ void Init_mpfr()
2699
2950
  rb_define_alias(r_mpfr_class, "finite?", "number_p");
2700
2951
  rb_define_alias(r_mpfr_class, "zero?", "zero_p");
2701
2952
  rb_define_method(r_mpfr_class, "nonzero?", r_mpfr_nonzero_p, 1);
2953
+ rb_define_method(r_mpfr_class, "regular?", r_mpfr_regular_p, 1);
2702
2954
 
2703
2955
  /* ------------------------------ Comparison Functions Start ------------------------------ */
2704
2956
 
2705
2957
  /* ------------------------------ Integer Related Functions Start ------------------------------ */
2706
2958
 
2707
- rb_define_method(r_mpfr_class, "m_rint", r_mpfr_m_rint, -1);
2708
- rb_define_method(r_mpfr_class, "m_ceil", r_mpfr_m_ceil, -1);
2709
- rb_define_method(r_mpfr_class, "m_floor", r_mpfr_m_floor, -1);
2710
- rb_define_method(r_mpfr_class, "m_round", r_mpfr_m_round, -1);
2711
- rb_define_method(r_mpfr_class, "m_trunc", r_mpfr_m_trunc, -1);
2959
+ rb_define_method(r_mpfr_class, "fr_rint", r_mpfr_fr_rint, -1);
2960
+ rb_define_method(r_mpfr_class, "fr_ceil", r_mpfr_fr_ceil, -1);
2961
+ rb_define_method(r_mpfr_class, "fr_floor", r_mpfr_fr_floor, -1);
2962
+ rb_define_method(r_mpfr_class, "fr_round", r_mpfr_fr_round, -1);
2963
+ rb_define_method(r_mpfr_class, "fr_trunc", r_mpfr_fr_trunc, -1);
2712
2964
  rb_define_method(r_mpfr_class, "rint_ceil", r_mpfr_rint_ceil, -1);
2713
2965
  rb_define_method(r_mpfr_class, "rint_floor", r_mpfr_rint_floor, -1);
2714
2966
  rb_define_method(r_mpfr_class, "rint_round", r_mpfr_rint_round, -1);
@@ -2743,6 +2995,8 @@ void Init_mpfr()
2743
2995
 
2744
2996
  rb_define_method(r_mpfr_class, "prec_round", r_mpfr_prec_round, -1);
2745
2997
  rb_define_method(r_mpfr_class, "prec_round!", r_mpfr_prec_round2, -1);
2998
+ rb_define_method(r_mpfr_class, "can_round", r_mpfr_can_round, 4);
2999
+ rb_define_method(r_mpfr_class, "min_prec", r_mpfr_min_prec, 0);
2746
3000
 
2747
3001
  /* ------------------------------ Rounding Mode Related Functions End ------------------------------ */
2748
3002
 
@@ -2813,6 +3067,9 @@ void Init_mpfr()
2813
3067
  rb_define_module_function(r_mpfr_math, "sinh", r_mpfr_math_sinh, -1);
2814
3068
  rb_define_module_function(r_mpfr_math, "tanh", r_mpfr_math_tanh, -1);
2815
3069
  rb_define_module_function(r_mpfr_math, "sinh_cosh", r_mpfr_math_sinh_cosh, -1);
3070
+ rb_define_module_function(r_mpfr_math, "sech", r_mpfr_math_sech, -1);
3071
+ rb_define_module_function(r_mpfr_math, "csch", r_mpfr_math_csch, -1);
3072
+ rb_define_module_function(r_mpfr_math, "coth", r_mpfr_math_coth, -1);
2816
3073
  rb_define_module_function(r_mpfr_math, "acosh", r_mpfr_math_acosh, -1);
2817
3074
  rb_define_module_function(r_mpfr_math, "asinh", r_mpfr_math_asinh, -1);
2818
3075
  rb_define_module_function(r_mpfr_math, "atanh", r_mpfr_math_atanh, -1);
@@ -2824,6 +3081,7 @@ void Init_mpfr()
2824
3081
  rb_define_module_function(r_mpfr_math, "gamma", r_mpfr_math_gamma, -1);
2825
3082
  rb_define_module_function(r_mpfr_math, "lngamma", r_mpfr_math_lngamma, -1);
2826
3083
  rb_define_module_function(r_mpfr_math, "lgamma", r_mpfr_math_lgamma, -1);
3084
+ rb_define_module_function(r_mpfr_math, "digamma", r_mpfr_math_digamma, -1);
2827
3085
  rb_define_module_function(r_mpfr_math, "zeta", r_mpfr_math_zeta, -1);
2828
3086
  rb_define_module_function(r_mpfr_math, "erf", r_mpfr_math_erf, -1);
2829
3087
  rb_define_module_function(r_mpfr_math, "erfc", r_mpfr_math_erfc, -1);
@@ -2837,6 +3095,7 @@ void Init_mpfr()
2837
3095
  rb_define_module_function(r_mpfr_math, "fms", r_mpfr_math_fms, -1);
2838
3096
  rb_define_module_function(r_mpfr_math, "agm", r_mpfr_math_agm, -1);
2839
3097
  rb_define_module_function(r_mpfr_math, "hypot", r_mpfr_math_hypot, -1);
3098
+ rb_define_module_function(r_mpfr_math, "ai", r_mpfr_math_ai, -1);
2840
3099
  rb_define_module_function(r_mpfr_math, "const_log2", r_mpfr_math_const_log2, -1);
2841
3100
  rb_define_module_function(r_mpfr_math, "const_pi", r_mpfr_math_const_pi, -1);
2842
3101
  rb_define_module_function(r_mpfr_math, "const_euler", r_mpfr_math_const_euler, -1);
@@ -2867,3 +3126,4 @@ void Init_mpfr()
2867
3126
  __sym_to_str__ = rb_eval_string(":to_str");
2868
3127
 
2869
3128
  }
3129
+
@@ -1,7 +1,21 @@
1
1
  require 'mkmf'
2
2
 
3
+ $CFLAGS += " -Wall"
4
+
5
+ REQUIRE_VERSION = 3
6
+
3
7
  dir_config("mpfr")
4
8
  dir_config("gmp")
9
+
5
10
  if have_header('mpfr.h') && have_library('mpfr') && have_header('gmp.h') && have_library('gmp')
6
- create_makefile("mpfr/matrix")
11
+ if have_macro('MPFR_VERSION_MAJOR', 'mpfr.h') do |src|
12
+ src + <<SRC
13
+ #if MPFR_VERSION_MAJOR < #{REQUIRE_VERSION}
14
+ # error
15
+ >>>>>> MPFR_VERSION_MAJOR requires larger than #{REQUIRE_VERSION} <<<<<<
16
+ #endif
17
+ SRC
18
+ end
19
+ create_makefile("mpfr/matrix")
20
+ end
7
21
  end
@@ -1,5 +1,12 @@
1
1
  #include "ruby_mpfr_matrix.h"
2
2
 
3
+ #define MPFR_DUMP_NUMBER 'A'
4
+ #define MPFR_DUMP_PZERO 'B'
5
+ #define MPFR_DUMP_MZERO 'C'
6
+ #define MPFR_DUMP_PINF 'D'
7
+ #define MPFR_DUMP_MINF 'E'
8
+ #define MPFR_DUMP_NAN 'F'
9
+
3
10
  static ID eqq;
4
11
 
5
12
  void r_mpfr_matrix_free(void *ptr)
@@ -185,6 +192,108 @@ static VALUE r_mpfr_matrix_initialize_copy (VALUE self, VALUE other)
185
192
  return Qtrue;
186
193
  }
187
194
 
195
+ static VALUE r_mpfr_matrix_marshal_dump(VALUE self)
196
+ {
197
+ MPFRMatrix *ptr;
198
+ r_mpfr_get_matrix_struct(ptr, self);
199
+ mpz_t m;
200
+ mp_exp_t e;
201
+ mpz_init(m);
202
+ int i;
203
+ MPFR *ptr_el;
204
+ char *tmp_str, type;
205
+ VALUE ret_ary;
206
+ ret_ary = rb_ary_new();
207
+ rb_ary_push(ret_ary, INT2FIX(ptr->row));
208
+ rb_ary_push(ret_ary, INT2FIX(ptr->column));
209
+
210
+ for (i = 0; i < ptr->size; i++) {
211
+ ptr_el = ptr->data + i;
212
+ if (mpfr_regular_p(ptr_el)) {
213
+ e = mpfr_get_z_2exp(m, ptr_el);
214
+ mpfr_asprintf(&tmp_str, "%c%ld\t%ld\t%Zd", MPFR_DUMP_NUMBER, mpfr_get_prec(ptr_el), (long int)e, m);
215
+ } else {
216
+ if (mpfr_zero_p(ptr_el)) {
217
+ if (mpfr_sgn(ptr_el) >= 0) {
218
+ type = MPFR_DUMP_PZERO;
219
+ } else {
220
+ type = MPFR_DUMP_MZERO;
221
+ }
222
+ } else if (mpfr_nan_p(ptr_el)) {
223
+ type = MPFR_DUMP_NAN;
224
+ } else if (mpfr_sgn(ptr_el) >= 0) {
225
+ type = MPFR_DUMP_PINF;
226
+ } else {
227
+ type = MPFR_DUMP_MINF;
228
+ }
229
+ mpfr_asprintf(&tmp_str, "%c%ld", type, mpfr_get_prec(ptr_el));
230
+ }
231
+ rb_ary_push(ret_ary, rb_str_new2(tmp_str));
232
+ mpfr_free_str(tmp_str);
233
+ }
234
+
235
+ mpz_clear(m);
236
+ return ret_ary;
237
+ }
238
+
239
+ static VALUE r_mpfr_matrix_marshal_load(VALUE self, VALUE dump_ary)
240
+ {
241
+ MPFRMatrix *ptr;
242
+ r_mpfr_get_matrix_struct(ptr, self);
243
+
244
+ ptr->row = NUM2INT(rb_ary_entry(dump_ary, 0));
245
+ ptr->column = NUM2INT(rb_ary_entry(dump_ary, 1));
246
+ ptr->size = ptr->row * ptr->column;
247
+ ptr->data = ALLOC_N(MPFR, ptr->size);
248
+ int i, j;
249
+ long int prec, e;
250
+ MPFR *ptr_el;
251
+ char *dump, type;
252
+ VALUE dump_element;
253
+ mpz_t m;
254
+
255
+ for(i = 0; i < ptr->size; i++){
256
+ dump_element = rb_ary_entry(dump_ary, i + 2);
257
+ ptr_el = ptr->data + i;
258
+ Check_Type(dump_element, T_STRING);
259
+ dump = RSTRING_PTR(dump_element);
260
+ type = dump[0];
261
+ dump++;
262
+ if (type == MPFR_DUMP_NUMBER) {
263
+ mpz_init(m);
264
+ sscanf(dump, "%ld\t%ld\t", &prec, &e);
265
+ j = 0;
266
+ while (j < 2) {
267
+ if (dump[0] == '\t') {
268
+ j++;
269
+ }
270
+ dump++;
271
+ }
272
+ mpz_set_str(m, dump, 10);
273
+ mpfr_init2(ptr_el, prec);
274
+ mpfr_set_z_2exp(ptr_el, m, e, MPFR_RNDN);
275
+ mpz_clear(m);
276
+ } else {
277
+ sscanf(dump, "%ld", &prec);
278
+ mpfr_init2(ptr_el, prec);
279
+ if (type == MPFR_DUMP_PZERO) {
280
+ mpfr_set_zero(ptr_el, +1);
281
+ } else if (type == MPFR_DUMP_MZERO){
282
+ mpfr_set_zero(ptr_el, -1);
283
+ } else if (type == MPFR_DUMP_NAN) {
284
+ mpfr_set_nan(ptr_el);
285
+ } else if (type == MPFR_DUMP_PINF) {
286
+ mpfr_set_inf(ptr_el, +1);
287
+ } else if (type == MPFR_DUMP_MINF) {
288
+ mpfr_set_inf(ptr_el, -1);
289
+ } else {
290
+ rb_raise(rb_eArgError, "Invalid dumped data for marshal_load.");
291
+ }
292
+ }
293
+ }
294
+ return self;
295
+ }
296
+
188
297
  /* Allocation function for MPFR::ColumnVector. */
189
298
  static VALUE r_mpfr_col_vector_alloc (VALUE self)
190
299
  {
@@ -273,7 +382,7 @@ static VALUE r_mpfr_row_vector_global_new(int argc, VALUE arg)
273
382
  {
274
383
  MPFRMatrix *ptr;
275
384
  VALUE val;
276
- r_mpfr_make_row_struct(val, ptr);
385
+ r_mpfr_make_row_vector_struct(val, ptr);
277
386
  r_mpfr_row_vector_set_initial_value(ptr, arg);
278
387
  return val;
279
388
  }
@@ -1031,6 +1140,9 @@ void Init_matrix()
1031
1140
  rb_define_private_method(r_mpfr_matrix, "initialize", r_mpfr_matrix_initialize, -1);
1032
1141
  rb_define_private_method(r_mpfr_matrix, "initialize_copy", r_mpfr_matrix_initialize_copy, 1);
1033
1142
 
1143
+ rb_define_method(r_mpfr_matrix, "marshal_dump", r_mpfr_matrix_marshal_dump, 0);
1144
+ rb_define_method(r_mpfr_matrix, "marshal_load", r_mpfr_matrix_marshal_load, 1);
1145
+
1034
1146
  rb_define_singleton_method(tmp_r_mpfr_class, "SquareMatrix", r_mpfr_square_matrix_global_new, 1);
1035
1147
  rb_define_alloc_func(r_mpfr_square_matrix, r_mpfr_square_matrix_alloc);
1036
1148
  rb_define_private_method(r_mpfr_square_matrix, "initialize", r_mpfr_square_matrix_initialize, 1);
@@ -1 +1 @@
1
- RUBY_MPFR_VERSION = '0.0.7'
1
+ RUBY_MPFR_VERSION = '0.0.8'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  describe MPFR, 'when allocating objects from integer' do
4
4
  it "should equal bignum" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  MPFR.set_default_prec(256)
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  MPFR.set_default_prec(256)
4
4
 
@@ -1,10 +1,8 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  describe MPFR, "when calling constant of MPFR" do
4
4
  it "should be defined" do
5
5
  MPFR::MPFR_VERSION.should be_true
6
- MPFR::MPFR_PATCHES.should be_true
7
- MPFR::MPFR_VERSION2.should be_true
8
6
  MPFR::MPFR_VERSION_MAJOR.should be_true
9
7
  MPFR::MPFR_VERSION_MINOR.should be_true
10
8
  MPFR::MPFR_VERSION_PATCHLEVEL.should be_true
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  MPFR.set_default_prec(90)
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  describe MPFR, "when executing methods which are exception related functions" do
4
4
  it "should get and set emin and emax" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  MPFR.set_default_prec(256)
4
4
 
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
+
3
+ describe MPFR do
4
+ context "when marshaling" do
5
+ before(:all) do
6
+ MPFR.set_default_prec(256)
7
+ end
8
+
9
+ it "should restore nan" do
10
+ n = MPFR.nan(128)
11
+ n2 = Marshal.load(Marshal.dump(n))
12
+ n2.nan?.should be_true
13
+ n2.get_prec.should == 128
14
+ end
15
+
16
+ it "should restore plus infinity" do
17
+ n = MPFR.pinf(128)
18
+ n2 = Marshal.load(Marshal.dump(n))
19
+ n2.infinite?.should be_true
20
+ n2.get_prec.should == 128
21
+ n2.sgn.should > 0
22
+ end
23
+
24
+ it "should restore minus infinity" do
25
+ n = MPFR.minf(128)
26
+ n2 = Marshal.load(Marshal.dump(n))
27
+ n2.infinite?.should be_true
28
+ n2.get_prec.should == 128
29
+ n2.sgn.should < 0
30
+ end
31
+
32
+ it "should restore plus zero" do
33
+ n = MPFR.zero(1, 128)
34
+ n2 = Marshal.load(Marshal.dump(n))
35
+ n2.zero?.should be_true
36
+ n2.get_prec.should == 128
37
+ n2.sgn.should >= 0
38
+ end
39
+
40
+ it "should restore minus zero" do
41
+ n = MPFR.zero(-1, 128)
42
+ n2 = Marshal.load(Marshal.dump(n))
43
+ n2.zero?.should be_true
44
+ n2.get_prec.should == 128
45
+ n2.sgn.should <= 0
46
+ end
47
+
48
+ it "should restore regular numbers" do
49
+ GenerateNumber.string(1000).each do |s|
50
+ n = MPFR(s, MPFR::RNDN, 128)
51
+ n2 = Marshal.load(Marshal.dump(n))
52
+ n2.should == n
53
+ n2.get_prec.should == 128
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  def check_rnd(a)
4
4
  MPFR.new(a).should == MPFR.new(a, MPFR.get_default_rounding_mode)
@@ -6,9 +6,11 @@ def check_rnd(a)
6
6
  z = MPFR.new(a, MPFR::RNDZ)
7
7
  u = MPFR.new(a, MPFR::RNDU)
8
8
  d = MPFR.new(a, MPFR::RNDD)
9
+ a = MPFR.new(a, MPFR::RNDA)
9
10
  (n > 0 ? d : u).should == z
10
11
  [(a - z).abs, (a - u).abs, (a - d).abs].min.should >= (a - n).abs
11
12
  (d <= u && (n == z || n == u || n == d)).should be_true
13
+ z.abs.should <= a.abs
12
14
  end
13
15
 
14
16
  def check_set_rnd(rnd1, rnd2)
@@ -24,11 +26,11 @@ describe MPFR, 'when getting rounding mode' do
24
26
  args = GenerateNumber.float(100)
25
27
  args += [Math::PI, -Math::PI, Math::E, -Math::E, 0, 10, 27, -9, -293578]
26
28
  args.each{ |a| check_rnd(a) }
27
- [MPFR::RNDN, MPFR::RNDZ, MPFR::RNDU, MPFR::RNDD].each{ |rnd| args.each{ |a| check_rnd(a) } }
29
+ [MPFR::RNDN, MPFR::RNDZ, MPFR::RNDU, MPFR::RNDD, MPFR::RNDA].each{ |rnd| args.each{ |a| check_rnd(a) } }
28
30
  end
29
31
 
30
32
  it "should be set rounding mode" do
31
- rnds = [MPFR::RNDN, MPFR::RNDZ, MPFR::RNDU, MPFR::RNDD]
33
+ rnds = [MPFR::RNDN, MPFR::RNDZ, MPFR::RNDU, MPFR::RNDD, MPFR::RNDA]
32
34
  for i in 0...rnds.size
33
35
  for j in (i+1)...rnds.size
34
36
  check_set_rnd(rnds[i], rnds[j])
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  describe MPFR, "when rounding number by prec_round" do
4
4
  before(:all) do
@@ -38,7 +38,7 @@ describe MPFR, "when rounding number by prec_round" do
38
38
 
39
39
  it "should be rounded by prec_round!" do
40
40
  @args.each do |a|
41
- [MPFR::RNDU, MPFR::RNDD, MPFR::RNDN, MPFR::RNDZ].each do |rnd|
41
+ [MPFR::RNDU, MPFR::RNDD, MPFR::RNDN, MPFR::RNDZ, MPFR::RNDA].each do |rnd|
42
42
  b = a.dup
43
43
  old_object_id = b.object_id
44
44
  b.prec_round!(rnd, @prec)
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  MPFR.set_default_prec(300)
4
4
 
@@ -1,13 +1,13 @@
1
1
  begin
2
- require 'spec'
2
+ require 'rspec'
3
3
  rescue LoadError
4
4
  require 'rubygems' unless ENV['NO_RUBYGEMS']
5
5
  gem 'rspec'
6
- require 'spec'
6
+ require 'rspec'
7
7
  end
8
8
 
9
- $:.unshift(File.dirname(__FILE__) + '/../../lib')
10
- $:.unshift(File.dirname(__FILE__) + '/../../ext')
11
- $:.unshift(File.dirname(__FILE__))
12
- require 'mpfr'
9
+ $:.unshift(File.expand_path(File.dirname(__FILE__)) + '/../../lib')
10
+ $:.unshift(File.expand_path(File.dirname(__FILE__)) + '/../../ext')
11
+ $:.unshift(File.expand_path(File.dirname(__FILE__)))
12
+ require 'mpfr/mpfr'
13
13
  require "generate_number_modulue"
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  describe MPFR, "when converted to string" do
4
4
  before(:all) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  describe "initialization of matrix" do
4
4
  before(:all) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  describe MPFR::Matrix, "when making matrix negative" do
4
4
  before(:all) do
@@ -0,0 +1,65 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
+
3
+ describe MPFR::Matrix, "when marshaling" do
4
+ before(:all) do
5
+ MPFR.set_default_prec(128)
6
+ end
7
+
8
+ it "should be restore" do
9
+ row = 8
10
+ column = 3
11
+ args = GenerateNumber.float_matrix_arguments(1000, row, column).map{ |a| MPFR::Matrix.new(a) }
12
+ args.each do |m|
13
+ m2 = Marshal.load(Marshal.dump(m))
14
+ m2.should == m
15
+ end
16
+ end
17
+ end
18
+
19
+ describe MPFR::SquareMatrix, "when marshaling" do
20
+ before(:all) do
21
+ MPFR.set_default_prec(128)
22
+ end
23
+
24
+ it "should be restore" do
25
+ row = 4
26
+ column = 4
27
+ args = GenerateNumber.float_matrix_arguments(1000, row, column).map{ |a| MPFR::SquareMatrix.new(a) }
28
+ args.each do |m|
29
+ m2 = Marshal.load(Marshal.dump(m))
30
+ m2.should == m
31
+ end
32
+ end
33
+ end
34
+
35
+ describe MPFR::ColumnVector, "when marshaling" do
36
+ before(:all) do
37
+ MPFR.set_default_prec(128)
38
+ end
39
+
40
+ it "should be restore" do
41
+ row = 1
42
+ column = 6
43
+ args = GenerateNumber.float_matrix_arguments(1000, row, column).map{ |a| MPFR::ColumnVector.new(a[0]) }
44
+ args.each do |m|
45
+ m2 = Marshal.load(Marshal.dump(m))
46
+ m2.should == m
47
+ end
48
+ end
49
+ end
50
+
51
+ describe MPFR::RowVector, "when marshaling" do
52
+ before(:all) do
53
+ MPFR.set_default_prec(128)
54
+ end
55
+
56
+ it "should be restore" do
57
+ row = 1
58
+ column = 6
59
+ args = GenerateNumber.float_matrix_arguments(1000, row, column).map{ |a| MPFR::RowVector.new(a[0]) }
60
+ args.each do |m|
61
+ m2 = Marshal.load(Marshal.dump(m))
62
+ m2.should == m
63
+ end
64
+ end
65
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  describe MPFR::Matrix, "when setting number to particular element" do
4
4
  before(:all) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  describe MPFR::Matrix, "when MPFR instance is converted to string by some methods." do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
 
3
3
  describe MPFR::SquareMatrix, "when calculating LU decomposition" do
4
4
  before(:all) do
@@ -1,9 +1,9 @@
1
1
  begin
2
- require 'spec'
2
+ require 'rspec'
3
3
  rescue LoadError
4
4
  require 'rubygems' unless ENV['NO_RUBYGEMS']
5
5
  gem 'rspec'
6
- require 'spec'
6
+ require 'rspec'
7
7
  end
8
8
 
9
9
  $:.unshift(File.dirname(__FILE__) + '/../../lib')
@@ -1,18 +1,18 @@
1
- begin
2
- require 'spec'
3
- rescue LoadError
4
- require 'rubygems' unless ENV['NO_RUBYGEMS']
5
- require 'spec'
6
- end
7
- begin
8
- require 'spec/rake/spectask'
9
- rescue LoadError
10
- puts <<-EOS
11
- To use rspec for testing you must install rspec gem:
12
- gem install rspec
13
- EOS
14
- exit(0)
15
- end
1
+ # begin
2
+ # require 'rspec'
3
+ # rescue LoadError
4
+ # require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ # require 'rspec'
6
+ # end
7
+ # begin
8
+ # require 'rspec/rake/spectask'
9
+ # rescue LoadError
10
+ # puts <<-EOS
11
+ # To use rspec for testing you must install rspec gem:
12
+ # gem install rspec
13
+ # EOS
14
+ # exit(0)
15
+ # end
16
16
 
17
17
  desc "Run 'make realclean' for extended libraries"
18
18
  task "ext:realclean" do
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mpfr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 8
9
+ version: 0.0.8
5
10
  platform: ruby
6
11
  authors:
7
12
  - Takayuki YAMAGUCHI
@@ -9,39 +14,39 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-21 00:00:00 +09:00
17
+ date: 2010-11-14 00:00:00 +09:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rubyforge
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
23
- version: 2.0.3
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: gemcutter
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 4
32
+ version: 2.0.4
27
33
  type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.3.0
34
- version:
34
+ version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: hoe
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 2.5.0
44
- version:
43
+ segments:
44
+ - 2
45
+ - 6
46
+ - 2
47
+ version: 2.6.2
48
+ type: :development
49
+ version_requirements: *id002
45
50
  description: |-
46
51
  ruby-mpfr is a library to use MPFR[http://www.mpfr.org/] which is a C library for
47
52
  multiple-precision floating-point computations.
@@ -93,6 +98,7 @@ files:
93
98
  - spec/mpfr/exception_spec.rb
94
99
  - spec/mpfr/functions_spec.rb
95
100
  - spec/mpfr/generate_number_modulue.rb
101
+ - spec/mpfr/marshal_spec.rb
96
102
  - spec/mpfr/precision_roundmode_spec.rb
97
103
  - spec/mpfr/rounding_spec.rb
98
104
  - spec/mpfr/set_value_spec.rb
@@ -101,11 +107,11 @@ files:
101
107
  - spec/mpfr_matrix/generate_matrix_arguments.rb
102
108
  - spec/mpfr_matrix/mpfr_matrix_alloc_spec.rb
103
109
  - spec/mpfr_matrix/mpfr_matrix_arithmetic_spec.rb
110
+ - spec/mpfr_matrix/mpfr_matrix_marshal_spec.rb
104
111
  - spec/mpfr_matrix/mpfr_matrix_set_element_spec.rb
105
112
  - spec/mpfr_matrix/mpfr_matrix_string_spec.rb
106
113
  - spec/mpfr_matrix/mpfr_square_matrix_spec.rb
107
114
  - spec/mpfr_matrix/spec_helper.rb
108
- - spec/spec.opts
109
115
  - tasks/extconf.rake
110
116
  has_rdoc: true
111
117
  homepage: http://rubyforge.org/projects/ruby-mpfr/
@@ -117,23 +123,26 @@ rdoc_options:
117
123
  - README.rdoc
118
124
  require_paths:
119
125
  - lib
120
- - ext
121
126
  required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
122
128
  requirements:
123
129
  - - ">="
124
130
  - !ruby/object:Gem::Version
131
+ segments:
132
+ - 0
125
133
  version: "0"
126
- version:
127
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
+ none: false
128
136
  requirements:
129
137
  - - ">="
130
138
  - !ruby/object:Gem::Version
139
+ segments:
140
+ - 0
131
141
  version: "0"
132
- version:
133
142
  requirements: []
134
143
 
135
144
  rubyforge_project: ruby-mpfr
136
- rubygems_version: 1.3.5
145
+ rubygems_version: 1.3.7
137
146
  signing_key:
138
147
  specification_version: 3
139
148
  summary: ruby-mpfr is a library to use MPFR[http://www.mpfr.org/] which is a C library for multiple-precision floating-point computations
@@ -1 +0,0 @@
1
- --colour