ruby-mpfr 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/History.txt +7 -0
  2. data/README.rdoc +17 -2
  3. data/Rakefile +26 -26
  4. data/ext/ruby_mpfr.c +51 -16
  5. data/lib/ruby-mpfr.rb +2 -2
  6. metadata +2 -2
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ # -*- rd -*-
2
+
3
+ === 0.0.2 2009-07-25
4
+ * 2 minor enhancements:
5
+ * Add comments in a source file.
6
+ * Add method MPFR::Math.sum.
7
+
1
8
  === 0.0.1 2009-07-11
2
9
 
3
10
  * 1 major enhancement:
data/README.rdoc CHANGED
@@ -22,7 +22,7 @@ multiple-precision floating-point computations.
22
22
  == REQUIREMENTS:
23
23
 
24
24
  * GMP
25
- * MPFR
25
+ * MPFR 2.4.0 or later
26
26
 
27
27
  == INSTALL:
28
28
 
@@ -30,4 +30,19 @@ multiple-precision floating-point computations.
30
30
 
31
31
  == LICENSE:
32
32
 
33
- LGPL v3
33
+ ruby-mpfr
34
+ Copyright (C) 2009 Takayuki YAMAGUCHI
35
+
36
+ This program is free software; you can redistribute it and/or modify it under
37
+ the terms of the GNU Lesser General Public License as published by the Free
38
+ Software Foundation; either version 3 of the License, or (at your option) any
39
+ later version.
40
+
41
+ This program is distributed in the hope that it will be useful, but WITHOUT
42
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
44
+ details.
45
+
46
+ You should have received a copy of the GNU General Public License along with
47
+ this program. If not, see <http://www.gnu.org/licenses/>.
48
+
data/Rakefile CHANGED
@@ -1,26 +1,26 @@
1
- require 'rubygems'
2
- gem 'hoe', '>= 2.1.0'
3
- require 'hoe'
4
- require 'fileutils'
5
- require './lib/ruby-mpfr'
6
-
7
- Hoe.plugin :newgem
8
- # Hoe.plugin :website
9
- # Hoe.plugin :cucumberfeatures
10
-
11
- # Generate all the Rake tasks
12
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
- $hoe = Hoe.spec 'ruby-mpfr' do
14
- self.developer 'Takayuki YAMAGUCHI', 'd@ytak.info'
15
- self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
- self.rubyforge_name = self.name # TODO this is default value
17
- # self.extra_deps = [['activesupport','>= 2.0.2']]
18
- self.spec_extras[:extensions] = "ext/extconf.rb"
19
- end
20
-
21
- require 'newgem/tasks'
22
- Dir['tasks/**/*.rake'].each { |t| load t }
23
-
24
- # TODO - want other tests/tasks run by default? Add them to the list
25
- # remove_task :default
26
- # task :default => [:spec, :features]
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/ruby-mpfr'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'ruby-mpfr' do
14
+ self.developer 'Takayuki YAMAGUCHI', 'd@ytak.info'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+ self.spec_extras[:extensions] = "ext/extconf.rb"
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
data/ext/ruby_mpfr.c CHANGED
@@ -287,6 +287,7 @@ static VALUE r_mpfr_initialize(int argc, VALUE *argv, VALUE self){
287
287
  return Qtrue;
288
288
  }
289
289
 
