mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* numeric.c (flodivmod): work around for inifinity.
* numeric.c (flo_divmod): work around for platforms have no round(). [ruby-dev:32247] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9829e14432
commit
b7d363ead6
3 changed files with 19 additions and 2 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Tue Nov 13 16:33:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* numeric.c (flodivmod): work around for inifinity.
|
||||||
|
|
||||||
|
* numeric.c (flo_divmod): work around for platforms have no round().
|
||||||
|
[ruby-dev:32247]
|
||||||
|
|
||||||
Tue Nov 13 15:26:33 2007 Tanaka Akira <akr@fsij.org>
|
Tue Nov 13 15:26:33 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* lex.c.blt: moved from lex.c.
|
* lex.c.blt: moved from lex.c.
|
||||||
|
|
|
@ -598,7 +598,7 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall chroot fsync getcwd
|
||||||
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
|
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
|
||||||
getpriority getrlimit setrlimit sysconf group_member\
|
getpriority getrlimit setrlimit sysconf group_member\
|
||||||
dlopen sigprocmask sigaction _setjmp vsnprintf snprintf\
|
dlopen sigprocmask sigaction _setjmp vsnprintf snprintf\
|
||||||
setsid telldir seekdir fchmod mktime timegm cosh sinh tanh log2\
|
setsid telldir seekdir fchmod mktime timegm cosh sinh tanh log2 round\
|
||||||
setuid setgid daemon select_large_fdset setenv unsetenv)
|
setuid setgid daemon select_large_fdset setenv unsetenv)
|
||||||
AC_ARG_ENABLE(setreuid,
|
AC_ARG_ENABLE(setreuid,
|
||||||
[ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.],
|
[ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.],
|
||||||
|
|
12
numeric.c
12
numeric.c
|
@ -644,7 +644,10 @@ flodivmod(double x, double y, double *divp, double *modp)
|
||||||
mod = x - z * y;
|
mod = x - z * y;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
div = (x - mod) / y;
|
if (isinf(x) && !isinf(y) && !isnan(y))
|
||||||
|
div = x;
|
||||||
|
else
|
||||||
|
div = (x - mod) / y;
|
||||||
if (y*mod < 0) {
|
if (y*mod < 0) {
|
||||||
mod += y;
|
mod += y;
|
||||||
div -= 1.0;
|
div -= 1.0;
|
||||||
|
@ -715,9 +718,16 @@ flo_divmod(VALUE x, VALUE y)
|
||||||
}
|
}
|
||||||
flodivmod(RFLOAT(x)->value, fy, &div, &mod);
|
flodivmod(RFLOAT(x)->value, fy, &div, &mod);
|
||||||
if (FIXABLE(div)) {
|
if (FIXABLE(div)) {
|
||||||
|
#ifdef HVAE_ROUND
|
||||||
val = round(div);
|
val = round(div);
|
||||||
|
#else
|
||||||
|
val = (div < 0) ? ceil(x - 0.5) : floor(x + 0.5);
|
||||||
|
#endif
|
||||||
a = LONG2FIX(val);
|
a = LONG2FIX(val);
|
||||||
}
|
}
|
||||||
|
else if (isnan(div) || isinf(div)) {
|
||||||
|
a = rb_float_new(div);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
a = rb_dbl2big(div);
|
a = rb_dbl2big(div);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue