1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* util.c (IEEE_BIG_ENDIAN): use configured value. [ruby-dev:31623]

* util.c (Llong): set to LONG_LONG if available.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-08-27 06:33:12 +00:00
parent fa02a6cedd
commit d4b9e9815b
2 changed files with 47 additions and 37 deletions

View file

@ -1,3 +1,9 @@
Mon Aug 27 15:33:10 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* util.c (IEEE_BIG_ENDIAN): use configured value. [ruby-dev:31623]
* util.c (Llong): set to LONG_LONG if available.
Mon Aug 27 13:11:56 2007 Yukihiro Matsumoto <matz@ruby-lang.org> Mon Aug 27 13:11:56 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (tr_trans): wrong condition for mbmaxlen==1 strings. * string.c (tr_trans): wrong condition for mbmaxlen==1 strings.

78
util.c
View file

@ -21,6 +21,14 @@
#ifdef _WIN32 #ifdef _WIN32
#include "missing/file.h" #include "missing/file.h"
#endif #endif
#if defined(__CYGWIN32__)
#define _open open
#define _close close
#define _unlink unlink
#define _access access
#elif defined(_WIN32)
#include <io.h>
#endif
#include "ruby/util.h" #include "ruby/util.h"
@ -184,7 +192,7 @@ ruby_add_suffix(VALUE str, const char *suffix)
p = t; p = t;
t = ext; extlen = 0; t = ext; extlen = 0;
while (*t++ = *s++) extlen++; while ((*t++ = *s++) != 0) extlen++;
if (extlen == 0) { ext[0] = '.'; ext[1] = 0; extlen++; } if (extlen == 0) { ext[0] = '.'; ext[1] = 0; extlen++; }
if (*suffix == '.') { /* Style 1 */ if (*suffix == '.') { /* Style 1 */
@ -814,7 +822,7 @@ ruby_getcwd(void)
* the result overflows to +-Infinity or underflows to 0. * the result overflows to +-Infinity or underflows to 0.
*/ */
#ifdef __BIG_ENDIAN__ #ifdef WORDS_BIGENDIAN
#define IEEE_BIG_ENDIAN #define IEEE_BIG_ENDIAN
#else #else
#define IEEE_LITTLE_ENDIAN #define IEEE_LITTLE_ENDIAN
@ -842,10 +850,8 @@ ruby_getcwd(void)
#define ULong unsigned long int #define ULong unsigned long int
#endif #endif
#if defined(_MSC_VER) || defined(__BORLANDC__) #if HAVE_LONG_LONG
#define Long __int32 #define Llong LONG_LONG
#define ULong unsigned __int32
#define IEEE_LITTLE_ENDIAN
#endif #endif
#ifdef DEBUG #ifdef DEBUG
@ -1147,7 +1153,7 @@ Balloc(int k)
#endif #endif
ACQUIRE_DTOA_LOCK(0); ACQUIRE_DTOA_LOCK(0);
if (rv = freelist[k]) { if ((rv = freelist[k]) != 0) {
freelist[k] = rv->next; freelist[k] = rv->next;
} }
else { else {
@ -1391,7 +1397,7 @@ mult(Bigint *a, Bigint *b)
xc0 = c->x; xc0 = c->x;
#ifdef ULLong #ifdef ULLong
for (; xb < xbe; xc0++) { for (; xb < xbe; xc0++) {
if (y = *xb++) { if ((y = *xb++) != 0) {
x = xa; x = xa;
xc = xc0; xc = xc0;
carry = 0; carry = 0;
@ -1464,7 +1470,7 @@ pow5mult(Bigint *b, int k)
int i; int i;
static int p05[3] = { 5, 25, 125 }; static int p05[3] = { 5, 25, 125 };
if (i = k & 3) if ((i = k & 3) != 0)
b = multadd(b, p05[i-1], 0); b = multadd(b, p05[i-1], 0);
if (!(k >>= 2)) if (!(k >>= 2))
@ -1539,7 +1545,7 @@ lshift(Bigint *b, int k)
*x1++ = *x << k | z; *x1++ = *x << k | z;
z = *x++ >> k1; z = *x++ >> k1;
} while (x < xe); } while (x < xe);
if (*x1 = z) if ((*x1 = z) != 0)
++n1; ++n1;
} }
#else #else
@ -1738,16 +1744,16 @@ b2d(Bigint *a, int *e)
*e = 32 - k; *e = 32 - k;
#ifdef Pack_32 #ifdef Pack_32
if (k < Ebits) { if (k < Ebits) {
d0 = Exp_1 | y >> Ebits - k; d0 = Exp_1 | y >> (Ebits - k);
w = xa > xa0 ? *--xa : 0; w = xa > xa0 ? *--xa : 0;
d1 = y << (32-Ebits) + k | w >> Ebits - k; d1 = y << ((32-Ebits) + k) | w >> (Ebits - k);
goto ret_d; goto ret_d;
} }
z = xa > xa0 ? *--xa : 0; z = xa > xa0 ? *--xa : 0;
if (k -= Ebits) { if (k -= Ebits) {
d0 = Exp_1 | y << k | z >> 32 - k; d0 = Exp_1 | y << k | z >> (32 - k);
y = xa > xa0 ? *--xa : 0; y = xa > xa0 ? *--xa : 0;
d1 = z << k | y >> 32 - k; d1 = z << k | y >> (32 - k);
} }
else { else {
d0 = Exp_1 | y; d0 = Exp_1 | y;
@ -1813,13 +1819,13 @@ d2b(double d, int *e, int *bits)
z |= Exp_msk11; z |= Exp_msk11;
#endif #endif
#else #else
if (de = (int)(d0 >> Exp_shift)) if ((de = (int)(d0 >> Exp_shift)) != 0)
z |= Exp_msk1; z |= Exp_msk1;
#endif #endif
#ifdef Pack_32 #ifdef Pack_32
if (y = d1) { if ((y = d1) != 0) {
if (k = lo0bits(&y)) { if ((k = lo0bits(&y)) != 0) {
x[0] = y | z << 32 - k; x[0] = y | z << (32 - k);
z >>= k; z >>= k;
} }
else else
@ -2364,7 +2370,7 @@ vax_ovfl_check:
/* Get starting approximation = rv * 10**e1 */ /* Get starting approximation = rv * 10**e1 */
if (e1 > 0) { if (e1 > 0) {
if (i = e1 & 15) if ((i = e1 & 15) != 0)
dval(rv) *= tens[i]; dval(rv) *= tens[i];
if (e1 &= ~15) { if (e1 &= ~15) {
if (e1 > DBL_MAX_10_EXP) { if (e1 > DBL_MAX_10_EXP) {
@ -2424,7 +2430,7 @@ ovfl:
} }
else if (e1 < 0) { else if (e1 < 0) {
e1 = -e1; e1 = -e1;
if (i = e1 & 15) if ((i = e1 & 15) != 0)
dval(rv) /= tens[i]; dval(rv) /= tens[i];
if (e1 >>= 4) { if (e1 >>= 4) {
if (e1 >= 1 << n_bigtens) if (e1 >= 1 << n_bigtens)
@ -2443,7 +2449,7 @@ ovfl:
if (j >= 53) if (j >= 53)
word0(rv) = (P+2)*Exp_msk1; word0(rv) = (P+2)*Exp_msk1;
else else
word0(rv) &= 0xffffffff << j-32; word0(rv) &= 0xffffffff << (j-32);
} }
else else
word1(rv) &= 0xffffffff << j; word1(rv) &= 0xffffffff << j;
@ -3091,7 +3097,7 @@ nrv_alloc(char *s, char **rve, int n)
char *rv, *t; char *rv, *t;
t = rv = rv_alloc(n); t = rv = rv_alloc(n);
while (*t = *s++) t++; while ((*t = *s++) != 0) t++;
if (rve) if (rve)
*rve = t; *rve = t;
return rv; return rv;
@ -3261,7 +3267,7 @@ dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
#ifdef Sudden_Underflow #ifdef Sudden_Underflow
i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
#else #else
if (i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) { if ((i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) != 0) {
#endif #endif
dval(d2) = dval(d); dval(d2) = dval(d);
word0(d2) &= Frac_mask1; word0(d2) &= Frac_mask1;
@ -3305,8 +3311,8 @@ dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
/* d is denormalized */ /* d is denormalized */
i = bbits + be + (Bias + (P-1) - 1); i = bbits + be + (Bias + (P-1) - 1);
x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32 x = i > 32 ? word0(d) << (64 - i) | word1(d) >> (i - 32)
: word1(d) << 32 - i; : word1(d) << (32 - i);
dval(d2) = x; dval(d2) = x;
word0(d2) -= 31*Exp_msk1; /* adjust exponent */ word0(d2) -= 31*Exp_msk1; /* adjust exponent */
i -= (Bias + (P-1) - 1) + 1; i -= (Bias + (P-1) - 1) + 1;
@ -3358,10 +3364,10 @@ dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
try_quick = 0; try_quick = 0;
} }
leftright = 1; leftright = 1;
ilim = ilim1 = -1;
switch (mode) { switch (mode) {
case 0: case 0:
case 1: case 1:
ilim = ilim1 = -1;
i = 18; i = 18;
ndigits = 0; ndigits = 0;
break; break;
@ -3415,7 +3421,7 @@ dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
} }
dval(d) /= ds; dval(d) /= ds;
} }
else if (j1 = -k) { else if ((j1 = -k) != 0) {
dval(d) *= tens[j1 & 0xf]; dval(d) *= tens[j1 & 0xf];
for (j = j1 >> 4; j; j >>= 1, i++) for (j = j1 >> 4; j; j >>= 1, i++)
if (j & 1) { if (j & 1) {
@ -3529,7 +3535,7 @@ fast_failed:
} }
#endif #endif
dval(d) += dval(d); dval(d) += dval(d);
if (dval(d) > ds || dval(d) == ds && L & 1) { if (dval(d) > ds || (dval(d) == ds && (L & 1))) {
bump_up: bump_up:
while (*--s == '9') while (*--s == '9')
if (s == s0) { if (s == s0) {
@ -3576,7 +3582,7 @@ bump_up:
Bfree(b); Bfree(b);
b = b1; b = b1;
} }
if (j = b5 - m5) if ((j = b5 - m5) != 0)
b = pow5mult(b, j); b = pow5mult(b, j);
} }
else else
@ -3614,10 +3620,10 @@ bump_up:
* can do shifts and ors to compute the numerator for q. * can do shifts and ors to compute the numerator for q.
*/ */
#ifdef Pack_32 #ifdef Pack_32
if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) if ((i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) != 0)
i = 32 - i; i = 32 - i;
#else #else
if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) if ((i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) != 0)
i = 16 - i; i = 16 - i;
#endif #endif
if (i > 4) { if (i > 4) {
@ -3699,11 +3705,11 @@ one_digit:
goto ret; goto ret;
} }
#endif #endif
if (j < 0 || j == 0 && mode != 1 if (j < 0 || (j == 0 && mode != 1
#ifndef ROUND_BIASED #ifndef ROUND_BIASED
&& !(word1(d) & 1) && !(word1(d) & 1)
#endif #endif
) { )) {
if (!b->x[0] && b->wds <= 1) { if (!b->x[0] && b->wds <= 1) {
#ifdef SET_INEXACT #ifdef SET_INEXACT
inexact = 0; inexact = 0;
@ -3720,8 +3726,7 @@ one_digit:
if (j1 > 0) { if (j1 > 0) {
b = lshift(b, 1); b = lshift(b, 1);
j1 = cmp(b, S); j1 = cmp(b, S);
if ((j1 > 0 || j1 == 0 && dig & 1) if ((j1 > 0 || (j1 == 0 && (dig & 1))) && dig++ == '9')
&& dig++ == '9')
goto round_9_up; goto round_9_up;
} }
accept_dig: accept_dig:
@ -3780,7 +3785,7 @@ keep_dig:
#endif #endif
b = lshift(b, 1); b = lshift(b, 1);
j = cmp(b, S); j = cmp(b, S);
if (j > 0 || j == 0 && dig & 1) { if (j > 0 || (j == 0 && (dig & 1))) {
roundoff: roundoff:
while (*--s == '9') while (*--s == '9')
if (s == s0) { if (s == s0) {
@ -3791,7 +3796,6 @@ keep_dig:
++*s++; ++*s++;
} }
else { else {
trimzeros:
while (*--s == '0') ; while (*--s == '0') ;
s++; s++;
} }