~ubuntu-branches/ubuntu/saucy/nspr/saucy-updates

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/src/misc/prdtoa.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-06-16 11:28:24 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090616112824-cg6qzhvt63lx7bub
Tags: 4.7.5-0ubuntu1
* New upstream version: 4.7.5 (LP: #387745)

* adjust patches to changed upstream code base
  - update debian/patches/99_configure.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
217
217
 *      floating-point numbers and flushes underflows to zero rather
218
218
 *      than implementing gradual underflow, then you must also #define
219
219
 *      Sudden_Underflow.
220
 
 * #define YES_ALIAS to permit aliasing certain double values with
221
 
 *      arrays of ULongs.  This leads to slightly better code with
222
 
 *      some compilers and was always used prior to 19990916, but it
223
 
 *      is not strictly legal and can cause trouble with aggressively
224
 
 *      optimizing compilers (e.g., gcc 2.95.1 under -O2).
225
220
 * #define USE_LOCALE to use the current locale's decimal_point value.
226
221
 * #define SET_INEXACT if IEEE arithmetic is being used and extra
227
222
 *      computation should be done to set the inexact flag when the
358
353
 
359
354
typedef union { double d; ULong L[2]; } U;
360
355
 
361
 
#ifdef YES_ALIAS
362
 
#define dval(x) x
363
 
#ifdef IEEE_8087
364
 
#define word0(x) ((ULong *)&x)[1]
365
 
#define word1(x) ((ULong *)&x)[0]
366
 
#else
367
 
#define word0(x) ((ULong *)&x)[0]
368
 
#define word1(x) ((ULong *)&x)[1]
369
 
#endif
370
 
#else
371
 
#ifdef IEEE_8087
372
 
#define word0(x) ((U*)&x)->L[1]
373
 
#define word1(x) ((U*)&x)->L[0]
374
 
#else
375
 
#define word0(x) ((U*)&x)->L[0]
376
 
#define word1(x) ((U*)&x)->L[1]
377
 
#endif
378
 
#define dval(x) ((U*)&x)->d
 
356
#define dval(x) (x).d
 
357
#ifdef IEEE_8087
 
358
#define word0(x) (x).L[1]
 
359
#define word1(x) (x).L[0]
 
360
#else
 
361
#define word0(x) (x).L[0]
 
362
#define word1(x) (x).L[1]
379
363
#endif
380
364
 
381
365
/* The following definition of Storeinc is appropriate for MIPS processors.
1184
1168
 static double
1185
1169
ulp
1186
1170
#ifdef KR_headers
1187
 
        (x) double x;
 
1171
        (dx) double dx;
1188
1172
#else
1189
 
        (double x)
 
1173
        (double dx)
1190
1174
#endif
1191
1175
{
1192
1176
        register Long L;
1193
 
        double a;
 
1177
        U x, a;
1194
1178
 
 
1179
        dval(x) = dx;
1195
1180
        L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
1196
1181
#ifndef Avoid_Underflow
1197
1182
#ifndef Sudden_Underflow
1233
1218
{
1234
1219
        ULong *xa, *xa0, w, y, z;
1235
1220
        int k;
1236
 
        double d;
 
1221
        U d;
1237
1222
#ifdef VAX
1238
1223
        ULong d0, d1;
1239
1224
#else
1296
1281
 static Bigint *
1297
1282
d2b
1298
1283
#ifdef KR_headers
1299
 
        (d, e, bits) double d; int *e, *bits;
 
1284
        (dd, e, bits) double dd; int *e, *bits;
1300
1285
#else
1301
 
        (double d, int *e, int *bits)
 
1286
        (double dd, int *e, int *bits)
1302
1287
#endif
1303
1288
{
 
1289
        U d;
1304
1290
        Bigint *b;
1305
1291
        int de, k;
1306
1292
        ULong *x, y, z;
1309
1295
#endif
1310
1296
#ifdef VAX
1311
1297
        ULong d0, d1;
 
1298
#endif
 
1299
 
 
1300
        dval(d) = dd;
 
1301
#ifdef VAX
1312
1302
        d0 = word0(d) >> 16 | word0(d) << 16;
1313
1303
        d1 = word1(d) >> 16 | word1(d) << 16;
1314
1304
#else
1439
1429
        (Bigint *a, Bigint *b)
1440
1430
#endif
1441
1431
{
1442
 
        double da, db;
 
1432
        U da, db;
1443
1433
        int k, ka, kb;
1444
1434
 
1445
1435
        dval(da) = b2d(a, &ka);
1613
1603
        int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign,
1614
1604
                 e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
1615
1605
        CONST char *s, *s0, *s1;
1616
 
        double aadj, aadj1, adj, rv, rv0;
 
1606
        double aadj, aadj1, adj;
 
1607
        U aadj2, rv, rv0;
1617
1608
        Long L;
1618
1609
        ULong y, z;
1619
1610
        Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
2376
2367
                                        aadj = z;
2377
2368
                                        aadj1 = dsign ? aadj : -aadj;
2378
2369
                                        }
2379
 
                                word0(aadj1) += (2*P+1)*Exp_msk1 - y;
 
2370
                                dval(aadj2) = aadj1;
 
2371
                                word0(aadj2) += (2*P+1)*Exp_msk1 - y;
 
2372
                                aadj1 = dval(aadj2);
2380
2373
                                }
2381
2374
                        adj = aadj1 * ulp(dval(rv));
2382
2375
                        dval(rv) += adj;
2711
2704
 static char *
2712
2705
dtoa
2713
2706
#ifdef KR_headers
2714
 
        (d, mode, ndigits, decpt, sign, rve)
2715
 
        double d; int mode, ndigits, *decpt, *sign; char **rve;
 
2707
        (dd, mode, ndigits, decpt, sign, rve)
 
2708
        double dd; int mode, ndigits, *decpt, *sign; char **rve;
2716
2709
#else
2717
 
        (double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
 
2710
        (double dd, int mode, int ndigits, int *decpt, int *sign, char **rve)
2718
2711
#endif
2719
2712
{
2720
2713
 /*     Arguments ndigits, decpt, sign are similar to those
2760
2753
        ULong x;
2761
2754
#endif
2762
2755
        Bigint *b, *b1, *delta, *mlo, *mhi, *S;
2763
 
        double d2, ds, eps;
 
2756
        U d, d2, eps;
 
2757
        double ds;
2764
2758
        char *s, *s0;
2765
2759
#ifdef Honor_FLT_ROUNDS
2766
2760
        int rounding;
2776
2770
                }
2777
2771
#endif
2778
2772
 
 
2773
        dval(d) = dd;
2779
2774
        if (word0(d) & Sign_bit) {
2780
2775
                /* set sign for everything, including 0's and NaNs */
2781
2776
                *sign = 1;
3435
3430
**   '+' or '-' after the 'e' in scientific notation
3436
3431
*/
3437
3432
PR_IMPLEMENT(void)
3438
 
PR_cnvtf(char *buf,int bufsz, int prcsn,double fval)
 
3433
PR_cnvtf(char *buf, int bufsz, int prcsn, double dfval)
3439
3434
{
3440
3435
    PRIntn decpt, sign, numdigits;
3441
3436
    char *num, *nump;
3442
3437
    char *bufp = buf;
3443
3438
    char *endnum;
 
3439
    U fval;
3444
3440
 
 
3441
    dval(fval) = dfval;
3445
3442
    /* If anything fails, we store an empty string in 'buf' */
3446
3443
    num = (char*)PR_MALLOC(bufsz);
3447
3444
    if (num == NULL) {