added lrint and llrint functions to math.h

added generic implementations for ppc and m68k


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30945 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2009-06-02 20:24:18 +00:00
parent 30bc84e971
commit 59d67522ea
9 changed files with 510 additions and 1 deletions

View File

@ -100,10 +100,12 @@ extern float gammaf(float x);
extern float hypotf(float x, float y);
extern float ldexpf(float x, int exponent);
extern float lgammaf(float x);
extern long long llrintf(float x);
extern float log10f(float x);
extern float log1pf(float x);
extern float logbf(float x);
extern float logf(float x);
extern long lrintf(float x);
extern long lroundf(float x);
extern float modff(float x, float *y);
extern float nearbyintf(float x);
@ -135,8 +137,10 @@ extern double frexp(double x, int *_exponent);
extern double gamma(double x);
extern double ldexp(double x, int exponent);
extern double lgamma(double x);
extern long long llrint(double x);
extern double log(double x);
extern double log10(double x);
extern long lrint(double x);
extern long lround(double x);
extern double modf(double x, double *y);
extern double nearbyint(double x);
@ -159,9 +163,11 @@ extern long double atanhl(long double x);
extern long double atan2l(long double y, long double x);
extern long double lgammal(long double x);
extern long double nearbyintl(long double x);
extern long double roundl(long double x);
extern long long llrintl(long double x);
extern long lrintl(long double x);
extern long lroundl(long double x);
extern long double remquol(long double x, long double y, int *quo);
extern long double roundl(long double x);
/* some BSD non-ANSI or POSIX math functions */
extern double cbrt(double x);

View File

@ -0,0 +1,93 @@
/* Round argument to nearest integral value according to current rounding
direction.
Copyright (C) 1997, 2004, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <math.h>
#include "math_private.h"
static const double two52[2] =
{
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
};
long long int
__llrint (double x)
{
int32_t j0;
u_int32_t i1, i0;
long long int result;
volatile double w;
double t;
int sx;
EXTRACT_WORDS (i0, i1, x);
j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
sx = i0 >> 31;
i0 &= 0xfffff;
i0 |= 0x100000;
if (j0 < 20)
{
w = two52[sx] + x;
t = w - two52[sx];
EXTRACT_WORDS (i0, i1, t);
j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
i0 &= 0xfffff;
i0 |= 0x100000;
result = (j0 < 0 ? 0 : i0 >> (20 - j0));
}
else if (j0 < (int32_t) (8 * sizeof (long long int)) - 1)
{
if (j0 >= 52)
result = (((long long int) i0 << 32) | i1) << (j0 - 52);
else
{
w = two52[sx] + x;
t = w - two52[sx];
EXTRACT_WORDS (i0, i1, t);
j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
i0 &= 0xfffff;
i0 |= 0x100000;
if (j0 == 20)
result = (long long int) i0;
else
result = ((long long int) i0 << (j0 - 20)) | (i1 >> (52 - j0));
}
}
else
{
/* The number is too large. It is left implementation defined
what happens. */
return (long long int) x;
}
return sx ? -result : result;
}
weak_alias (__llrint, llrint)
#ifdef NO_LONG_DOUBLE
strong_alias (__llrint, __llrintl)
weak_alias (__llrint, llrintl)
#endif

View File

@ -0,0 +1,76 @@
/* Round argument to nearest integral value according to current rounding
direction.
Copyright (C) 1997, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <math.h>
#include "math_private.h"
static const float two23[2] =
{
8.3886080000e+06, /* 0x4B000000 */
-8.3886080000e+06, /* 0xCB000000 */
};
long long int
__llrintf (float x)
{
int32_t j0;
u_int32_t i0;
volatile float w;
float t;
long long int result;
int sx;
GET_FLOAT_WORD (i0, x);
sx = i0 >> 31;
j0 = ((i0 >> 23) & 0xff) - 0x7f;
i0 &= 0x7fffff;
i0 |= 0x800000;
if (j0 < (int32_t) (sizeof (long long int) * 8) - 1)
{
if (j0 >= 23)
result = (long long int) i0 << (j0 - 23);
else
{
w = two23[sx] + x;
t = w - two23[sx];
GET_FLOAT_WORD (i0, t);
j0 = ((i0 >> 23) & 0xff) - 0x7f;
i0 &= 0x7fffff;
i0 |= 0x800000;
result = (j0 < 0 ? 0 : i0 >> (23 - j0));
}
}
else
{
/* The number is too large. It is left implementation defined
what happens. */
return (long long int) x;
}
return sx ? -result : result;
}
weak_alias (__llrintf, llrintf)

