Changeset 31948 in webkit for trunk/JavaScriptCore/kjs/dtoa.cpp


Ignore:
Timestamp:
Apr 16, 2008, 11:41:54 AM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-04-16 Sam Weinig <[email protected]>

Reviewed by Darin Adler.

  • Remove kjs_ prefix from strtod, dtoa, and freedtoa and put it in the KJS namespace.
  • Make strtod, dtoa, and freedtoa c++ functions instead of extern "C".
  • Remove mode switching from dtoa. ~2% improvement on test 26.
  • Removes all unnecessary #defines from dtoa code.
  • JavaScriptCore.exp:
  • kjs/dtoa.cpp: (KJS::ulp): (KJS::b2d): (KJS::d2b): (KJS::ratio): (KJS::): (KJS::strtod): (KJS::freedtoa): (KJS::dtoa):
  • kjs/dtoa.h:
  • kjs/function.cpp: (KJS::parseInt):
  • kjs/lexer.cpp: (KJS::Lexer::lex):
  • kjs/number_object.cpp: (KJS::integer_part_noexp): (KJS::numberProtoFuncToExponential):
  • kjs/ustring.cpp: (KJS::UString::from): (KJS::UString::toDouble):

WebCore:

2008-04-16 Sam Weinig <[email protected]>

Reviewed by Darin Adler.

Rename kjs_strtod to KJS::strtod.

  • platform/text/String.cpp: (WebCore::charactersToDouble):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/dtoa.cpp

    r31561 r31948  
    3939 */
    4040
    41 /* strtod for IEEE-, VAX-, and IBM-arithmetic machines.
     41/* strtod for IEEE-arithmetic machines.
    4242 *
    4343 * This strtod returns a nearest machine number to the input decimal
     
    5151 * Modifications:
    5252 *
    53  *    1. We only require IEEE, IBM, or VAX double-precision
    54  *        arithmetic (not IEEE double-extended).
     53 *    1. We only require IEEE.
    5554 *    2. We get by with floating-point arithmetic in a case that
    5655 *        Clinger missed -- when we're computing d * 10^n
     
    7473 * #define IEEE_MC68k for IEEE-arithmetic machines where the most
    7574 *    significant byte has the lowest address.
    76  * #define IBM for IBM mainframe-style floating-point arithmetic.
    77  * #define VAX for VAX-style floating-point arithmetic (D_floating).
    7875 * #define No_leftright to omit left-right logic in fast floating-point
    7976 *    computation of dtoa.
    80  * #define Honor_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3
    81  *    and strtod and dtoa should round accordingly.
    8277 * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3
    8378 *    and Honor_FLT_ROUNDS is not #defined.
    84  * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines
    85  *    that use extended-precision instructions to compute rounded
    86  *    products and quotients) with IBM.
    87  * #define ROUND_BIASED for IEEE-format with biased rounding.
    8879 * #define Inaccurate_Divide for IEEE-format with correctly rounded
    8980 *    products but inaccurate quotients, e.g., for Intel i860.
     
    145136#include "dtoa.h"
    146137
     138#include <errno.h>
     139#include <float.h>
     140#include <math.h>
     141#include <stdint.h>
     142#include <stdlib.h>
     143#include <string.h>
     144#include <wtf/AlwaysInline.h>
     145#include <wtf/Assertions.h>
     146#include <wtf/FastMalloc.h>
     147#include <wtf/Threading.h>
     148
    147149#if COMPILER(MSVC)
    148150#pragma warning(disable: 4244)
     
    158160#define IEEE_8087
    159161#endif
     162
    160163#define INFNAN_CHECK
    161164
    162 
    163 
    164 #include <stdint.h>
    165 #include <stdlib.h>
    166 #include <string.h>
    167 #include <wtf/Assertions.h>
    168 #include <wtf/FastMalloc.h>
    169 #include <wtf/Threading.h>
    170 
    171 #undef IEEE_Arith
    172 #undef Avoid_Underflow
    173 #ifdef IEEE_MC68k
    174 #define IEEE_Arith
    175 #endif
    176 #ifdef IEEE_8087
    177 #define IEEE_Arith
    178 #endif
    179 #ifdef IEEE_ARM
    180 #define IEEE_Arith
    181 #endif
    182 
    183 #include <errno.h>
    184 
    185 #ifdef Bad_float_h
    186 
    187 #ifdef IEEE_Arith
    188 #define DBL_DIG 15
    189 #define DBL_MAX_10_EXP 308
    190 #define DBL_MAX_EXP 1024
    191 #define FLT_RADIX 2
    192 #endif /*IEEE_Arith*/
    193 
    194 #ifdef IBM
    195 #define DBL_DIG 16
    196 #define DBL_MAX_10_EXP 75
    197 #define DBL_MAX_EXP 63
    198 #define FLT_RADIX 16
    199 #define DBL_MAX 7.2370055773322621e+75
    200 #endif
    201 
    202 #ifdef VAX
    203 #define DBL_DIG 16
    204 #define DBL_MAX_10_EXP 38
    205 #define DBL_MAX_EXP 127
    206 #define FLT_RADIX 2
    207 #define DBL_MAX 1.7014118346046923e+38
    208 #endif
    209 
    210 #ifndef LONG_MAX
    211 #define LONG_MAX 2147483647
    212 #endif
    213 
    214 #else /* ifndef Bad_float_h */
    215 #include <float.h>
    216 #endif /* Bad_float_h */
    217 
    218 #ifndef __MATH_H__
    219 #include <math.h>
    220 #endif
    221 
    222 using namespace KJS;
     165#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(IEEE_ARM) != 1
     166Exactly one of IEEE_8087, IEEE_ARM or IEEE_MC68k should be defined.
     167#endif
     168
     169namespace KJS {
    223170
    224171#if USE(MULTIPLE_THREADS)
    225 Mutex* KJS::s_dtoaP5Mutex;
    226 #endif
    227 
    228 #ifdef __cplusplus
    229 extern "C" {
    230 #endif
    231 
    232 #if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(IEEE_ARM) + defined(VAX) + defined(IBM) != 1
    233 Exactly one of IEEE_8087, IEEE_ARM, IEEE_MC68k, VAX, or IBM should be defined.
     172Mutex* s_dtoaP5Mutex;
    234173#endif
    235174
     
    260199 * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
    261200 */
    262 #if defined(IEEE_8087) + defined(IEEE_ARM) + defined(VAX)
     201#if defined(IEEE_8087) || defined(IEEE_ARM)
    263202#define Storeinc(a,b,c) (((unsigned short*)a)[1] = (unsigned short)b, ((unsigned short*)a)[0] = (unsigned short)c, a++)
    264203#else
     
    266205#endif
    267206
    268 #ifdef IEEE_Arith
    269207#define Exp_shift  20
    270208#define Exp_shift1 20
     
    291229#define Quick_max 14
    292230#define Int_max 14
    293 #ifndef NO_IEEE_Scale
     231
     232#if !defined(NO_IEEE_Scale)
     233#undef Avoid_Underflow
    294234#define Avoid_Underflow
    295 #ifdef Flush_Denorm    /* debugging option */
    296 #undef Sudden_Underflow
    297 #endif
    298 #endif
    299 
    300 #ifndef Flt_Rounds
    301 #ifdef FLT_ROUNDS
     235#endif
     236
     237#if !defined(Flt_Rounds)
     238#if defined(FLT_ROUNDS)
    302239#define Flt_Rounds FLT_ROUNDS
    303240#else
     
    306243#endif /*Flt_Rounds*/
    307244
    308 #ifdef Honor_FLT_ROUNDS
    309 #define Rounding rounding
    310 #undef Check_FLT_ROUNDS
    311 #define Check_FLT_ROUNDS
    312 #else
    313 #define Rounding Flt_Rounds
    314 #endif
    315 
    316 #else /* ifndef IEEE_Arith */
    317 #undef Check_FLT_ROUNDS
    318 #undef Honor_FLT_ROUNDS
    319 #undef SET_INEXACT
    320 #undef  Sudden_Underflow
    321 #define Sudden_Underflow
    322 #ifdef IBM
    323 #undef Flt_Rounds
    324 #define Flt_Rounds 0
    325 #define Exp_shift  24
    326 #define Exp_shift1 24
    327 #define Exp_msk1   0x1000000
    328 #define Exp_msk11  0x1000000
    329 #define Exp_mask  0x7f000000
    330 #define P 14
    331 #define Bias 65
    332 #define Exp_1  0x41000000
    333 #define Exp_11 0x41000000
    334 #define Ebits 8    /* exponent has 7 bits, but 8 is the right value in b2d */
    335 #define Frac_mask  0xffffff
    336 #define Frac_mask1 0xffffff
    337 #define Bletch 4
    338 #define Ten_pmax 22
    339 #define Bndry_mask  0xefffff
    340 #define Bndry_mask1 0xffffff
    341 #define LSB 1
    342 #define Sign_bit 0x80000000
    343 #define Log2P 4
    344 #define Tiny0 0x100000
    345 #define Tiny1 0
    346 #define Quick_max 14
    347 #define Int_max 15
    348 #else /* VAX */
    349 #undef Flt_Rounds
    350 #define Flt_Rounds 1
    351 #define Exp_shift  23
    352 #define Exp_shift1 7
    353 #define Exp_msk1    0x80
    354 #define Exp_msk11   0x800000
    355 #define Exp_mask  0x7f80
    356 #define P 56
    357 #define Bias 129
    358 #define Exp_1  0x40800000
    359 #define Exp_11 0x4080
    360 #define Ebits 8
    361 #define Frac_mask  0x7fffff
    362 #define Frac_mask1 0xffff007f
    363 #define Ten_pmax 24
    364 #define Bletch 2
    365 #define Bndry_mask  0xffff007f
    366 #define Bndry_mask1 0xffff007f
    367 #define LSB 0x10000
    368 #define Sign_bit 0x8000
    369 #define Log2P 1
    370 #define Tiny0 0x80
    371 #define Tiny1 0
    372 #define Quick_max 15
    373 #define Int_max 15
    374 #endif /* IBM, VAX */
    375 #endif /* IEEE_Arith */
    376 
    377 #ifndef IEEE_Arith
    378 #define ROUND_BIASED
    379 #endif
    380 
    381 #ifdef RND_PRODQUOT
    382 #define rounded_product(a,b) a = rnd_prod(a, b)
    383 #define rounded_quotient(a,b) a = rnd_quot(a, b)
    384 extern double rnd_prod(double, double), rnd_quot(double, double);
    385 #else
     245
    386246#define rounded_product(a,b) a *= b
    387247#define rounded_quotient(a,b) a /= b
    388 #endif
    389248
    390249#define Big0 (Frac_mask1 | Exp_msk1 * (DBL_MAX_EXP + Bias - 1))
     
    921780#endif
    922781#endif
    923 #ifdef IBM
    924         L |= Exp_msk1 >> 4;
    925 #endif
    926782        word0(a) = L;
    927783        word1(a) = 0;
     
    953809    int k;
    954810    double d;
    955 #ifdef VAX
    956     uint32_t d0, d1;
    957 #else
     811
    958812#define d0 word0(d)
    959813#define d1 word1(d)
    960 #endif
    961814
    962815    xa0 = a->x;
     
    999852#endif
    1000853ret_d:
    1001 #ifdef VAX
    1002     word0(d) = d0 >> 16 | d0 << 16;
    1003     word1(d) = d1 >> 16 | d1 << 16;
    1004 #else
    1005854#undef d0
    1006855#undef d1
    1007 #endif
    1008856    return dval(d);
    1009857}
     
    1017865    int i;
    1018866#endif
    1019 #ifdef VAX
    1020     uint32_t d0, d1;
    1021     d0 = word0(d) >> 16 | word0(d) << 16;
    1022     d1 = word1(d) >> 16 | word1(d) << 16;
    1023 #else
    1024867#define d0 word0(d)
    1025868#define d1 word1(d)
    1026 #endif
    1027869
    1028870#ifdef Pack_32
     
    1037879#ifdef Sudden_Underflow
    1038880    de = (int)(d0 >> Exp_shift);
    1039 #ifndef IBM
    1040     z |= Exp_msk11;
    1041 #endif
    1042881#else
    1043882    if ((de = (int)(d0 >> Exp_shift)))
     
    1104943    if (de) {
    1105944#endif
    1106 #ifdef IBM
    1107         *e = (de - Bias - (P - 1) << 2) + k;
    1108         *bits = (4 * P) + 8 - k - hi0bits(word0(d) & Frac_mask);
    1109 #else
    1110945        *e = de - Bias - (P - 1) + k;
    1111946        *bits = P - k;
    1112 #endif
    1113947#ifndef Sudden_Underflow
    1114948    } else {
     
    1138972    k = ka - kb + 16 * (a->wds - b->wds);
    1139973#endif
    1140 #ifdef IBM
    1141     if (k > 0) {
    1142         word0(da) += (k >> 2) * Exp_msk1;
    1143         if (k &= 3)
    1144             dval(da) *= 1 << k;
    1145     } else {
    1146         k = -k;
    1147         word0(db) += (k >> 2) * Exp_msk1;
    1148         if (k &= 3)
    1149             dval(db) *= 1 << k;
    1150     }
    1151 #else
    1152974    if (k > 0)
    1153975        word0(da) += k * Exp_msk1;
     
    1156978        word0(db) += k * Exp_msk1;
    1157979    }
    1158 #endif
    1159980    return dval(da) / dval(db);
    1160981}
     
    1164985        1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
    1165986        1e20, 1e21, 1e22
    1166 #ifdef VAX
    1167         , 1e23, 1e24
    1168 #endif
    1169987};
    1170988
    1171 static const double
    1172 #ifdef IEEE_Arith
    1173     bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
     989static const double bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
    1174990static const double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128,
    1175991#ifdef Avoid_Underflow
     
    11851001#define Scale_Bit 0x10
    11861002#define n_bigtens 5
    1187 #else
    1188 #ifdef IBM
    1189     bigtens[] = { 1e16, 1e32, 1e64 };
    1190 static const double tinytens[] = { 1e-16, 1e-32, 1e-64 };
    1191 #define n_bigtens 3
    1192 #else
    1193     bigtens[] = { 1e16, 1e32 };
    1194 static const double tinytens[] = { 1e-16, 1e-32 };
    1195 #define n_bigtens 2
    1196 #endif
    1197 #endif
    1198 
    1199 #ifndef IEEE_Arith
    1200 #undef INFNAN_CHECK
    1201 #endif
    1202 
    1203 #ifdef INFNAN_CHECK
     1003
     1004#if defined(INFNAN_CHECK)
    12041005
    12051006#ifndef NAN_WORD0
     
    12731074#endif /* INFNAN_CHECK */
    12741075
    1275 double kjs_strtod(const char* s00, char** se)
     1076double strtod(const char* s00, char** se)
    12761077{
    12771078#ifdef Avoid_Underflow
     
    12871088#ifdef SET_INEXACT
    12881089    int inexact, oldinexact;
    1289 #endif
    1290 #ifdef Honor_FLT_ROUNDS
    1291     int rounding;
    12921090#endif
    12931091
     
    14511249    }
    14521250    bd0 = 0;
    1453     if (nd <= DBL_DIG
    1454 #ifndef RND_PRODQUOT
    1455 #ifndef Honor_FLT_ROUNDS
    1456         && Flt_Rounds == 1
    1457 #endif
    1458 #endif
    1459             ) {
     1251    if (nd <= DBL_DIG && Flt_Rounds == 1) {
    14601252        if (!e)
    14611253            goto ret;
    14621254        if (e > 0) {
    14631255            if (e <= Ten_pmax) {
    1464 #ifdef VAX
    1465                 goto vax_ovfl_check;
    1466 #else
    1467 #ifdef Honor_FLT_ROUNDS
    1468                 /* round correctly FLT_ROUNDS = 2 or 3 */
    1469                 if (sign) {
    1470                     rv = -rv;
    1471                     sign = 0;
    1472                 }
    1473 #endif
    14741256                /* rv = */ rounded_product(dval(rv), tens[e]);
    14751257                goto ret;
    1476 #endif
    14771258            }
    14781259            i = DBL_DIG - nd;
     
    14811262                 * this for larger i values.
    14821263                 */
    1483 #ifdef Honor_FLT_ROUNDS
    1484                 /* round correctly FLT_ROUNDS = 2 or 3 */
    1485                 if (sign) {
    1486                     rv = -rv;
    1487                     sign = 0;
    1488                 }
    1489 #endif
    14901264                e -= i;
    14911265                dval(rv) *= tens[i];
    1492 #ifdef VAX
    1493                 /* VAX exponent range is so narrow we must
    1494                  * worry about overflow here...
    1495                  */
    1496 vax_ovfl_check:
    1497                 word0(rv) -= P * Exp_msk1;
    14981266                /* rv = */ rounded_product(dval(rv), tens[e]);
    1499                 if ((word0(rv) & Exp_mask) > Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P))
    1500                     goto ovfl;
    1501                 word0(rv) += P * Exp_msk1;
    1502 #else
    1503                 /* rv = */ rounded_product(dval(rv), tens[e]);
    1504 #endif
    15051267                goto ret;
    15061268            }
     
    15081270#ifndef Inaccurate_Divide
    15091271        else if (e >= -Ten_pmax) {
    1510 #ifdef Honor_FLT_ROUNDS
    1511             /* round correctly FLT_ROUNDS = 2 or 3 */
    1512             if (sign) {
    1513                 rv = -rv;
    1514                 sign = 0;
    1515             }
    1516 #endif
    15171272            /* rv = */ rounded_quotient(dval(rv), tens[-e]);
    15181273            goto ret;
     
    15221277    e1 += nd - k;
    15231278
    1524 #ifdef IEEE_Arith
    15251279#ifdef SET_INEXACT
    15261280    inexact = 1;
     
    15311285    scale = 0;
    15321286#endif
    1533 #ifdef Honor_FLT_ROUNDS
    1534     if ((rounding = Flt_Rounds) >= 2) {
    1535         if (sign)
    1536             rounding = rounding == 2 ? 0 : 2;
    1537         else
    1538             if (rounding != 2)
    1539                 rounding = 0;
    1540         }
    1541 #endif
    1542 #endif /*IEEE_Arith*/
    15431287
    15441288    /* Get starting approximation = rv * 10**e1 */
     
    15541298#endif
    15551299                /* Can't trust HUGE_VAL */
    1556 #ifdef IEEE_Arith
    1557 #ifdef Honor_FLT_ROUNDS
    1558                 switch (rounding) {
    1559                     case 0: /* toward 0 */
    1560                     case 3: /* toward -infinity */
    1561                         word0(rv) = Big0;
    1562                         word1(rv) = Big1;
    1563                         break;
    1564                     default:
    1565                         word0(rv) = Exp_mask;
    1566                         word1(rv) = 0;
    1567                   }
    1568 #else /*Honor_FLT_ROUNDS*/
    15691300                word0(rv) = Exp_mask;
    15701301                word1(rv) = 0;
    1571 #endif /*Honor_FLT_ROUNDS*/
    15721302#ifdef SET_INEXACT
    15731303                /* set overflow bit */
     
    15751305                dval(rv0) *= dval(rv0);
    15761306#endif
    1577 #else /*IEEE_Arith*/
    1578                 word0(rv) = Big0;
    1579                 word1(rv) = Big1;
    1580 #endif /*IEEE_Arith*/
    15811307                if (bd0)
    15821308                    goto retfree;
     
    16801406            bd2 -= bbe;
    16811407        bs2 = bb2;
    1682 #ifdef Honor_FLT_ROUNDS
    1683         if (rounding != 1)
    1684             bs2++;
    1685 #endif
    16861408#ifdef Avoid_Underflow
    16871409        j = bbe - scale;
     
    16931415#else /*Avoid_Underflow*/
    16941416#ifdef Sudden_Underflow
    1695 #ifdef IBM
    1696         j = 1 + (4 * P) - 3 - bbbits + ((bbe + bbbits - 1) & 3);
    1697 #else
    16981417        j = P + 1 - bbbits;
    1699 #endif
    17001418#else /*Sudden_Underflow*/
    17011419        j = bbe;
     
    17381456        delta->sign = 0;
    17391457        i = cmp(delta, bs);
    1740 #ifdef Honor_FLT_ROUNDS
    1741         if (rounding != 1) {
    1742             if (i < 0) {
    1743                 /* Error is less than an ulp */
    1744                 if (!delta->x[0] && delta->wds <= 1) {
    1745                     /* exact */
    1746 #ifdef SET_INEXACT
    1747                     inexact = 0;
    1748 #endif
    1749                     break;
    1750                 }
    1751                 if (rounding) {
    1752                     if (dsign) {
    1753                         adj = 1.;
    1754                         goto apply_adj;
    1755                         }
    1756                 } else if (!dsign) {
    1757                     adj = -1.;
    1758                     if (!word1(rv) && !(word0(rv) & Frac_mask)) {
    1759                         y = word0(rv) & Exp_mask;
    1760 #ifdef Avoid_Underflow
    1761                         if (!scale || y > 2 * P * Exp_msk1)
    1762 #else
    1763                         if (y)
    1764 #endif
    1765                         {
    1766                             delta = lshift(delta, Log2P);
    1767                             if (cmp(delta, bs) <= 0)
    1768                                 adj = -0.5;
    1769                         }
    1770                     }
    1771 apply_adj:
    1772 #ifdef Avoid_Underflow
    1773                     if (scale && (y = word0(rv) & Exp_mask) <= 2 * P * Exp_msk1)
    1774                       word0(adj) += (2 * P + 1) * Exp_msk1 - y;
    1775 #else
    1776 #ifdef Sudden_Underflow
    1777                     if ((word0(rv) & Exp_mask) <= P * Exp_msk1) {
    1778                         word0(rv) += P * Exp_msk1;
    1779                         dval(rv) += adj * ulp(dval(rv));
    1780                         word0(rv) -= P * Exp_msk1;
    1781                     } else
    1782 #endif /*Sudden_Underflow*/
    1783 #endif /*Avoid_Underflow*/
    1784                     dval(rv) += adj * ulp(dval(rv));
    1785                 }
    1786                 break;
    1787             }
    1788             adj = ratio(delta, bs);
    1789             if (adj < 1.)
    1790                 adj = 1.;
    1791             if (adj <= 0x7ffffffe) {
    1792                 y = adj;
    1793                 if (y != adj) {
    1794                     if (!((rounding >> 1) ^ dsign))
    1795                         y++;
    1796                     adj = y;
    1797                 }
    1798             }
    1799 #ifdef Avoid_Underflow
    1800             if (scale && (y = word0(rv) & Exp_mask) <= 2 * P * Exp_msk1)
    1801                 word0(adj) += (2 * P + 1) * Exp_msk1 - y;
    1802 #else
    1803 #ifdef Sudden_Underflow
    1804             if ((word0(rv) & Exp_mask) <= P * Exp_msk1) {
    1805                 word0(rv) += P * Exp_msk1;
    1806                 adj *= ulp(dval(rv));
    1807                 if (dsign)
    1808                     dval(rv) += adj;
    1809                 else
    1810                     dval(rv) -= adj;
    1811                 word0(rv) -= P * Exp_msk1;
    1812                 goto cont;
    1813             }
    1814 #endif /*Sudden_Underflow*/
    1815 #endif /*Avoid_Underflow*/
    1816             adj *= ulp(dval(rv));
    1817             if (dsign)
    1818                 dval(rv) += adj;
    1819             else
    1820                 dval(rv) -= adj;
    1821             goto cont;
    1822         }
    1823 #endif /*Honor_FLT_ROUNDS*/
    18241458
    18251459        if (i < 0) {
     
    18281462             */
    18291463            if (dsign || word1(rv) || word0(rv) & Bndry_mask
    1830 #ifdef IEEE_Arith
    18311464#ifdef Avoid_Underflow
    18321465             || (word0(rv) & Exp_mask) <= (2 * P + 1) * Exp_msk1
    18331466#else
    18341467             || (word0(rv) & Exp_mask) <= Exp_msk1
    1835 #endif
    18361468#endif
    18371469                ) {
     
    18651497                           0xffffffff)) {
    18661498                    /*boundary case -- increment exponent*/
    1867                     word0(rv) = (word0(rv) & Exp_mask)
    1868                         + Exp_msk1
    1869 #ifdef IBM
    1870                         | Exp_msk1 >> 4
    1871 #endif
    1872                         ;
     1499                    word0(rv) = (word0(rv) & Exp_mask) + Exp_msk1;
    18731500                    word1(rv) = 0;
    18741501#ifdef Avoid_Underflow
     
    18821509#ifdef Sudden_Underflow /*{{*/
    18831510                L = word0(rv) & Exp_mask;
    1884 #ifdef IBM
    1885                 if (L <  Exp_msk1)
    1886 #else
    18871511#ifdef Avoid_Underflow
    18881512                if (L <= (scale ? (2 * P + 1) * Exp_msk1 : Exp_msk1))
     
    18901514                if (L <= Exp_msk1)
    18911515#endif /*Avoid_Underflow*/
    1892 #endif /*IBM*/
    18931516                    goto undfl;
    18941517                L -= Exp_msk1;
     
    19111534                word0(rv) = L | Bndry_mask1;
    19121535                word1(rv) = 0xffffffff;
    1913 #ifdef IBM
    1914                 goto cont;
    1915 #else
    19161536                break;
    1917 #endif
    1918             }
    1919 #ifndef ROUND_BIASED
     1537            }
    19201538            if (!(word1(rv) & LSB))
    19211539                break;
    1922 #endif
    19231540            if (dsign)
    19241541                dval(rv) += ulp(dval(rv));
    1925 #ifndef ROUND_BIASED
    19261542            else {
    19271543                dval(rv) -= ulp(dval(rv));
     
    19331549#ifdef Avoid_Underflow
    19341550            dsign = 1 - dsign;
    1935 #endif
    19361551#endif
    19371552            break;
     
    20111626                adj = aadj1 * ulp(dval(rv));
    20121627                dval(rv) += adj;
    2013 #ifdef IBM
    2014                 if ((word0(rv) & Exp_mask) <  P * Exp_msk1)
    2015 #else
    20161628                if ((word0(rv) & Exp_mask) <= P * Exp_msk1)
    2017 #endif
    20181629                {
    20191630                    if (word0(rv0) == Tiny0 && word1(rv0) == Tiny1)
     
    22551866 */
    22561867
    2257 void kjs_freedtoa(char* s)
     1868void freedtoa(char* s)
    22581869{
    22591870    Bigint* b = (Bigint*)((int*)s - 1);
     
    23001911 */
    23011912
    2302 char* kjs_dtoa(double d, int mode, int ndigits, int* decpt, int* sign, char** rve)
     1913char* dtoa(double d, int ndigits, int* decpt, int* sign, char** rve)
    23031914{
    2304  /*    Arguments ndigits, decpt, sign are similar to those
     1915    /*
     1916        Arguments ndigits, decpt, sign are similar to those
    23051917    of ecvt and fcvt; trailing zeros are suppressed from
    23061918    the returned string.  If not null, *rve is set to point
     
    23081920    then *decpt is set to 9999.
    23091921
    2310     mode:
    2311         0 ==> shortest string that yields d when read in
    2312             and rounded to nearest.
    2313         1 ==> like 0, but with Steele & White stopping rule;
    2314             e.g. with IEEE P754 arithmetic , mode 0 gives
    2315             1e23 whereas mode 1 gives 9.999999999999999e22.
    2316         2 ==> max(1,ndigits) significant digits.  This gives a
    2317             return value similar to that of ecvt, except
    2318             that trailing zeros are suppressed.
    2319         3 ==> through ndigits past the decimal point.  This
    2320             gives a return value similar to that from fcvt,
    2321             except that trailing zeros are suppressed, and
    2322             ndigits can be negative.
    2323         4,5 ==> similar to 2 and 3, respectively, but (in
    2324             round-nearest mode) with the tests of mode 0 to
    2325             possibly return a shorter string that rounds to d.
    2326             With IEEE arithmetic and compilation with
    2327             -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same
    2328             as modes 2 and 3 when FLT_ROUNDS != 1.
    2329         6-9 ==> Debugging modes similar to mode - 4:  don't try
    2330             fast floating-point estimate (if applicable).
    2331 
    2332         Values of mode other than 0-9 are treated as mode 0.
    2333 
    2334         Sufficient space is allocated to the return value
    2335         to hold the suppressed trailing zeros.
    23361922    */
    23371923
     
    23471933    double d2, ds, eps;
    23481934    char *s, *s0;
    2349 #ifdef Honor_FLT_ROUNDS
    2350     int rounding;
    2351 #endif
    23521935#ifdef SET_INEXACT
    23531936    int inexact, oldinexact;
     
    23561939#if !USE(MULTIPLE_THREADS)
    23571940    if (dtoa_result) {
    2358         kjs_freedtoa(dtoa_result);
     1941        freedtoa(dtoa_result);
    23591942        dtoa_result = 0;
    23601943    }
     
    23681951        *sign = 0;
    23691952
    2370 #if defined(IEEE_Arith) + defined(VAX)
    2371 #ifdef IEEE_Arith
    23721953    if ((word0(d) & Exp_mask) == Exp_mask)
    2373 #else
    2374     if (word0(d)  == 0x8000)
    2375 #endif
    23761954    {
    23771955        /* Infinity or NaN */
    23781956        *decpt = 9999;
    2379 #ifdef IEEE_Arith
    23801957        if (!word1(d) && !(word0(d) & 0xfffff))
    23811958            return nrv_alloc("Infinity", rve, 8);
    2382 #endif
    23831959        return nrv_alloc("NaN", rve, 3);
    23841960    }
    2385 #endif
    2386 #ifdef IBM
    2387     dval(d) += 0; /* normalize */
    2388 #endif
    23891961    if (!dval(d)) {
    23901962        *decpt = 1;
     
    23961968    inexact = 1;
    23971969#endif
    2398 #ifdef Honor_FLT_ROUNDS
    2399     if ((rounding = Flt_Rounds) >= 2) {
    2400         if (*sign)
    2401             rounding = rounding == 2 ? 0 : 2;
    2402         else if (rounding != 2)
    2403             rounding = 0;
    2404     }
    2405 #endif
    24061970
    24071971    b = d2b(dval(d), &be, &bbits);
     
    24141978        word0(d2) &= Frac_mask1;
    24151979        word0(d2) |= Exp_11;
    2416 #ifdef IBM
    2417         if (j = 11 - hi0bits(word0(d2) & Frac_mask))
    2418             dval(d2) /= 1 << j;
    2419 #endif
    24201980
    24211981        /* log(x)    ~=~ log(1.5) + (x-1.5)/1.5
     
    24422002
    24432003        i -= Bias;
    2444 #ifdef IBM
    2445         i <<= 2;
    2446         i += j;
    2447 #endif
    24482004#ifndef Sudden_Underflow
    24492005        denorm = 0;
     
    24872043        s5 = 0;
    24882044    }
    2489     if (mode < 0 || mode > 9)
    2490         mode = 0;
    24912045
    24922046#ifndef SET_INEXACT
     
    24982052#endif /*SET_INEXACT*/
    24992053
    2500     if (mode > 5) {
    2501         mode -= 4;
    2502         try_quick = 0;
    2503     }
    25042054    leftright = 1;
    2505     switch (mode) {
    2506         case 0:
    2507         case 1:
    2508             ilim = ilim1 = -1;
    2509             i = 18;
    2510             ndigits = 0;
    2511             break;
    2512         case 2:
    2513             leftright = 0;
    2514             /* no break */
    2515         case 4:
    2516             if (ndigits <= 0)
    2517                 ndigits = 1;
    2518             ilim = ilim1 = i = ndigits;
    2519             break;
    2520         case 3:
    2521             leftright = 0;
    2522             /* no break */
    2523         case 5:
    2524             i = ndigits + k + 1;
    2525             ilim = i;
    2526             ilim1 = i - 1;
    2527             if (i <= 0)
    2528                 i = 1;
    2529     }
     2055    ilim = ilim1 = -1;
     2056    i = 18;
     2057    ndigits = 0;
    25302058    s = s0 = rv_alloc(i);
    2531 
    2532 #ifdef Honor_FLT_ROUNDS
    2533     if (mode > 1 && rounding != 1)
    2534         leftright = 0;
    2535 #endif
    25362059
    25372060    if (ilim >= 0 && ilim <= Quick_max && try_quick) {
     
    26662189            }
    26672190            if (i == ilim) {
    2668 #ifdef Honor_FLT_ROUNDS
    2669                 if (mode > 1) {
    2670                     switch (rounding) {
    2671                         case 0:
    2672                             goto ret1;
    2673                         case 2:
    2674                             goto bump_up;
    2675                     }
    2676                 }
    2677 #endif
    26782191                dval(d) += dval(d);
    26792192                if (dval(d) > ds || dval(d) == ds && L & 1) {
     
    27012214            denorm ? be + (Bias + (P - 1) - 1 + 1) :
    27022215#endif
    2703 #ifdef IBM
    2704             1 + (4 * P) - 3 - bbits + ((bbits + be - 1) & 3);
    2705 #else
    27062216            1 + P - bbits;
    2707 #endif
    27082217        b2 += i;
    27092218        s2 += i;
     
    27362245
    27372246    spec_case = 0;
    2738     if ((mode < 2 || leftright)
    2739 #ifdef Honor_FLT_ROUNDS
    2740             && rounding == 1
    2741 #endif
    2742                 ) {
    2743         if (!word1(d) && !(word0(d) & Bndry_mask)
     2247    if (!word1(d) && !(word0(d) & Bndry_mask)
    27442248#ifndef Sudden_Underflow
    2745          && word0(d) & (Exp_mask & ~Exp_msk1)
    2746 #endif
    2747                 ) {
    2748             /* The special case */
    2749             b2 += Log2P;
    2750             s2 += Log2P;
    2751             spec_case = 1;
    2752         }
     2249     && word0(d) & (Exp_mask & ~Exp_msk1)
     2250#endif
     2251            ) {
     2252        /* The special case */
     2253        b2 += Log2P;
     2254        s2 += Log2P;
     2255        spec_case = 1;
    27532256    }
    27542257
     
    27912294        }
    27922295    }
    2793     if (ilim <= 0 && (mode == 3 || mode == 5)) {
    2794         if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
    2795             /* no digits, fcvt style */
    2796 no_digits:
    2797             k = -1 - ndigits;
    2798             goto ret;
    2799         }
    2800 one_digit:
    2801         *s++ = '1';
    2802         k++;
    2803         goto ret;
    2804     }
     2296
    28052297    if (leftright) {
    28062298        if (m2 > 0)
     
    28272319            j1 = delta->sign ? 1 : cmp(b, delta);
    28282320            Bfree(delta);
    2829 #ifndef ROUND_BIASED
    2830             if (j1 == 0 && mode != 1 && !(word1(d) & 1)
    2831 #ifdef Honor_FLT_ROUNDS
    2832                 && rounding >= 1
    2833 #endif
    2834                                    ) {
     2321            if (j1 == 0 && !(word1(d) & 1)) {
    28352322                if (dig == '9')
    28362323                    goto round_9_up;
     
    28442331                goto ret;
    28452332            }
    2846 #endif
    2847             if (j < 0 || j == 0 && mode != 1
    2848 #ifndef ROUND_BIASED
    2849                             && !(word1(d) & 1)
    2850 #endif
    2851                     ) {
     2333            if (j < 0 || j == 0 && !(word1(d) & 1)) {
    28522334                if (!b->x[0] && b->wds <= 1) {
    28532335#ifdef SET_INEXACT
     
    28562338                    goto accept_dig;
    28572339                }
    2858 #ifdef Honor_FLT_ROUNDS
    2859                 if (mode > 1) {
    2860                     switch (rounding) {
    2861                         case 0:
    2862                             goto accept_dig;
    2863                         case 2:
    2864                             goto keep_dig;
    2865                     }
    2866                 }
    2867 #endif /*Honor_FLT_ROUNDS*/
    28682340                if (j1 > 0) {
    28692341                    b = lshift(b, 1);
     
    28772349            }
    28782350            if (j1 > 0) {
    2879 #ifdef Honor_FLT_ROUNDS
    2880                 if (!rounding)
    2881                     goto accept_dig;
    2882 #endif
    28832351                if (dig == '9') { /* possible if i == 1 */
    28842352round_9_up:
     
    28892357                goto ret;
    28902358            }
    2891 #ifdef Honor_FLT_ROUNDS
    2892 keep_dig:
    2893 #endif
    28942359            *s++ = dig;
    28952360            if (i == ilim)
     
    29192384    /* Round off last digit */
    29202385
    2921 #ifdef Honor_FLT_ROUNDS
    2922     switch (rounding) {
    2923         case 0:
    2924             goto trimzeros;
    2925         case 2:
    2926             goto roundoff;
    2927       }
    2928 #endif
    29292386    b = lshift(b, 1);
    29302387    j = cmp(b, S);
     
    29392396        ++*s++;
    29402397    } else {
    2941 #ifdef Honor_FLT_ROUNDS
    2942 trimzeros:
    2943 #endif
    29442398        while (*--s == '0') { }
    29452399        s++;
    29462400    }
     2401    goto ret;
     2402no_digits:
     2403    k = -1 - ndigits;
     2404    goto ret;
     2405one_digit:
     2406    *s++ = '1';
     2407    k++;
     2408    goto ret;
    29472409ret:
    29482410    Bfree(S);
     
    29712433}
    29722434
    2973 #ifdef __cplusplus
    2974 }
    2975 #endif
     2435} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.