mirror of
https://github.com/reactos/reactos.git
synced 2025-01-02 20:43:18 +00:00
- Fixed some 'dereferencing type-punned pointer will break strict-aliasing rules'
warnings on higher optimisation levels. svn path=/trunk/; revision=10653
This commit is contained in:
parent
adc7fbb548
commit
df7a301805
9 changed files with 181 additions and 79 deletions
|
@ -7,12 +7,17 @@
|
|||
*/
|
||||
double _chgsign( double __x )
|
||||
{
|
||||
double_t *x = (double_t *)&x;
|
||||
union
|
||||
{
|
||||
double* __x;
|
||||
double_t *x;
|
||||
} u;
|
||||
u.__x = &__x;
|
||||
|
||||
if ( x->sign == 1 )
|
||||
x->sign = 0;
|
||||
if ( u.x->sign == 1 )
|
||||
u.x->sign = 0;
|
||||
else
|
||||
x->sign = 1;
|
||||
u.x->sign = 1;
|
||||
|
||||
return __x;
|
||||
}
|
||||
|
|
|
@ -6,10 +6,20 @@
|
|||
*/
|
||||
double _copysign (double __d, double __s)
|
||||
{
|
||||
double_t *d = (double_t *)&__d;
|
||||
double_t *s = (double_t *)&__s;
|
||||
union
|
||||
{
|
||||
double* __d;
|
||||
double_t* d;
|
||||
} d;
|
||||
union
|
||||
{
|
||||
double* __s;
|
||||
double_t* s;
|
||||
} s;
|
||||
d.__d = &__d;
|
||||
s.__s = &__s;
|
||||
|
||||
d->sign = s->sign;
|
||||
d.d->sign = s.s->sign;
|
||||
|
||||
return __d;
|
||||
}
|
||||
|
|
|
@ -31,33 +31,38 @@ typedef int fpclass_t;
|
|||
* @implemented
|
||||
*/
|
||||
fpclass_t _fpclass(double __d)
|
||||
{
|
||||
double_t *d = (double_t *)&__d;
|
||||
{
|
||||
union
|
||||
{
|
||||
double* __d;
|
||||
double_t* d;
|
||||
} d;
|
||||
d.__d = &__d;
|
||||
|
||||
if ( d->exponent == 0 ) {
|
||||
if ( d->mantissah == 0 && d->mantissal == 0 ) {
|
||||
if ( d->sign ==0 )
|
||||
if ( d.d->exponent == 0 ) {
|
||||
if ( d.d->mantissah == 0 && d.d->mantissal == 0 ) {
|
||||
if ( d.d->sign ==0 )
|
||||
return FP_NZERO;
|
||||
else
|
||||
return FP_PZERO;
|
||||
} else {
|
||||
if ( d->sign ==0 )
|
||||
if ( d.d->sign ==0 )
|
||||
return FP_NDENORM;
|
||||
else
|
||||
return FP_PDENORM;
|
||||
}
|
||||
}
|
||||
if (d->exponent == 0x7ff ) {
|
||||
if ( d->mantissah == 0 && d->mantissal == 0 ) {
|
||||
if ( d->sign ==0 )
|
||||
if (d.d->exponent == 0x7ff ) {
|
||||
if ( d.d->mantissah == 0 && d.d->mantissal == 0 ) {
|
||||
if ( d.d->sign ==0 )
|
||||
return FP_NINF;
|
||||
else
|
||||
return FP_PINF;
|
||||
}
|
||||
else if ( d->mantissah == 0 && d->mantissal != 0 ) {
|
||||
else if ( d.d->mantissah == 0 && d.d->mantissal != 0 ) {
|
||||
return FP_QNAN;
|
||||
}
|
||||
else if ( d->mantissah == 0 && d->mantissal != 0 ) {
|
||||
else if ( d.d->mantissah == 0 && d.d->mantissal != 0 ) {
|
||||
return FP_SNAN;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,31 +25,46 @@ Cambridge, MA 02139, USA. */
|
|||
* @implemented
|
||||
*/
|
||||
int _isnan(double __x)
|
||||
{
|
||||
double_t * x = (double_t *)&__x;
|
||||
return ( x->exponent == 0x7ff && ( x->mantissah != 0 || x->mantissal != 0 ));
|
||||
{
|
||||
union
|
||||
{
|
||||
double* __x;
|
||||
double_t* x;
|
||||
} x;
|
||||
x.__x = &__x;
|
||||
return ( x.x->exponent == 0x7ff && ( x.x->mantissah != 0 || x.x->mantissal != 0 ));
|
||||
}
|
||||
|
||||
int _isnanl(long double __x)
|
||||
{
|
||||
/* Intel's extended format has the normally implicit 1 explicit
|
||||
present. Sigh! */
|
||||
|
||||
long_double_t * x = (long_double_t *)&__x;
|
||||
union
|
||||
{
|
||||
long double* __x;
|
||||
long_double_t* x;
|
||||
} x;
|
||||
x.__x = &__x;
|
||||
|
||||
|
||||
/* IEEE 854 NaN's have the maximum possible
|
||||
exponent and a nonzero mantissa. */
|
||||
|
||||
return (( x->exponent == 0x7fff)
|
||||
&& ( (x->mantissah & 0x80000000) != 0)
|
||||
&& ( (x->mantissah & (unsigned int)0x7fffffff) != 0 || x->mantissal != 0 ));
|
||||
return (( x.x->exponent == 0x7fff)
|
||||
&& ( (x.x->mantissah & 0x80000000) != 0)
|
||||
&& ( (x.x->mantissah & (unsigned int)0x7fffffff) != 0 || x.x->mantissal != 0 ));
|
||||
}
|
||||
|
||||
int _isinf(double __x)
|
||||
{
|
||||
double_t * x = (double_t *)&__x;
|
||||
return ( x->exponent == 0x7ff && ( x->mantissah == 0 && x->mantissal == 0 ));
|
||||
union
|
||||
{
|
||||
double* __x;
|
||||
double_t* x;
|
||||
} x;
|
||||
|
||||
x.__x = &__x;
|
||||
return ( x.x->exponent == 0x7ff && ( x.x->mantissah == 0 && x.x->mantissal == 0 ));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -64,15 +79,20 @@ int _isinfl(long double __x)
|
|||
{
|
||||
/* Intel's extended format has the normally implicit 1 explicit
|
||||
present. Sigh! */
|
||||
|
||||
long_double_t * x = (long_double_t *)&__x;
|
||||
union
|
||||
{
|
||||
long double* __x;
|
||||
long_double_t* x;
|
||||
} x;
|
||||
|
||||
x.__x = &__x;
|
||||
|
||||
|
||||
/* An IEEE 854 infinity has an exponent with the
|
||||
maximum possible value and a zero mantissa. */
|
||||
|
||||
|
||||
if ( x->exponent == 0x7fff && ( (x->mantissah == 0x80000000 ) && x->mantissal == 0 ))
|
||||
return x->sign ? -1 : 1;
|
||||
if ( x.x->exponent == 0x7fff && ( (x.x->mantissah == 0x80000000 ) && x.x->mantissal == 0 ))
|
||||
return x.x->sign ? -1 : 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -5,10 +5,16 @@
|
|||
* @implemented
|
||||
*/
|
||||
double _scalb( double __x, long e )
|
||||
{
|
||||
double_t *x = (double_t *)&__x;
|
||||
{
|
||||
union
|
||||
{
|
||||
double* __x;
|
||||
double_t* x;
|
||||
} x;
|
||||
|
||||
x->exponent += e;
|
||||
x.__x = &__x;
|
||||
|
||||
x.x->exponent += e;
|
||||
|
||||
return __x;
|
||||
}
|
||||
|
|
|
@ -8,13 +8,19 @@
|
|||
double
|
||||
frexp(double __x, int *exptr)
|
||||
{
|
||||
double_t *x = (double_t *)&__x;
|
||||
union
|
||||
{
|
||||
double* __x;
|
||||
double_t* x;
|
||||
} x;
|
||||
|
||||
x.__x = &__x;
|
||||
|
||||
if ( exptr != NULL )
|
||||
*exptr = x->exponent - 0x3FE;
|
||||
*exptr = x.x->exponent - 0x3FE;
|
||||
|
||||
|
||||
x->exponent = 0x3FE;
|
||||
x.x->exponent = 0x3FE;
|
||||
|
||||
return __x;
|
||||
}
|
||||
|
|
|
@ -20,32 +20,45 @@
|
|||
|
||||
double modf(double __x, double *__i)
|
||||
{
|
||||
double_t * x = (double_t *)&__x;
|
||||
double_t * iptr = ( double_t *)__i;
|
||||
union
|
||||
{
|
||||
double* __x;
|
||||
double_t* x;
|
||||
} x;
|
||||
union
|
||||
{
|
||||
double* __i;
|
||||
double_t* iptr;
|
||||
} iptr;
|
||||
|
||||
int j0;
|
||||
unsigned int i;
|
||||
j0 = x->exponent - 0x3ff; /* exponent of x */
|
||||
|
||||
x.__x = &__x;
|
||||
iptr.__i = __i;
|
||||
|
||||
|
||||
j0 = x.x->exponent - 0x3ff; /* exponent of x */
|
||||
if(j0<20) { /* integer part in high x */
|
||||
if(j0<0) { /* |x|<1 */
|
||||
*__i = 0.0;
|
||||
iptr->sign = x->sign;
|
||||
iptr.iptr->sign = x.x->sign;
|
||||
return __x;
|
||||
} else {
|
||||
|
||||
if ( x->mantissah == 0 && x->mantissal == 0 ) {
|
||||
if ( x.x->mantissah == 0 && x.x->mantissal == 0 ) {
|
||||
*__i = __x;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
i = (0x000fffff)>>j0;
|
||||
iptr->sign = x->sign;
|
||||
iptr->exponent = x->exponent;
|
||||
iptr->mantissah = x->mantissah&(~i);
|
||||
iptr->mantissal = 0;
|
||||
iptr.iptr->sign = x.x->sign;
|
||||
iptr.iptr->exponent = x.x->exponent;
|
||||
iptr.iptr->mantissah = x.x->mantissah&(~i);
|
||||
iptr.iptr->mantissal = 0;
|
||||
if ( __x == *__i ) {
|
||||
__x = 0.0;
|
||||
x->sign = iptr->sign;
|
||||
x.x->sign = iptr.iptr->sign;
|
||||
return __x;
|
||||
}
|
||||
return __x - *__i;
|
||||
|
@ -56,18 +69,18 @@ double modf(double __x, double *__i)
|
|||
return __x;
|
||||
|
||||
__x = 0.0;
|
||||
x->sign = iptr->sign;
|
||||
x.x->sign = iptr.iptr->sign;
|
||||
return __x;
|
||||
} else { /* fraction part in low x */
|
||||
|
||||
i = ((unsigned)(0xffffffff))>>(j0-20);
|
||||
iptr->sign = x->sign;
|
||||
iptr->exponent = x->exponent;
|
||||
iptr->mantissah = x->mantissah;
|
||||
iptr->mantissal = x->mantissal&(~i);
|
||||
iptr.iptr->sign = x.x->sign;
|
||||
iptr.iptr->exponent = x.x->exponent;
|
||||
iptr.iptr->mantissah = x.x->mantissah;
|
||||
iptr.iptr->mantissal = x.x->mantissal&(~i);
|
||||
if ( __x == *__i ) {
|
||||
__x = 0.0;
|
||||
x->sign = iptr->sign;
|
||||
x.x->sign = iptr.iptr->sign;
|
||||
return __x;
|
||||
}
|
||||
return __x - *__i;
|
||||
|
@ -77,31 +90,44 @@ double modf(double __x, double *__i)
|
|||
|
||||
long double modfl(long double __x, long double *__i)
|
||||
{
|
||||
long_double_t * x = (long_double_t *)&__x;
|
||||
long_double_t * iptr = (long_double_t *)__i;
|
||||
union
|
||||
{
|
||||
long double* __x;
|
||||
long_double_t* x;
|
||||
} x;
|
||||
union
|
||||
{
|
||||
long double* __i;
|
||||
long_double_t* iptr;
|
||||
} iptr;
|
||||
|
||||
int j0;
|
||||
unsigned int i;
|
||||
j0 = x->exponent - 0x3fff; /* exponent of x */
|
||||
|
||||
x.__x = &__x;
|
||||
iptr.__i = __i;
|
||||
|
||||
|
||||
j0 = x.x->exponent - 0x3fff; /* exponent of x */
|
||||
|
||||
if(j0<32) { /* integer part in high x */
|
||||
if(j0<0) { /* |x|<1 */
|
||||
*__i = 0.0L;
|
||||
iptr->sign = x->sign;
|
||||
iptr.iptr->sign = x.x->sign;
|
||||
return __x;
|
||||
} else {
|
||||
|
||||
i = ((unsigned int)(0xffffffff))>>(j0+1);
|
||||
if ( x->mantissal == 0 && (x->mantissal & i) == 0 ) {
|
||||
if ( x.x->mantissal == 0 && (x.x->mantissal & i) == 0 ) {
|
||||
*__i = __x;
|
||||
__x = 0.0L;
|
||||
x->sign = iptr->sign;
|
||||
x.x->sign = iptr.iptr->sign;
|
||||
return __x;
|
||||
}
|
||||
iptr->sign = x->sign;
|
||||
iptr->exponent = x->exponent;
|
||||
iptr->mantissah = x->mantissah&((~i));
|
||||
iptr->mantissal = 0;
|
||||
iptr.iptr->sign = x.x->sign;
|
||||
iptr.iptr->exponent = x.x->exponent;
|
||||
iptr.iptr->mantissah = x.x->mantissah&((~i));
|
||||
iptr.iptr->mantissal = 0;
|
||||
|
||||
return __x - *__i;
|
||||
}
|
||||
|
@ -111,21 +137,21 @@ long double modfl(long double __x, long double *__i)
|
|||
return __x;
|
||||
|
||||
__x = 0.0L;
|
||||
x->sign = iptr->sign;
|
||||
x.x->sign = iptr.iptr->sign;
|
||||
return __x;
|
||||
} else { /* fraction part in low x */
|
||||
|
||||
i = ((unsigned int)(0xffffffff))>>(j0-32);
|
||||
if ( x->mantissal == 0 ) {
|
||||
if ( x.x->mantissal == 0 ) {
|
||||
*__i = __x;
|
||||
__x = 0.0L;
|
||||
x->sign = iptr->sign;
|
||||
x.x->sign = iptr.iptr->sign;
|
||||
return __x;
|
||||
}
|
||||
iptr->sign = x->sign;
|
||||
iptr->exponent = x->exponent;
|
||||
iptr->mantissah = x->mantissah;
|
||||
iptr->mantissal = x->mantissal&(~i);
|
||||
iptr.iptr->sign = x.x->sign;
|
||||
iptr.iptr->exponent = x.x->exponent;
|
||||
iptr.iptr->mantissah = x.x->mantissah;
|
||||
iptr.iptr->mantissal = x.x->mantissal&(~i);
|
||||
|
||||
return __x - *__i;
|
||||
}
|
||||
|
|
|
@ -219,10 +219,16 @@ static int numberf(FILE * f, double __n, char exp_sign, int size, int precision
|
|||
char ro = 0;
|
||||
int result, done = 0;
|
||||
|
||||
double_t *n = (double_t *)&__n;
|
||||
union
|
||||
{
|
||||
double* __n;
|
||||
double_t* n;
|
||||
} n;
|
||||
|
||||
n.__n = &__n;
|
||||
|
||||
if ( exp_sign == 'g' || exp_sign == 'G' || exp_sign == 'e' || exp_sign == 'E' ) {
|
||||
ie = ((unsigned int)n->exponent - (unsigned int)0x3ff);
|
||||
ie = ((unsigned int)n.n->exponent - (unsigned int)0x3ff);
|
||||
exponent = ie/3.321928;
|
||||
}
|
||||
|
||||
|
@ -422,10 +428,16 @@ static int numberfl(FILE * f, long double __n, char exp_sign, int size, int pre
|
|||
|
||||
int result, done = 0;
|
||||
|
||||
long_double_t *n = (long_double_t *)&__n;
|
||||
union
|
||||
{
|
||||
long double* __n;
|
||||
long_double_t* n;
|
||||
} n;
|
||||
|
||||
n.__n = &__n;
|
||||
|
||||
if ( exp_sign == 'g' || exp_sign == 'G' || exp_sign == 'e' || exp_sign == 'E' ) {
|
||||
ie = ((unsigned int)n->exponent - (unsigned int)0x3fff);
|
||||
ie = ((unsigned int)n.n->exponent - (unsigned int)0x3fff);
|
||||
exponent = ie/3.321928;
|
||||
}
|
||||
|
||||
|
|
|
@ -226,10 +226,16 @@ static int numberf(FILE * f, double __n, wchar_t exp_sign, int size, int precis
|
|||
char ro = 0;
|
||||
int result, done = 0;
|
||||
|
||||
double_t *n = (double_t *)&__n;
|
||||
union
|
||||
{
|
||||
double* __n;
|
||||
double_t* n;
|
||||
} n;
|
||||
|
||||
n.__n = &__n;
|
||||
|
||||
if ( exp_sign == L'g' || exp_sign == L'G' || exp_sign == L'e' || exp_sign == L'E' ) {
|
||||
ie = ((unsigned int)n->exponent - (unsigned int)0x3ff);
|
||||
ie = ((unsigned int)n.n->exponent - (unsigned int)0x3ff);
|
||||
exponent = ie/3.321928;
|
||||
}
|
||||
|
||||
|
@ -429,10 +435,16 @@ static int numberfl(FILE * f, long double __n, wchar_t exp_sign, int size, int
|
|||
|
||||
int result, done = 0;
|
||||
|
||||
long_double_t *n = (long_double_t *)&__n;
|
||||
union
|
||||
{
|
||||
long double* __n;
|
||||
long_double_t* n;
|
||||
} n;
|
||||
|
||||
n.__n = &__n;
|
||||
|
||||
if ( exp_sign == L'g' || exp_sign == L'G' || exp_sign == L'e' || exp_sign == L'E' ) {
|
||||
ie = ((unsigned int)n->exponent - (unsigned int)0x3fff);
|
||||
ie = ((unsigned int)n.n->exponent - (unsigned int)0x3fff);
|
||||
exponent = ie/3.321928;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue