From 3a4c2bc034a4205ac7116c69ee39de02defb6d17 Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 1 Apr 2010 05:09:10 +0000 Subject: [PATCH] * util.c (BSD__hdtoa): don't use C99 macros. (FP_NORMAL etc) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ util.c | 37 ++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 21d237beb2..3c5441b1bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Apr 1 14:07:51 2010 NARUSE, Yui + + * util.c (BSD__hdtoa): don't use C99 macros. (FP_NORMAL etc) + Thu Apr 1 13:30:12 2010 NARUSE, Yui * sprintf.c (rb_str_format): support %a format. [ruby-dev:40650] diff --git a/util.c b/util.c index 88914be410..838f2e5c8f 100644 --- a/util.c +++ b/util.c @@ -3937,26 +3937,25 @@ BSD__hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign, else *sign = 0; - switch (fpclassify(d)) { - case FP_NORMAL: - *decpt = dexp_get(u) - DBL_ADJ; - break; - case FP_ZERO: - *decpt = 1; - return (nrv_alloc("0", rve, 1)); - case FP_SUBNORMAL: - u.d *= 5.363123171977039e+154 /* 0x1p514 */; - *decpt = dexp_get(u) - (514 + DBL_ADJ); - break; - case FP_INFINITE: - *decpt = INT_MAX; - return (nrv_alloc(INFSTR, rve, sizeof(INFSTR) - 1)); - default: /* FP_NAN or unrecognized */ - *decpt = INT_MAX; - return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1)); + if (isinf(d)) { /* FP_INFINITE */ + *decpt = INT_MAX; + return (nrv_alloc(INFSTR, rve, sizeof(INFSTR) - 1)); + } + else if (isnan(d)) { /* FP_NAN */ + *decpt = INT_MAX; + return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1)); + } + else if (d == 0.0) { /* FP_ZERO */ + *decpt = 1; + return (nrv_alloc("0", rve, 1)); + } + else if (dexp_get(u)) { /* FP_NORMAL */ + *decpt = dexp_get(u) - DBL_ADJ; + } + else { /* FP_SUBNORMAL */ + u.d *= 5.363123171977039e+154 /* 0x1p514 */; + *decpt = dexp_get(u) - (514 + DBL_ADJ); } - - /* FP_NORMAL or FP_SUBNORMAL */ if (ndigits == 0) /* dtoa() compatibility */ ndigits = 1;