View File

@ -0,0 +1,77 @@
/* Round argument to nearest integral value according to current rounding
direction.
Copyright (C) 1997, 2004, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <math.h>
#include "math_private.h"
static const long double two63[2] =
{
9.223372036854775808000000e+18, /* 0x403E, 0x00000000, 0x00000000 */
-9.223372036854775808000000e+18 /* 0xC03E, 0x00000000, 0x00000000 */
};
long long int
__llrintl (long double x)
{
int32_t se,j0;
u_int32_t i0, i1;
long long int result;
volatile long double w;
long double t;
int sx;
GET_LDOUBLE_WORDS (se, i0, i1, x);
sx = (se >> 15) & 1;
j0 = (se & 0x7fff) - 0x3fff;
if (j0 < (int32_t) (8 * sizeof (long long int)) - 1)
{
if (j0 >= 63)
result = (((long long int) i0 << 32) | i1) << (j0 - 63);
else
{
w = two63[sx] + x;
t = w - two63[sx];
GET_LDOUBLE_WORDS (se, i0, i1, t);
j0 = (se & 0x7fff) - 0x3fff;
if (j0 < 0)
result = 0;
else if (j0 <= 31)
result = i0 >> (31 - j0);
else
result = ((long long int) i0 << (j0 - 31)) | (i1 >> (63 - j0));
}
}
else
{
/* The number is too large. It is left implementation defined
what happens. */
return (long long int) x;
}
return sx ? -result : result;
}
weak_alias (__llrintl, llrintl)

View File

@ -0,0 +1,93 @@
/* Round argument to nearest integral value according to current rounding
direction.
Copyright (C) 1997, 2004, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <math.h>
#include "math_private.h"
static const double two52[2] =
{
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
};
long int
__lrint (double x)
{
int32_t j0;
u_int32_t i0,i1;
volatile double w;
double t;
long int result;
int sx;
EXTRACT_WORDS (i0, i1, x);
j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
sx = i0 >> 31;
i0 &= 0xfffff;
i0 |= 0x100000;
if (j0 < 20)
{
w = two52[sx] + x;
t = w - two52[sx];
EXTRACT_WORDS (i0, i1, t);
j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
i0 &= 0xfffff;
i0 |= 0x100000;
result = (j0 < 0 ? 0 : i0 >> (20 - j0));
}
else if (j0 < (int32_t) (8 * sizeof (long int)) - 1)
{
if (j0 >= 52)
result = ((long int) i0 << (j0 - 20)) | (i1 << (j0 - 52));
else
{
w = two52[sx] + x;
t = w - two52[sx];
EXTRACT_WORDS (i0, i1, t);
j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
i0 &= 0xfffff;
i0 |= 0x100000;
if (j0 == 20)
result = (long int) i0;
else
result = ((long int) i0 << (j0 - 20)) | (i1 >> (52 - j0));
}
}
else
{
/* The number is too large. It is left implementation defined
what happens. */
return (long int) x;
}
return sx ? -result : result;
}
weak_alias (__lrint, lrint)
#ifdef NO_LONG_DOUBLE
strong_alias (__lrint, __lrintl)
weak_alias (__lrint, lrintl)
#endif

View File

