Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

merge revision(s) 21298:

	* numeric.c (ruby_float_step): extracted from num_step().
	* range.c (range_step): uses ruby_float_step() for float range.
	  [ruby-dev:37691]


git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7@22528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 1dd679818bc0d5698590e2629fe6eafc0ea0e715 1 parent 9f30492
Urabe, Shyouhei authored February 22, 2009
7  ChangeLog
... ...
@@ -1,3 +1,10 @@
  1
+Sun Feb 22 21:43:34 2009  Nobuyoshi Nakada  <nobu@ruby-lang.org>
  2
+
  3
+	* numeric.c (ruby_float_step): extracted from num_step().
  4
+
  5
+	* range.c (range_step): uses ruby_float_step() for float range.
  6
+	  [ruby-dev:37691]
  7
+
1 8
 Sun Feb 22 00:49:36 2009  Nobuyoshi Nakada  <nobu@ruby-lang.org>
2 9
 
3 10
 	* ext/extmk.rb (extmake): does not use both of makefile.rb and
44  numeric.c
@@ -1427,6 +1427,33 @@ num_truncate(num)
1427 1427
 }
1428 1428
 
1429 1429
 
  1430
+int ruby_float_step _((VALUE from, VALUE to, VALUE step, int excl));
  1431
+
  1432
+int
  1433
+ruby_float_step(from, to, step, excl)
  1434
+    VALUE from, to, step;
  1435
+    int excl;
  1436
+{
  1437
+    if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) {
  1438
+	const double epsilon = DBL_EPSILON;
  1439
+	double beg = NUM2DBL(from);
  1440
+	double end = NUM2DBL(to);
  1441
+	double unit = NUM2DBL(step);
  1442
+	double n = (end - beg)/unit;
  1443
+	double err = (fabs(beg) + fabs(end) + fabs(end-beg)) / fabs(unit) * epsilon;
  1444
+	long i;
  1445
+
  1446
+	if (err>0.5) err=0.5;
  1447
+	n = floor(n + err);
  1448
+	if (!excl) n++;
  1449
+	for (i=0; i<n; i++) {
  1450
+	    rb_yield(rb_float_new(i*unit+beg));
  1451
+	}
  1452
+	return Qtrue;
  1453
+    }
  1454
+    return Qfalse;
  1455
+}
  1456
+
1430 1457
 /*
1431 1458
  *  call-seq:
1432 1459
  *     num.step(limit, step ) {|i| block }     => num
@@ -1501,22 +1528,7 @@ num_step(argc, argv, from)
1501 1528
 	    }
1502 1529
 	}
1503 1530
     }
1504  
-    else if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) {
1505  
-	const double epsilon = DBL_EPSILON;
1506  
-	double beg = NUM2DBL(from);
1507  
-	double end = NUM2DBL(to);
1508  
-	double unit = NUM2DBL(step);
1509  
-	double n = (end - beg)/unit;
1510  
-	double err = (fabs(beg) + fabs(end) + fabs(end-beg)) / fabs(unit) * epsilon;
1511  
-	long i;
1512  
-
1513  
-	if (err>0.5) err=0.5;
1514  
-	n = floor(n + err) + 1;
1515  
-	for (i=0; i<n; i++) {
1516  
-	    rb_yield(rb_float_new(i*unit+beg));
1517  
-	}
1518  
-    }
1519  
-    else {
  1531
+    else if (!ruby_float_step(from, to, step, Qfalse)) {
1520 1532
 	VALUE i = from;
1521 1533
 	ID cmp;
1522 1534
 
5  range.c
@@ -273,6 +273,8 @@ step_i(i, arg)
273 273
     return Qnil;
274 274
 }
275 275
 
  276
+extern int ruby_float_step _((VALUE from, VALUE to, VALUE step, int excl));
  277
+
276 278
 /*
277 279
  *  call-seq:
278 280
  *     rng.step(n=1) {| obj | block }    => rng
@@ -343,6 +345,9 @@ range_step(argc, argv, range)
343 345
 	}
344 346
 
345 347
     }
  348
+    else if (ruby_float_step(b, e, step, EXCL(range))) {
  349
+	/* done */
  350
+    }
346 351
     else if (rb_obj_is_kind_of(b, rb_cNumeric) ||
347 352
 	     !NIL_P(rb_check_to_integer(b, "to_int")) ||
348 353
 	     !NIL_P(rb_check_to_integer(e, "to_int"))) {
2  version.h
@@ -2,7 +2,7 @@
2 2
 #define RUBY_RELEASE_DATE "2009-02-22"
3 3
 #define RUBY_VERSION_CODE 187
4 4
 #define RUBY_RELEASE_CODE 20090222
5  
-#define RUBY_PATCHLEVEL 136
  5
+#define RUBY_PATCHLEVEL 137
6 6
 
7 7
 #define RUBY_VERSION_MAJOR 1
8 8
 #define RUBY_VERSION_MINOR 8

0 notes on commit 1dd6798

Please sign in to comment.
Something went wrong with that request. Please try again.