/*
|
/*
|
* inspired by glibc-2.0.6/sysdeps/libm-ieee754/s_nextafterf.c
|
* inspired by glibc-2.0.6/sysdeps/libm-ieee754/s_nextafterf.c
|
*
|
*
|
* gcc -O2 -S -DOP=+ gives faddp %st(1),%st
|
* gcc -O2 -S -DOP=+ gives faddp %st(1),%st
|
* gcc -O2 -S -DOP=* gives fmulp %st(1),%st
|
* gcc -O2 -S -DOP=* gives fmulp %st(1),%st
|
* gcc -O2 -S -DOP=- gives fsubrp %st(1),%st
|
* gcc -O2 -S -DOP=- gives fsubrp %st(1),%st
|
* gcc -O2 -S -DOP=/ gives fdivrp %st(1),%st
|
* gcc -O2 -S -DOP=/ gives fdivrp %st(1),%st
|
*/
|
*/
|
|
|
#ifndef OP
|
#ifndef OP
|
#define OP *
|
#define OP *
|
#endif
|
#endif
|
|
|
typedef int int32_t __attribute__ ((__mode__ ( __SI__ ))) ;
|
typedef int int32_t __attribute__ ((__mode__ ( __SI__ ))) ;
|
typedef unsigned int u_int32_t __attribute__ ((__mode__ ( __SI__ ))) ;
|
typedef unsigned int u_int32_t __attribute__ ((__mode__ ( __SI__ ))) ;
|
|
|
typedef union
|
typedef union
|
{
|
{
|
float value;
|
float value;
|
u_int32_t word;
|
u_int32_t word;
|
} ieee_float_shape_type;
|
} ieee_float_shape_type;
|
|
|
float __nextafterf(float x, float y)
|
float __nextafterf(float x, float y)
|
{
|
{
|
int32_t hx,hy,ix,iy;
|
int32_t hx,hy,ix,iy;
|
|
|
{
|
{
|
ieee_float_shape_type gf_u;
|
ieee_float_shape_type gf_u;
|
gf_u.value = x;
|
gf_u.value = x;
|
hx = gf_u.word;
|
hx = gf_u.word;
|
}
|
}
|
{
|
{
|
ieee_float_shape_type gf_u;
|
ieee_float_shape_type gf_u;
|
gf_u.value = y;
|
gf_u.value = y;
|
hy = gf_u.word;
|
hy = gf_u.word;
|
}
|
}
|
ix = hx&0x7fffffff;
|
ix = hx&0x7fffffff;
|
iy = hy&0x7fffffff;
|
iy = hy&0x7fffffff;
|
|
|
if ( ix > 0x7f800000 || iy > 0x7f800000 )
|
if ( ix > 0x7f800000 || iy > 0x7f800000 )
|
return x+y;
|
return x+y;
|
if (x == y) return x;
|
if (x == y) return x;
|
if (ix == 0)
|
if (ix == 0)
|
{
|
{
|
{
|
{
|
ieee_float_shape_type sf_u;
|
ieee_float_shape_type sf_u;
|
sf_u.word = (hy&0x80000000) | 1;
|
sf_u.word = (hy&0x80000000) | 1;
|
x = sf_u.value;
|
x = sf_u.value;
|
}
|
}
|
y = x*x;
|
y = x*x;
|
if (y == x) return y; else return x;
|
if (y == x) return y; else return x;
|
}
|
}
|
if (hx >= 0)
|
if (hx >= 0)
|
{
|
{
|
if (hx > hy)
|
if (hx > hy)
|
hx -= 1;
|
hx -= 1;
|
else
|
else
|
hx += 1;
|
hx += 1;
|
}
|
}
|
else
|
else
|
{
|
{
|
if (hy >= 0 || hx > hy)
|
if (hy >= 0 || hx > hy)
|
hx -= 1;
|
hx -= 1;
|
else
|
else
|
hx += 1;
|
hx += 1;
|
}
|
}
|
hy = hx & 0x7f800000;
|
hy = hx & 0x7f800000;
|
if (hy >= 0x7f800000)
|
if (hy >= 0x7f800000)
|
return x+x;
|
return x+x;
|
if (hy < 0x00800000)
|
if (hy < 0x00800000)
|
{
|
{
|
y = x OP x;
|
y = x OP x;
|
if (y != x)
|
if (y != x)
|
{
|
{
|
ieee_float_shape_type sf_u;
|
ieee_float_shape_type sf_u;
|
sf_u.word = hx;
|
sf_u.word = hx;
|
y = sf_u.value;
|
y = sf_u.value;
|
return y;
|
return y;
|
}
|
}
|
}
|
}
|
{
|
{
|
ieee_float_shape_type sf_u;
|
ieee_float_shape_type sf_u;
|
sf_u.word = hx;
|
sf_u.word = hx;
|
x = sf_u.value;
|
x = sf_u.value;
|
}
|
}
|
return x;
|
return x;
|
}
|
}
|
|
|
|
|
|
|