@ -0,0 +1,76 @@
/* Round argument to nearest integral value according to current rounding
direction.
Copyright (C) 1997, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <math.h>
#include "math_private.h"
static const float two23[2] =
{
8.3886080000e+06, /* 0x4B000000 */
-8.3886080000e+06, /* 0xCB000000 */
};
long int
__lrintf (float x)
{
int32_t j0;
u_int32_t i0;
volatile float w;
float t;
long int result;
int sx;
GET_FLOAT_WORD (i0, x);
sx = i0 >> 31;
j0 = ((i0 >> 23) & 0xff) - 0x7f;
i0 &= 0x7fffff;
i0 |= 0x800000;
if (j0 < (int32_t) (sizeof (long int) * 8) - 1)
{
if (j0 >= 23)
result = (long int) i0 << (j0 - 23);
else
{
w = two23[sx] + x;
t = w - two23[sx];
GET_FLOAT_WORD (i0, t);
j0 = ((i0 >> 23) & 0xff) - 0x7f;
i0 &= 0x7fffff;
i0 |= 0x800000;
result = (j0 < 0 ? 0 : i0 >> (23 - j0));
}
}
else
{
/* The number is too large. It is left implementation defined
what happens. */
return (long int) x;
}
return sx ? -result : result;
}
weak_alias (__lrintf, lrintf)

View File

@ -0,0 +1,84 @@
/* Round argument to nearest integral value according to current rounding
direction.
Copyright (C) 1997, 2004, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <math.h>
#include "math_private.h"
static const long double two63[2] =
{
9.223372036854775808000000e+18, /* 0x403E, 0x00000000, 0x00000000 */
-9.223372036854775808000000e+18 /* 0xC03E, 0x00000000, 0x00000000 */
};
long int
__lrintl (long double x)
{
int32_t se,j0;
u_int32_t i0, i1;
long int result;
volatile long double w;
long double t;
int sx;
GET_LDOUBLE_WORDS (se, i0, i1, x);
sx = (se >> 15) & 1;
j0 = (se & 0x7fff) - 0x3fff;
if (j0 < 31)
{
w = two63[sx] + x;
t = w - two63[sx];
GET_LDOUBLE_WORDS (se, i0, i1, t);
j0 = (se & 0x7fff) - 0x3fff;
result = (j0 < 0 ? 0 : i0 >> (31 - j0));
}
else if (j0 < (int32_t) (8 * sizeof (long int)) - 1)
{
if (j0 >= 63)
result = ((long int) i0 << (j0 - 31)) | (i1 << (j0 - 63));
else
{
w = two63[sx] + x;
t = w - two63[sx];
GET_LDOUBLE_WORDS (se, i0, i1, t);
j0 = (se & 0x7fff) - 0x3fff;
if (j0 == 31)
result = (long int) i0;
else
result = ((long int) i0 << (j0 - 31)) | (i1 >> (63 - j0));
}
}
else
{
/* The number is too large. It is left implementation defined
what happens. */
return (long int) x;
}
return sx ? -result : result;
}
weak_alias (__lrintl, lrintl)

View File

@ -77,8 +77,10 @@ local genericSources =
s_ilogb.c s_ilogbf.c
s_isinf.c s_isinff.c # s_isinfl.c
s_ldexp.c s_ldexpf.c # s_ldexpl.c
s_llrint.c s_llrintf.c # s_llrintl.c
s_log1p.c s_log1pf.c
s_logb.c s_logbf.c # s_logbl.c
s_lrint.c s_lrintf.c # s_lrintl.c
s_lround.c s_lroundf.c
s_modf.c s_modff.c # s_modfl.c
s_nan.c s_nanf.c # s_nanl.c

View File

@ -75,8 +75,10 @@ local genericSources =
s_ilogb.c s_ilogbf.c
s_isinf.c s_isinff.c # s_isinfl.c
s_ldexp.c s_ldexpf.c # s_ldexpl.c
s_llrint.c s_llrintf.c # s_llrintl.c
s_log1p.c s_log1pf.c
s_logb.c s_logbf.c # s_logbl.c
s_lrint.c s_lrintf.c # s_lrintl.c
s_lround.c s_lroundf.c
s_modf.c s_modff.c # s_modfl.c
s_nan.c s_nanf.c # s_nanl.c