290
+ /* This method is the method of initialization for copying object. */
290
291
  static VALUE r_mpfr_initialize_copy(VALUE self, VALUE other){
291
292
  MPFR *ptr_self, *ptr_other;
292
293
  r_mpfr_get_struct(ptr_self, self);
@@ -1081,6 +1082,7 @@ static VALUE r_mpfr_unordered_p(VALUE self, VALUE other){
1081
1082
 
1082
1083
  /* ------------------------------ Integer Related Functions Start ------------------------------ */
1083
1084
 
1085
+ /* mpfr_rint(ret, self, rnd) */
1084
1086
  static VALUE r_mpfr_m_rint(int argc, VALUE *argv, VALUE self){
1085
1087
  mp_rnd_t rnd;
1086
1088
  mp_prec_t prec;
@@ -1093,6 +1095,7 @@ static VALUE r_mpfr_m_rint(int argc, VALUE *argv, VALUE self){
1093
1095
  return val_ret;
1094
1096
  }
1095
1097
 
1098
+ /* mpfr_ceil(ret, self) */
1096
1099
  static VALUE r_mpfr_m_ceil(int argc, VALUE *argv, VALUE self){
1097
1100
  mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv);
1098
1101
  MPFR *ptr_self, *ptr_return;
@@ -1103,6 +1106,7 @@ static VALUE r_mpfr_m_ceil(int argc, VALUE *argv, VALUE self){
1103
1106
  return val_ret;
1104
1107
  }
1105
1108
 
1109
+ /* mpfr_floor(ret, self) */
1106
1110
  static VALUE r_mpfr_m_floor(int argc, VALUE *argv, VALUE self){
1107
1111
  mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv);
1108
1112
  MPFR *ptr_self, *ptr_return;
@@ -1113,6 +1117,7 @@ static VALUE r_mpfr_m_floor(int argc, VALUE *argv, VALUE self){
1113
1117
  return val_ret;
1114
1118
  }
1115
1119
 
1120
+ /* mpfr_round(ret, self) */
1116
1121
  static VALUE r_mpfr_m_round(int argc, VALUE *argv, VALUE self){
1117
1122
  mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv);
1118
1123
  MPFR *ptr_self, *ptr_return;
@@ -1123,6 +1128,7 @@ static VALUE r_mpfr_m_round(int argc, VALUE *argv, VALUE self){
1123
1128
  return val_ret;
1124
1129
  }
1125
1130
 
1131
+ /* mpfr_trunc(ret, self) */
1126
1132
  static VALUE r_mpfr_m_trunc(int argc, VALUE *argv, VALUE self){
1127
1133
  mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv);
1128
1134
  MPFR *ptr_self, *ptr_return;
@@ -1133,6 +1139,7 @@ static VALUE r_mpfr_m_trunc(int argc, VALUE *argv, VALUE self){
1133
1139
  return val_ret;
1134
1140
  }
1135
1141
 
1142
+ /* mpfr_rint_ceil(ret, self, rnd) */
1136
1143
  static VALUE r_mpfr_rint_ceil(int argc, VALUE *argv, VALUE self){
1137
1144
  mp_rnd_t rnd;
1138
1145
  mp_prec_t prec;
@@ -1145,6 +1152,7 @@ static VALUE r_mpfr_rint_ceil(int argc, VALUE *argv, VALUE self){
1145
1152
  return val_ret;
1146
1153
  }
1147
1154
 
1155
+ /* mpfr_rint_floor(ret, self, rnd) */
1148
1156
  static VALUE r_mpfr_rint_floor(int argc, VALUE *argv, VALUE self){
1149
1157
  mp_rnd_t rnd;
1150
1158
  mp_prec_t prec;
@@ -1157,6 +1165,7 @@ static VALUE r_mpfr_rint_floor(int argc, VALUE *argv, VALUE self){
1157
1165
  return val_ret;
1158
1166
  }
1159
1167
 
1168
+ /* mpfr_rint_round(ret, self, rnd) */
1160
1169
  static VALUE r_mpfr_rint_round(int argc, VALUE *argv, VALUE self){
1161
1170
  mp_rnd_t rnd;
1162
1171
  mp_prec_t prec;
@@ -1169,6 +1178,7 @@ static VALUE r_mpfr_rint_round(int argc, VALUE *argv, VALUE self){
1169
1178
  return val_ret;
1170
1179
  }
1171
1180
 
1181
+ /* mpfr_rint_trunc(ret, self, rnd) */
1172
1182
  static VALUE r_mpfr_rint_trunc(int argc, VALUE *argv, VALUE self){
1173
1183
  mp_rnd_t rnd;
1174
1184
  mp_prec_t prec;
@@ -1181,6 +1191,7 @@ static VALUE r_mpfr_rint_trunc(int argc, VALUE *argv, VALUE self){
1181
1191
  return val_ret;
1182
1192
  }
1183
1193
 
1194
+ /* mpfr_frac(ret, self, rnd) */
1184
1195
  static VALUE r_mpfr_frac(int argc, VALUE *argv, VALUE self){
1185
1196
  mp_rnd_t rnd;
1186
1197
  mp_prec_t prec;
@@ -1207,6 +1218,7 @@ static VALUE r_mpfr_modf(int argc, VALUE *argv, VALUE self){
1207
1218
  return rb_ary_new3(2, val_ret1, val_ret2);
1208
1219
  }
1209
1220
 
1221
+ /* mpfr_fmod(ret, self, p1, rnd) */
1210
1222
  static VALUE r_mpfr_fmod(int argc, VALUE *argv, VALUE self){
1211
1223
  mp_rnd_t rnd;
1212
1224
  mp_prec_t prec;
@@ -1221,6 +1233,7 @@ static VALUE r_mpfr_fmod(int argc, VALUE *argv, VALUE self){
1221
1233
  return val_ret;
1222
1234
  }
1223
1235
 
1236
+ /* mpfr_remainder(ret, self, p1, rnd) */
1224
1237
  static VALUE r_mpfr_remainder(int argc, VALUE *argv, VALUE self){
1225
1238
  mp_rnd_t rnd;
1226
1239
  mp_prec_t prec;
@@ -1235,6 +1248,7 @@ static VALUE r_mpfr_remainder(int argc, VALUE *argv, VALUE self){
1235
1248
  return val_ret;
1236
1249
  }
1237
1250
 
1251
+ /* mpfr_remainder(ret, self, p1, mpfr_getdefault_rounding_mode()) */
1238
1252
  static VALUE r_mpfr_remainder2(VALUE self, VALUE other){
1239
1253
  MPFR *ptr_self, *ptr_other, *ptr_return;
1240
1254
  VALUE val_ret;
@@ -1246,6 +1260,7 @@ static VALUE r_mpfr_remainder2(VALUE self, VALUE other){
1246
1260
  return val_ret;
1247
1261
  }
1248
1262
 
1263
+ /* mpfr_remquo(ret1, ret2, self, p1, rnd) */
1249
1264
  static VALUE r_mpfr_remquo(int argc, VALUE *argv, VALUE self){
1250
1265
  mp_rnd_t rnd;
1251
1266
  mp_prec_t prec;
@@ -1261,6 +1276,7 @@ static VALUE r_mpfr_remquo(int argc, VALUE *argv, VALUE self){
1261
1276
  return rb_ary_new3(2, val_ret, LONG2FIX(q));
1262
1277
  }
1263
1278
 
1279
+ /* If value of self is integer, return true. Otherwise, nil. */
1264
1280
  static VALUE r_mpfr_integer_p(VALUE self){
1265
1281
  MPFR *ptr_self;
1266
1282
  r_mpfr_get_struct(ptr_self, self);
@@ -1271,6 +1287,7 @@ static VALUE r_mpfr_integer_p(VALUE self){
1271
1287
 
1272
1288
  /* ------------------------------ Miscellaneous Functions Start ------------------------------ */
1273
1289
 
1290
+ /* mpfr_nexttoward(self, p1) */
1274
1291
  static VALUE r_mpfr_nexttoward(VALUE self, VALUE other){
1275
1292
  MPFR *ptr_self, *ptr_other;
1276
1293
  r_mpfr_get_struct(ptr_self, self);
@@ -1280,6 +1297,7 @@ static VALUE r_mpfr_nexttoward(VALUE self, VALUE other){
1280
1297
  return self;
1281
1298
  }
1282
1299
 
1300
+ /* mpfr_nextabove(self) */
1283
1301
  static VALUE r_mpfr_nextabove(VALUE self){
1284
1302
  MPFR *ptr_self;
1285
1303
  r_mpfr_get_struct(ptr_self, self);
@@ -1287,6 +1305,7 @@ static VALUE r_mpfr_nextabove(VALUE self){
1287
1305
  return self;
1288
1306
  }
1289
1307
 
1308
+ /* mpfr_nextbelow(self) */
1290
1309
  static VALUE r_mpfr_nextbelow(VALUE self){
1291
1310
  MPFR *ptr_self;
1292
1311
  r_mpfr_get_struct(ptr_self, self);
@@ -1294,6 +1313,7 @@ static VALUE r_mpfr_nextbelow(VALUE self){
1294
1313
  return self;
1295
1314
  }
1296
1315
 
1316
+ /* If self is not number, return nil. Otherwise return an integer mpfr_get_exp(self). */
1297
1317
  static VALUE r_mpfr_get_exp(VALUE self){
1298
1318
  MPFR *ptr_self;
1299
1319
  r_mpfr_get_struct(ptr_self, self);
@@ -1304,6 +1324,7 @@ static VALUE r_mpfr_get_exp(VALUE self){
1304
1324
  }
1305
1325
  }
1306
1326
 
1327
+ /* arg_exp is integer and we execute mpfr_set_exp(self, arg_exp). */
1307
1328
  static VALUE r_mpfr_set_exp(VALUE self, VALUE arg_exp){
1308
1329
  MPFR *ptr_self;
1309
1330
  r_mpfr_get_struct(ptr_self, self);
@@ -1312,12 +1333,14 @@ static VALUE r_mpfr_set_exp(VALUE self, VALUE arg_exp){
1312
1333
  return self;
1313
1334
  }
1314
1335
 
1336
+ /* Return integer which is mpfr_signbit(self). */
1315
1337
  static VALUE r_mpfr_signbit(VALUE self){
1316
1338
  MPFR *ptr_self;
1317
1339
  r_mpfr_get_struct(ptr_self, self);
1318
1340
  return INT2FIX(mpfr_signbit(ptr_self));
1319
1341
  }
1320
1342
 
1343
+ /* mpfr_setsign(ret, self, p1, rnd) */
1321
1344
  static VALUE r_mpfr_setsign(int argc, VALUE *argv, VALUE self){
1322
1345
  mp_rnd_t rnd;
1323
1346
  mp_prec_t prec;
@@ -1331,6 +1354,7 @@ static VALUE r_mpfr_setsign(int argc, VALUE *argv, VALUE self){
1331
1354
  return val_ret;
1332
1355
  }
1333
1356
 
1357
+ /* mpfr_copysign(ret, self, p1, rnd) */
1334
1358
  static VALUE r_mpfr_copysign(int argc, VALUE *argv, VALUE self){
1335
1359
  mp_rnd_t rnd;
1336
1360
  mp_prec_t prec;
@@ -1349,6 +1373,7 @@ static VALUE r_mpfr_copysign(int argc, VALUE *argv, VALUE self){
1349
1373
 
1350
1374
  /* ------------------------------ Rounding Mode Related Functions Start ------------------------------ */
1351
1375
 
1376
+ /* mpfr_prec_round(ret, prec, rnd) */
1352
1377
  static VALUE r_mpfr_prec_round(int argc, VALUE *argv, VALUE self){
1353
1378
  mp_rnd_t rnd;
1354
1379
  mp_prec_t prec;
@@ -1362,6 +1387,7 @@ static VALUE r_mpfr_prec_round(int argc, VALUE *argv, VALUE self){
1362
1387
  return val_ret;
1363
1388
  }
1364
1389
 
1390
+ /* mpfr_prec_round(ret, prec, rnd) */
1365
1391
  static VALUE r_mpfr_prec_round2(int argc, VALUE *argv, VALUE self){
1366
1392
  mp_rnd_t rnd;
1367
1393
  mp_prec_t prec;
@@ -1827,6 +1853,7 @@ static VALUE r_mpfr_math_lngamma(int argc, VALUE *argv, VALUE self){
1827
1853
  return val_ret;
1828
1854
  }
1829
1855
 
1856
+ /* Execute mpfr_lgamma(ret1, ret2, p1, rnd) and return [ret1, ret2]. */
1830
1857
  static VALUE r_mpfr_math_lgamma(int argc, VALUE *argv, VALUE self){
1831
1858
  mp_rnd_t rnd;
1832
1859
  mp_prec_t prec;
@@ -1919,6 +1946,7 @@ static VALUE r_mpfr_math_j1(int argc, VALUE *argv, VALUE self){
1919
1946
  return val_ret;
1920
1947
  }
1921
1948
 
1949
+ /* mpfr_jn(ret, p2, p1, rnd) */
1922
1950
  static VALUE r_mpfr_math_jn(int argc, VALUE *argv, VALUE self){
1923
1951
  mp_rnd_t rnd;
1924
1952
  mp_prec_t prec;
@@ -1961,6 +1989,7 @@ static VALUE r_mpfr_math_y1(int argc, VALUE *argv, VALUE self){
1961
1989
  return val_ret;
1962
1990
  }
1963
1991
 
1992
+ /* mpfr_yn(ret, p2, p1, rnd) */
1964
1993
  static VALUE r_mpfr_math_yn(int argc, VALUE *argv, VALUE self){
1965
1994
  mp_rnd_t rnd;
1966
1995
  mp_prec_t prec;
@@ -2097,21 +2126,27 @@ static VALUE r_mpfr_math_free_cache(VALUE self){
2097
2126
  return Qnil;
2098
2127
  }
2099
2128
 
2100
- /* static VALUE r_mpfr_math_sum(int argc, VALUE *argv, VALUE self){ */
2101
- /* mp_rnd_t rnd; */
2102
- /* mp_prec_t prec; */
2103
- /* r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv); */
2104
- /* MPFR *ptr_return, *ptr_args[argc]; */
2105
- /* VALUE val_ret; */
2106
- /* int i; */
2107
- /* for(i = 0; i < argc; i++){ */
2108
- /* volatile VALUE tmp_argvi = r_mpfr_new_fr_obj(argv[i]); */
2109
- /* r_mpfr_get_struct(ptr_args[i], tmp_argvi); */
2110
- /* } */
2111
- /* r_mpfr_make_struct_init2(val_ret, ptr_return, prec); */
2112
- /* r_mpfr_set_special_func_state(mpfr_sum(ptr_return, ptr_args, argc, rnd)); */
2113
- /* return val_ret; */
2114
- /* } */
2129
+ /* Calculate sum of MPFR objects. */
2130
+ static VALUE r_mpfr_math_sum(int argc, VALUE *argv, VALUE self){
2131
+ int num;
2132
+ for (num = 0; num < argc; num += 1) {
2133
+ if(!RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[num]))){ break; }
2134
+ }
2135
+
2136
+ mp_rnd_t rnd;
2137
+ mp_prec_t prec;
2138
+ r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, num, num + 2, argc, argv);
2139
+ MPFR *ptr_return, *ptr_args[num];
2140
+ VALUE val_ret;
2141
+ int i;
2142
+ for(i = 0; i < num; i++){
2143
+ volatile VALUE tmp_argvi = r_mpfr_new_fr_obj(argv[i]);
2144
+ r_mpfr_get_struct(ptr_args[i], tmp_argvi);
2145
+ }
2146
+ r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
2147
+ r_mpfr_set_special_func_state(mpfr_sum(ptr_return, ptr_args, argc, rnd));
2148
+ return val_ret;
2149
+ }
2115
2150
 
2116
2151
  /* ------------------------------ Special Functions End ------------------------------ */
2117
2152
 
@@ -2515,7 +2550,7 @@ void Init_mpfr(){
2515
2550
  rb_define_module_function(r_mpfr_math, "const_euler", r_mpfr_math_const_euler, -1);
2516
2551
  rb_define_module_function(r_mpfr_math, "const_catalan", r_mpfr_math_const_catalan, -1);
2517
2552
  rb_define_module_function(r_mpfr_math, "free_cache", r_mpfr_math_free_cache, 0);
2518
- /* rb_define_module_function(r_mpfr_math, "sum", r_mpfr_math_sum, -1); */
2553
+ rb_define_module_function(r_mpfr_math, "sum", r_mpfr_math_sum, -1);
2519
2554
 
2520
2555
  /* ------------------------------ Special Functions End ------------------------------ */
2521
2556
 
data/lib/ruby-mpfr.rb CHANGED
@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module RubyMpfr
5
- VERSION = '0.0.1'
6
- end
5
+ VERSION = '0.0.2'
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mpfr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takayuki YAMAGUCHI
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-13 00:00:00 +09:00
12
+ date: 2009-07-25 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency