[#22503] can't require — IWATSUKI Hiroyuki <don@...>

岩月と申します。

94 messages 2004/01/06
[#22504] Re: can't require — nobu.nakada@... 2004/01/06

なかだです。

[#22505] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/06

まつもと ゆきひろです

[#22506] Re: can't require — IWATSUKI Hiroyuki <don@...> 2004/01/06

岩月と申します。

[#22509] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/07

山本です。

[#22513] Re: can't require — IWATSUKI Hiroyuki <don@...> 2004/01/07

岩月と申します。

[#22514] Re: can't require — nobu.nakada@... 2004/01/07

なかだです。

[#22522] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/07

山本です。

[#22524] Re: can't require — nobu.nakada@... 2004/01/07

なかだです。

[#22526] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/07

山本です。

[#22534] Re: can't require — nobu.nakada@... 2004/01/07

なかだです。

[#22535] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/07

まつもと ゆきひろです

[#22536] Re: can't require — Tanaka Akira <akr@...17n.org> 2004/01/07

In article <1073474004.933446.5475.nullmailer@picachu.netlab.jp>,

[#22540] Re: can't require — nobu.nakada@... 2004/01/07

なかだです。

[#22541] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/07

山本です。なかださんのコードで気になった点が3つあります。

[#22546] Re: can't require — nobu.nakada@... 2004/01/07

なかだです。

[#22549] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/08

山本です。

[#22550] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/08

山本です。

[#22551] Re: can't require — nobu.nakada@... 2004/01/08

なかだです。

[#22571] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/11

山本です。

[#22667] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/22

山本です。

[#22668] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/22

まつもと ゆきひろです

[#22669] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/22

山本です。

[#22676] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/24

山本です。

[#22677] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/25

まつもと ゆきひろです

[#22678] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/25

山本です。

[#22679] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/25

山本です。

[#22680] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/25

まつもと ゆきひろです

[#22682] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/25

山本です。

[#22683] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/25

まつもと ゆきひろです

[#22686] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/26

山本です。

[#22687] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/26

山本です。

[#22697] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/27

山本です。

[#22700] Re: can't require — nobu.nakada@... 2004/01/27

なかだです。

[#22712] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/27

山本です。WinCVS + byacc + sed をインストールして、ビルドできるようになりました。

[#22714] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/27

山本です。

[#22716] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/27

山本です。

[#22725] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22729] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/28

まつもと ゆきひろです

[#22734] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22736] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/28

まつもと ゆきひろです

[#22738] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22739] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22740] Dir.glob (Re: Re: can't require) — nobu.nakada@... 2004/01/28

なかだです。

[#22741] Re: Dir.glob (Re: Re: can't require) — matz@... (Yukihiro Matsumoto) 2004/01/28

まつもと ゆきひろです

[#22744] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22746] Re: Dir.glob (Re: Re: can't require) — nobu.nakada@... 2004/01/28

なかだです。

[#22747] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22748] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22750] Re: Dir.glob (Re: Re: can't require) — matz@... (Yukihiro Matsumoto) 2004/01/28

まつもと ゆきひろです

[#22761] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/29

山本です。

[#22764] Re: Dir.glob (Re: Re: can't require) — nobu.nakada@... 2004/01/29

なかだです。

[#22766] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/29

山本です。

[#22770] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/29

山本です。

[#22772] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/29

山本です。

[#22774] Re: Dir.glob (Re: Re: can't require) — matz@... (Yukihiro Matsumoto) 2004/01/29

まつもと ゆきひろです

[#22688] output directory for extensions — nobu.nakada@...

なかだです。

14 messages 2004/01/26

[#22691] 次期リリースでの新規添付ライブラリ — "Kawaji, Shinya" <kawaji@...>

かわじ、です

18 messages 2004/01/26
[#22693] Re: 次期リリースでの新規添付ライブラリ — matz@... (Yukihiro Matsumoto) 2004/01/26

まつもと ゆきひろです

[#22694] Re: 次期リリースでの新規添付ライブラリ — matz@... (Yukihiro Matsumoto) 2004/01/26

まつもと ゆきひろです

[#22763] $: trick in test/* — "NAKAMURA, Hiroshi" <nakahiro@...>

なひです。

21 messages 2004/01/29

[ruby-dev:22675] Re: Time#[+-] when given a negative argument

From: Tanaka Akira <akr@...17n.org>
Date: 2004-01-23 14:29:21 UTC
List: ruby-dev #22675
In article <200401210619.i0L6J6804314@cumail.chiba-u.jp>,
  siena@faculty.chiba-u.jp (Siena. / SHINAGAWA, Norihide) writes:

> double から time_t にして演算するのではなく、dounle で
> 演算してから結果を time_t に戻す方が簡単かもしれないと
> 思いましたが、time_t が 64bit の環境では仮数部の桁溢れに
> 注意しないとならないので、すっぱりとは行かないのですね。

ここは面倒ですよねぇ。

> はい。sign で場合分けしている点と、time_plus() と time_minus() で
> 原理的には同じコードが重複している点を指していました。
> リファクタリングすべきかなと思いながらも、やっつけ仕事で
> 済ましてしまったので。ちょっと気になっていたのでした。

ちょっとやってみまたところ、8行短くなりました。

ただ、書いていて疑問に思ったのですが、そちらの環境では usec まわりはちゃ
んと動いているんでしょうか?

たとえば、time_plus に
    usec = tobj->tv.tv_usec + (time_t)(d*1e6);
というコードがあります。これは Time.at(1.25) + (-0.5) とかやると d が
-0.5 になって、time_t という unsigned な型にキャストして変なことがおき
るんじゃないかと思うんですが。

他にも time_overflow_p の
    if (usec < 0) {             /* usec negative overflow */
とかは time_t が unsigned だと動く気がしません。

これに関連して聞きたいんですが、そちらの環境では struct timeval の
tv_usec の型は何でしょう?

ちなみに SUSv3 的には tv_usec は suseconds_t となっていて、これは
signed な整数型で [-1, 1000000] の範囲を表現できるとなっています。

Index: configure.in
===================================================================
RCS file: /src/ruby/configure.in,v
retrieving revision 1.221
diff -p -u -r1.221 configure.in
--- configure.in	21 Jan 2004 16:09:40 -0000	1.221
+++ configure.in	23 Jan 2004 13:57:02 -0000
@@ -205,6 +205,7 @@ AC_CHECK_SIZEOF(off_t, 0)
 AC_CHECK_SIZEOF(void*, 4)
 AC_CHECK_SIZEOF(float, 4)
 AC_CHECK_SIZEOF(double, 8)
+AC_CHECK_SIZEOF(time_t, 0)
 
 AC_CACHE_CHECK(for prototypes, rb_cv_have_prototypes,
   [AC_TRY_COMPILE([int foo(int x) { return 0; }], [return foo(10);],
Index: time.c
===================================================================
RCS file: /src/ruby/time.c,v
retrieving revision 1.95
diff -p -u -r1.95 time.c
--- time.c	18 Jan 2004 14:16:47 -0000	1.95
+++ time.c	23 Jan 2004 13:57:02 -0000
@@ -1168,6 +1168,57 @@ time_to_s(time)
     return rb_str_new(buf, len);
 }
 
+#if SIZEOF_TIME_T == SIZEOF_LONG
+typedef unsigned long unsigned_time_t;
+#elif SIZEOF_TIME_T == SIZEOF_LONG_LONG
+typedef unsigned long long unsigned_time_t;
+#else
+# error cannot find integer type which size is same as time_t.
+#endif
+
+static VALUE
+time_add(tobj, offset, sign)
+    struct time_object *tobj;
+    VALUE offset;
+    int sign;
+{
+    double v = NUM2DBL(offset);
+    double f, d;
+    unsigned_time_t sec_off;
+    time_t usec_off, sec, usec;
+    VALUE result;
+
+    if (v < 0) {
+        v = -v;
+        sign = -sign;
+    }
+    d = modf(v, &f);
+    sec_off = (unsigned_time_t)f;
+    if (f != (double)sec_off)
+        rb_raise(rb_eRangeError, "time %s %f out of Time range",
+            sign < 0 ? "-" : "+", v);
+    usec_off = (time_t)(d*1e6);
+
+    if (sign < 0) {
+        sec = tobj->tv.tv_sec - sec_off;
+        usec = tobj->tv.tv_usec - usec_off;
+        if (sec > tobj->tv.tv_sec)
+            rb_raise(rb_eRangeError, "time - %f out of Time range", v);
+    }
+    else {
+        sec = tobj->tv.tv_sec + sec_off;
+        usec = tobj->tv.tv_usec + usec_off;
+        if (sec < tobj->tv.tv_sec)
+            rb_raise(rb_eRangeError, "time + %f out of Time range", v);
+    }
+    result = rb_time_new(sec, usec);
+    if (tobj->gmt) {
+	GetTimeval(result, tobj);
+	tobj->gmt = 1;
+    }
+    return result;
+}
+
 /*
  *  call-seq:
  *     time + numeric => time
@@ -1184,42 +1235,12 @@ time_plus(time1, time2)
     VALUE time1, time2;
 {
     struct time_object *tobj;
-    time_t sec, usec;
-    double f, d, v;
-    int sign;
-
     GetTimeval(time1, tobj);
 
     if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) {
 	rb_raise(rb_eTypeError, "time + time?");
     }
-    v = NUM2DBL(time2);
-    d = modf(v, &f);
-    sign = (f < 0 ? -1 : 1);
-    f *= sign;
-    sec = (time_t)f;
-    if (f != (double)sec) {
-	rb_raise(rb_eRangeError, "time + %f out of Time range", v);
-    }
-#ifndef NEGATIVE_TIME_T
-    if (sign < 0 && f >= tobj->tv.tv_sec) {
-	rb_raise(rb_eArgError, "time must be positive");
-    }
-#endif
-    usec = tobj->tv.tv_usec + (time_t)(d*1e6);
-    sec = (sign > 0 ? tobj->tv.tv_sec + sec :  tobj->tv.tv_sec - sec);
-#ifdef NEGATIVE_TIME_T
-    if ((tobj->tv.tv_sec >= 0 && sign >= 0 && sec < 0) ||
-	(tobj->tv.tv_sec <= 0 && sign <= 0 && sec > 0)) {
-	rb_raise(rb_eRangeError, "time + %f out of Time range", v);
-    }
-#endif
-    time2 = rb_time_new(sec, usec);
-    if (tobj->gmt) {
-	GetTimeval(time2, tobj);
-	tobj->gmt = 1;
-    }
-    return time2;
+    return time_add(tobj, time2, 1);
 }
 
 /*
@@ -1242,13 +1263,11 @@ time_minus(time1, time2)
     VALUE time1, time2;
 {
     struct time_object *tobj;
-    time_t sec, usec;
-    double f, d, v;
-    int sign;
 
     GetTimeval(time1, tobj);
     if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) {
 	struct time_object *tobj2;
+        double f;
 
 	GetTimeval(time2, tobj2);
 	f = (double)tobj->tv.tv_sec - (double)tobj2->tv.tv_sec;
@@ -1257,34 +1276,7 @@ time_minus(time1, time2)
 
 	return rb_float_new(f);
     }
-    v = NUM2DBL(time2);
-    d = modf(v, &f);
-    sign = (f < 0 ? -1 : 1);
-    f *= sign;
-    sec = (time_t)f;
-    if (f != (double)sec) {
-	rb_raise(rb_eRangeError, "time - %f out of Time range", v);
-    }
-#ifndef NEGATIVE_TIME_T
-    if (sign > 0 && f >= tobj->tv.tv_sec) {
-	rb_raise(rb_eArgError, "time must be positive");
-    }
-#endif
-    usec = tobj->tv.tv_usec - (time_t)(d*1e6);
-    sec = (sign > 0 ? tobj->tv.tv_sec - sec :  tobj->tv.tv_sec + sec);
-#ifdef NEGATIVE_TIME_T
-    if ((tobj->tv.tv_sec <= 0 && sign >= 0 && sec > 0) ||
-	(tobj->tv.tv_sec >= 0 && sign <= 0 && sec < 0)) {
-	rb_raise(rb_eRangeError, "time - %f out of Time range", v);
-    }
-#endif
-
-    time2 = rb_time_new(sec, usec);
-    if (tobj->gmt) {
-	GetTimeval(time2, tobj);
-	tobj->gmt = 1;
-    }
-    return time2;
+    return time_add(tobj, time2, -1);
 }
 
 /*
-- 
[田中 哲][たなか あきら][Tanaka Akira]

In This Thread