[#23884] Ruby 1.8.2 preview1にむけて — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

34 messages 2004/07/13
[#23917] Re: Ruby 1.8.2 preview1にむけて — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/07/16

山本です。

[#23920] Re: Ruby 1.8.2 preview1にむけて — "NAKAMURA, Hiroshi" <nakahiro@...> 2004/07/16

なひです。

[#23922] ruby 1.8.2 preview1 — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

27 messages 2004/07/16

[#23995] String#each -> String#each_char — Shugo Maeda <shugo@...>

前田です。

27 messages 2004/07/30
[#23996] Re: String#each -> String#each_char — matz@... (Yukihiro Matsumoto) 2004/07/30

まつもと ゆきひろです

[#23997] Re: String#each -> String#each_char — "U.Nakamura" <usa@...> 2004/07/30

こんにちは、なかむら(う)です。

[#23999] Re: String#each -> String#each_char — matz@... (Yukihiro Matsumoto) 2004/07/30

まつもと ゆきひろです

[#24000] Re: String#each -> String#each_char — "U.Nakamura" <usa@...> 2004/07/30

こんにちは、なかむら(う)です。

[#24005] Re: String#each -> String#each_char — Minero Aoki <aamine@...> 2004/07/31

青木です。

[#24012] Re: String#each -> String#each_char — Shugo Maeda <shugo@...> 2004/08/01

前田です。

[#24014] Re: String#each -> String#each_char — Minero Aoki <aamine@...> 2004/08/02

青木です。

[ruby-dev:23879] Re: Are these comittable?

From: "H.Yamamoto" <ocean@...2.ccsnet.ne.jp>
Date: 2004-07-12 11:10:35 UTC
List: ruby-dev #23879
山本です。

>コミットは明日の正午を予定しています。問題がありましたら、よろしくお願いします。

strtod は "INF" じゃなくて "INFINITY" でも無限大として解釈するんですね _no
これで晴れて問題なくなりました。

少し自信がなくなったので、コミットは明日の深夜にします。

//////////////////////////////
// パッチ後

irb(main):004:0> a = 1.0 / 0.0
=> Infinity
irb(main):005:0> a.to_s.to_f
=> Infinity
irb(main):006:0> Float(a.to_s)
=> Infinity


Index: util.c
===================================================================
RCS file: /var/cvs/src/ruby/util.c,v
retrieving revision 1.43
diff -u -w -b -p -r1.43 util.c
--- util.c	14 May 2004 03:17:29 -0000	1.43
+++ util.c	12 Jul 2004 10:17:55 -0000
@@ -750,6 +750,7 @@ ruby_strtod(string, endPtr)
 				 * in string. */
     const char *pExp;		/* Temporarily holds location of exponent
 				 * in string. */
+    int frac1, frac2;
 
     /*
      * Strip off leading blanks and check for a sign.
@@ -772,6 +773,26 @@ ruby_strtod(string, endPtr)
     }
 
     /*
+     * Check for NaN and Inf.
+     */
+
+    if (strncasecmp(p, "NAN", 3) == 0) {
+	p += 3;
+	fraction = 0.0 / 0.0;
+	goto exit;
+    }
+    if (strncasecmp(p, "INFINITY", 8) == 0) {
+	p += 8;
+	fraction = 1.0 / 0.0;
+	goto exit;
+    }
+    if (strncasecmp(p, "INF", 3) == 0) {
+	p += 3;
+	fraction = 1.0 / 0.0;
+	goto exit;
+    }
+
+    /*
      * Count the number of digits in the mantissa
      * and also locate the decimal point.
      */
@@ -812,8 +833,7 @@ ruby_strtod(string, endPtr)
 	fracExp += (mantSize - 18);
 	mantSize = 18;
     }
-    {
-	int frac1, frac2;
+
 	frac1 = 0;
 	for ( ; mantSize > 9; mantSize -= 1) {
 	    c = *p;
@@ -920,12 +940,11 @@ ruby_strtod(string, endPtr)
 	else {
 	    fraction += frac2 * dblExp;
 	}
-    }
 
+  exit:
     if (endPtr != NULL) {
 	*endPtr = (char *) p;
     }
-
     if (sign) {
 	return -fraction;
     }


Index: test_float.rb
===================================================================
RCS file: /var/cvs/src/ruby/test/ruby/test_float.rb,v
retrieving revision 1.10
diff -u -w -b -p -r1.10 test_float.rb
--- test_float.rb	15 May 2004 08:54:23 -0000	1.10
+++ test_float.rb	12 Jul 2004 11:01:42 -0000
@@ -52,6 +52,25 @@ class TestFloat < Test::Unit::TestCase
     assert_equal(a == b, b == a)
   end
 
+  def strtod_nan(s)
+    a = Float(s)
+    assert(a.nan?)
+    a = Float("+" + s)
+    assert(a.nan?)
+    a = Float("-" + s)
+    assert(a.nan?)
+  end
+  def strtod_inf(s)
+    a = Float(s)
+    assert(a.infinite?)
+    assert(a > 0)
+    a = Float("+" + s)
+    assert(a.infinite?)
+    assert(a > 0)
+    a = Float("-" + s)
+    assert(a.infinite?)
+    assert(a < 0)
+  end
   def test_strtod
     a = Float("0")
     assert(a.abs < Float::EPSILON)
@@ -67,6 +86,15 @@ class TestFloat < Test::Unit::TestCase
     assert(a != 0.0)
     a = Float("-0." + "00" * Float::DIG + "1")
     assert(a != 0.0)
+    strtod_nan("NAN")
+    strtod_nan("NaN")
+    strtod_nan("nan")
+    strtod_inf("INF")
+    strtod_inf("Inf")
+    strtod_inf("inf")
+    strtod_inf("INFINITY")
+    strtod_inf("Infinity")
+    strtod_inf("infinity")
     # add expected behaviour here.
   end
 end



In This Thread