Project

General

Profile

Bug #3700 ยป util.c.patch

util.c patch - pweldon (Peter Weldon), 08/16/2010 01:38 PM

View differences:

util.c (working copy)
3120 3120
static char *
3121 3121
nrv_alloc(const char *s, char **rve, size_t n)
3122 3122
{
3123
    char *rv, *t;
3123
    char *rv;
3124 3124

  
3125
    t = rv = rv_alloc(n);
3126
    while ((*t = *s++) != 0) t++;
3125
    rv = rv_alloc(n);
3126
    memcpy(rv,s,n);
3127 3127
    if (rve)
3128
        *rve = t;
3128
        *rve = rv + n - 1;
3129 3129
    return rv;
3130 3130
}
3131 3131

  
3132
#define rv_strdup(s, rve) nrv_alloc(s, rve, strlen(s)+1)
3132
#define rv_strdup(s, rve) nrv_alloc(s, rve, sizeof(s))
3133 3133

  
3134 3134
#ifndef MULTIPLE_THREADS
3135 3135
/* freedtoa(s) must be used to free values s returned by dtoa
......
3179 3179
 *     calculation.
3180 3180
 */
3181 3181

  
3182
#define	INFSTR	"Infinity"
3183
#define	NANSTR	"NaN"
3184
#define ZEROSTR "0"
3185

  
3182 3186
char *
3183 3187
ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve)
3184 3188
{
......
3263 3267
        *decpt = 9999;
3264 3268
#ifdef IEEE_Arith
3265 3269
        if (!word1(d) && !(word0(d) & 0xfffff))
3266
            return rv_strdup("Infinity", rve);
3270
            return rv_strdup(INFSTR, rve);
3267 3271
#endif
3268
        return rv_strdup("NaN", rve);
3272
        return rv_strdup(NANSTR, rve);
3269 3273
    }
3270 3274
#endif
3271 3275
#ifdef IBM
......
3273 3277
#endif
3274 3278
    if (!dval(d)) {
3275 3279
        *decpt = 1;
3276
        return rv_strdup("0", rve);
3280
        return rv_strdup(ZEROSTR, rve);
3277 3281
    }
3278 3282

  
3279 3283
#ifdef SET_INEXACT
......
3897 3901

  
3898 3902
#define	DBL_MANH_SIZE	20
3899 3903
#define	DBL_MANL_SIZE	32
3900
#define	INFSTR	"Infinity"
3901
#define	NANSTR	"NaN"
3902 3904
#define	DBL_ADJ	(DBL_MAX_EXP - 2)
3903 3905
#define	SIGFIGS	((DBL_MANT_DIG + 3) / 4 + 1)
3904 3906
#define dexp_get(u) ((int)(word0(u) >> Exp_shift) & ~Exp_msk1)
......
3951 3953

  
3952 3954
	if (isinf(d)) { /* FP_INFINITE */
3953 3955
	    *decpt = INT_MAX;
3954
	    return (nrv_alloc(INFSTR, rve, sizeof(INFSTR) - 1));
3956
	    return (rv_strdup(INFSTR, rve));
3955 3957
	}
3956 3958
	else if (isnan(d)) { /* FP_NAN */
3957 3959
	    *decpt = INT_MAX;
3958
	    return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1));
3960
	    return (rv_strdup(NANSTR, rve));
3959 3961
	}
3960 3962
	else if (d == 0.0) { /* FP_ZERO */
3961 3963
	    *decpt = 1;
3962
	    return (nrv_alloc("0", rve, 1));
3964
	    return (rv_strdup(ZEROSTR, rve));
3963 3965
	}
3964 3966
	else if (dexp_get(u)) { /* FP_NORMAL */
3965 3967
	    *decpt = dexp_get(u) - DBL_ADJ;