From 28c53aabcad4ec41916ad5e72203022769ab73f5 Mon Sep 17 00:00:00 2001 From: tadf Date: Wed, 3 Dec 2008 16:28:17 +0000 Subject: [PATCH] * complex.c (f_signbit): NaN may be signed value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ complex.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f28004925..4b04058ec6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Dec 4 01:22:41 2008 Tadayoshi Funaba + + * complex.c (f_signbit): NaN may be signed value. + Wed Dec 3 23:59:32 2008 Tanaka Akira * process.c (EXEC_OPTION_DUP2_CHILD): defined. diff --git a/complex.c b/complex.c index 95a278e3ac..4230af22d6 100644 --- a/complex.c +++ b/complex.c @@ -887,15 +887,17 @@ f_signbit(VALUE x) switch (TYPE(x)) { case T_FLOAT: #ifdef HAVE_SIGNBIT - return f_boolcast(signbit(RFLOAT_VALUE(x))); + { + double f = RFLOAT_VALUE(x); + return f_boolcast(!isnan(f) && signbit(f)); + } #else - { - char s[2]; + { + char s[2]; - (void)snprintf(s, sizeof s, "%.0f", RFLOAT_VALUE(x)); - - return f_boolcast(s[0] == '-'); - } + (void)snprintf(s, sizeof s, "%.0f", RFLOAT_VALUE(x)); + return f_boolcast(s[0] == '-'); + } #endif } return f_negative_p(x);