Bug #3700 » util.c.patch
util.c (working copy) | ||
---|---|---|
static char *
|
||
nrv_alloc(const char *s, char **rve, size_t n)
|
||
{
|
||
char *rv, *t;
|
||
char *rv;
|
||
t = rv = rv_alloc(n);
|
||
while ((*t = *s++) != 0) t++;
|
||
rv = rv_alloc(n);
|
||
memcpy(rv,s,n);
|
||
if (rve)
|
||
*rve = t;
|
||
*rve = rv + n - 1;
|
||
return rv;
|
||
}
|
||
#define rv_strdup(s, rve) nrv_alloc(s, rve, strlen(s)+1)
|
||
#define rv_strdup(s, rve) nrv_alloc(s, rve, sizeof(s))
|
||
#ifndef MULTIPLE_THREADS
|
||
/* freedtoa(s) must be used to free values s returned by dtoa
|
||
... | ... | |
* calculation.
|
||
*/
|
||
#define INFSTR "Infinity"
|
||
#define NANSTR "NaN"
|
||
#define ZEROSTR "0"
|
||
char *
|
||
ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
||
{
|
||
... | ... | |
*decpt = 9999;
|
||
#ifdef IEEE_Arith
|
||
if (!word1(d) && !(word0(d) & 0xfffff))
|
||
return rv_strdup("Infinity", rve);
|
||
return rv_strdup(INFSTR, rve);
|
||
#endif
|
||
return rv_strdup("NaN", rve);
|
||
return rv_strdup(NANSTR, rve);
|
||
}
|
||
#endif
|
||
#ifdef IBM
|
||
... | ... | |
#endif
|
||
if (!dval(d)) {
|
||
*decpt = 1;
|
||
return rv_strdup("0", rve);
|
||
return rv_strdup(ZEROSTR, rve);
|
||
}
|
||
#ifdef SET_INEXACT
|
||
... | ... | |
#define DBL_MANH_SIZE 20
|
||
#define DBL_MANL_SIZE 32
|
||
#define INFSTR "Infinity"
|
||
#define NANSTR "NaN"
|
||
#define DBL_ADJ (DBL_MAX_EXP - 2)
|
||
#define SIGFIGS ((DBL_MANT_DIG + 3) / 4 + 1)
|
||
#define dexp_get(u) ((int)(word0(u) >> Exp_shift) & ~Exp_msk1)
|
||
... | ... | |
if (isinf(d)) { /* FP_INFINITE */
|
||
*decpt = INT_MAX;
|
||
return (nrv_alloc(INFSTR, rve, sizeof(INFSTR) - 1));
|
||
return (rv_strdup(INFSTR, rve));
|
||
}
|
||
else if (isnan(d)) { /* FP_NAN */
|
||
*decpt = INT_MAX;
|
||
return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1));
|
||
return (rv_strdup(NANSTR, rve));
|
||
}
|
||
else if (d == 0.0) { /* FP_ZERO */
|
||
*decpt = 1;
|
||
return (nrv_alloc("0", rve, 1));
|
||
return (rv_strdup(ZEROSTR, rve));
|
||
}
|
||
else if (dexp_get(u)) { /* FP_NORMAL */
|
||
*decpt = dexp_get(u) - DBL_ADJ;
|
- « Previous
- 1
- 2
- Next »