зеркало из https://github.com/github/ruby.git
* time.c (time_timespec): rounds subsecond toward zero.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
400d826393
Коммит
796fc30f84
|
@ -1,3 +1,7 @@
|
||||||
|
Mon Jul 13 01:18:13 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* time.c (time_timespec): rounds subsecond toward zero.
|
||||||
|
|
||||||
Sun Jul 12 23:51:39 2009 NARUSE, Yui <naruse@ruby-lang.org>
|
Sun Jul 12 23:51:39 2009 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* hash.c (env_str_new): use rb_locale_str_new instead of
|
* hash.c (env_str_new): use rb_locale_str_new instead of
|
||||||
|
|
19
time.c
19
time.c
|
@ -1499,22 +1499,17 @@ time_timespec(VALUE num, int interval)
|
||||||
double f, d;
|
double f, d;
|
||||||
|
|
||||||
d = modf(RFLOAT_VALUE(num), &f);
|
d = modf(RFLOAT_VALUE(num), &f);
|
||||||
if (d < 0) {
|
if (d >= 0) {
|
||||||
d += 1;
|
t.tv_nsec = (int)(d*1e9+0.5);
|
||||||
f -= 1;
|
}
|
||||||
}
|
else if ((t.tv_nsec = (int)(-d*1e9+0.5)) > 0) {
|
||||||
|
t.tv_nsec = 1000000000 - t.tv_nsec;
|
||||||
|
f -= 1;
|
||||||
|
}
|
||||||
t.tv_sec = (time_t)f;
|
t.tv_sec = (time_t)f;
|
||||||
if (f != t.tv_sec) {
|
if (f != t.tv_sec) {
|
||||||
rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT_VALUE(num));
|
rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT_VALUE(num));
|
||||||
}
|
}
|
||||||
t.tv_nsec = (int)(d*1e9+0.5);
|
|
||||||
if (t.tv_nsec >= 1000000000) {
|
|
||||||
t.tv_nsec -= 1000000000;
|
|
||||||
if (++t.tv_sec <= 0) {
|
|
||||||
--t.tv_nsec;
|
|
||||||
t.tv_nsec = 999999999;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче