2009-04-03 Craig Howland <howland@LGSInnovations.com>
* libm/common/s_llrint.c: New file, implementing llrint(). * libm/common/sf_llrint.c: New file, implementing llrintf(). * libm/common/Makefile.am: Add s_llrint.c (src); sf_llrint.c (fsrc). * libm/common/Makefile.in: Regenerate.
This commit is contained in:
parent
f5e097fa4b
commit
8ca79ad630
|
@ -1,3 +1,10 @@
|
||||||
|
2009-04-03 Craig Howland <howland@LGSInnovations.com>
|
||||||
|
|
||||||
|
* libm/common/s_llrint.c: New file, implementing llrint().
|
||||||
|
* libm/common/sf_llrint.c: New file, implementing llrintf().
|
||||||
|
* libm/common/Makefile.am: Add s_llrint.c (src); sf_llrint.c (fsrc).
|
||||||
|
* libm/common/Makefile.in: Regenerate.
|
||||||
|
|
||||||
2009-04-02 Corinna Vinschen <corinna@vinschen.de>
|
2009-04-02 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* libc/ctype/ctype_c.c: Move inclusion of ctype_iso.h and
|
* libc/ctype/ctype_c.c: Move inclusion of ctype_iso.h and
|
||||||
|
|
|
@ -9,7 +9,8 @@ src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \
|
||||||
s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
|
s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
|
||||||
s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
|
s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
|
||||||
s_rint.c s_logb.c s_log2.c s_matherr.c s_lib_ver.c \
|
s_rint.c s_logb.c s_log2.c s_matherr.c s_lib_ver.c \
|
||||||
s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c s_lrint.c \
|
s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
|
||||||
|
s_lrint.c s_llrint.c \
|
||||||
s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
|
s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
|
||||||
s_signbit.c s_trunc.c
|
s_signbit.c s_trunc.c
|
||||||
|
|
||||||
|
@ -18,7 +19,8 @@ fsrc = sf_finite.c sf_copysign.c sf_modf.c sf_scalbn.c \
|
||||||
sf_infinity.c sf_isinf.c sf_isinff.c sf_isnan.c sf_isnanf.c \
|
sf_infinity.c sf_isinf.c sf_isinff.c sf_isnan.c sf_isnanf.c \
|
||||||
sf_log1p.c sf_nan.c sf_nextafter.c sf_pow10.c \
|
sf_log1p.c sf_nan.c sf_nextafter.c sf_pow10.c \
|
||||||
sf_rint.c sf_logb.c sf_log2.c \
|
sf_rint.c sf_logb.c sf_log2.c \
|
||||||
sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_fpclassify.c sf_lrint.c \
|
sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_fpclassify.c \
|
||||||
|
sf_lrint.c sf_llrint.c \
|
||||||
sf_lround.c sf_llround.c sf_nearbyint.c sf_remquo.c sf_round.c \
|
sf_lround.c sf_llround.c sf_nearbyint.c sf_remquo.c sf_round.c \
|
||||||
sf_scalbln.c sf_trunc.c
|
sf_scalbln.c sf_trunc.c
|
||||||
|
|
||||||
|
|
|
@ -71,11 +71,11 @@ am__objects_1 = lib_a-s_finite.$(OBJEXT) lib_a-s_copysign.$(OBJEXT) \
|
||||||
lib_a-s_lib_ver.$(OBJEXT) lib_a-s_fdim.$(OBJEXT) \
|
lib_a-s_lib_ver.$(OBJEXT) lib_a-s_fdim.$(OBJEXT) \
|
||||||
lib_a-s_fma.$(OBJEXT) lib_a-s_fmax.$(OBJEXT) \
|
lib_a-s_fma.$(OBJEXT) lib_a-s_fmax.$(OBJEXT) \
|
||||||
lib_a-s_fmin.$(OBJEXT) lib_a-s_fpclassify.$(OBJEXT) \
|
lib_a-s_fmin.$(OBJEXT) lib_a-s_fpclassify.$(OBJEXT) \
|
||||||
lib_a-s_lrint.$(OBJEXT) lib_a-s_lround.$(OBJEXT) \
|
lib_a-s_lrint.$(OBJEXT) lib_a-s_llrint.$(OBJEXT) \
|
||||||
lib_a-s_llround.$(OBJEXT) lib_a-s_nearbyint.$(OBJEXT) \
|
lib_a-s_lround.$(OBJEXT) lib_a-s_llround.$(OBJEXT) \
|
||||||
lib_a-s_remquo.$(OBJEXT) lib_a-s_round.$(OBJEXT) \
|
lib_a-s_nearbyint.$(OBJEXT) lib_a-s_remquo.$(OBJEXT) \
|
||||||
lib_a-s_scalbln.$(OBJEXT) lib_a-s_signbit.$(OBJEXT) \
|
lib_a-s_round.$(OBJEXT) lib_a-s_scalbln.$(OBJEXT) \
|
||||||
lib_a-s_trunc.$(OBJEXT)
|
lib_a-s_signbit.$(OBJEXT) lib_a-s_trunc.$(OBJEXT)
|
||||||
am__objects_2 = lib_a-sf_finite.$(OBJEXT) lib_a-sf_copysign.$(OBJEXT) \
|
am__objects_2 = lib_a-sf_finite.$(OBJEXT) lib_a-sf_copysign.$(OBJEXT) \
|
||||||
lib_a-sf_modf.$(OBJEXT) lib_a-sf_scalbn.$(OBJEXT) \
|
lib_a-sf_modf.$(OBJEXT) lib_a-sf_scalbn.$(OBJEXT) \
|
||||||
lib_a-sf_cbrt.$(OBJEXT) lib_a-sf_exp10.$(OBJEXT) \
|
lib_a-sf_cbrt.$(OBJEXT) lib_a-sf_exp10.$(OBJEXT) \
|
||||||
|
@ -89,10 +89,10 @@ am__objects_2 = lib_a-sf_finite.$(OBJEXT) lib_a-sf_copysign.$(OBJEXT) \
|
||||||
lib_a-sf_fdim.$(OBJEXT) lib_a-sf_fma.$(OBJEXT) \
|
lib_a-sf_fdim.$(OBJEXT) lib_a-sf_fma.$(OBJEXT) \
|
||||||
lib_a-sf_fmax.$(OBJEXT) lib_a-sf_fmin.$(OBJEXT) \
|
lib_a-sf_fmax.$(OBJEXT) lib_a-sf_fmin.$(OBJEXT) \
|
||||||
lib_a-sf_fpclassify.$(OBJEXT) lib_a-sf_lrint.$(OBJEXT) \
|
lib_a-sf_fpclassify.$(OBJEXT) lib_a-sf_lrint.$(OBJEXT) \
|
||||||
lib_a-sf_lround.$(OBJEXT) lib_a-sf_llround.$(OBJEXT) \
|
lib_a-sf_llrint.$(OBJEXT) lib_a-sf_lround.$(OBJEXT) \
|
||||||
lib_a-sf_nearbyint.$(OBJEXT) lib_a-sf_remquo.$(OBJEXT) \
|
lib_a-sf_llround.$(OBJEXT) lib_a-sf_nearbyint.$(OBJEXT) \
|
||||||
lib_a-sf_round.$(OBJEXT) lib_a-sf_scalbln.$(OBJEXT) \
|
lib_a-sf_remquo.$(OBJEXT) lib_a-sf_round.$(OBJEXT) \
|
||||||
lib_a-sf_trunc.$(OBJEXT)
|
lib_a-sf_scalbln.$(OBJEXT) lib_a-sf_trunc.$(OBJEXT)
|
||||||
@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) \
|
@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) \
|
||||||
@USE_LIBTOOL_FALSE@ $(am__objects_2)
|
@USE_LIBTOOL_FALSE@ $(am__objects_2)
|
||||||
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
|
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
|
||||||
|
@ -104,16 +104,16 @@ am__objects_3 = s_finite.lo s_copysign.lo s_modf.lo s_scalbn.lo \
|
||||||
s_log1p.lo s_nan.lo s_nextafter.lo s_pow10.lo s_rint.lo \
|
s_log1p.lo s_nan.lo s_nextafter.lo s_pow10.lo s_rint.lo \
|
||||||
s_logb.lo s_log2.lo s_matherr.lo s_lib_ver.lo s_fdim.lo \
|
s_logb.lo s_log2.lo s_matherr.lo s_lib_ver.lo s_fdim.lo \
|
||||||
s_fma.lo s_fmax.lo s_fmin.lo s_fpclassify.lo s_lrint.lo \
|
s_fma.lo s_fmax.lo s_fmin.lo s_fpclassify.lo s_lrint.lo \
|
||||||
s_lround.lo s_llround.lo s_nearbyint.lo s_remquo.lo s_round.lo \
|
s_llrint.lo s_lround.lo s_llround.lo s_nearbyint.lo \
|
||||||
s_scalbln.lo s_signbit.lo s_trunc.lo
|
s_remquo.lo s_round.lo s_scalbln.lo s_signbit.lo s_trunc.lo
|
||||||
am__objects_4 = sf_finite.lo sf_copysign.lo sf_modf.lo sf_scalbn.lo \
|
am__objects_4 = sf_finite.lo sf_copysign.lo sf_modf.lo sf_scalbn.lo \
|
||||||
sf_cbrt.lo sf_exp10.lo sf_expm1.lo sf_ilogb.lo sf_infinity.lo \
|
sf_cbrt.lo sf_exp10.lo sf_expm1.lo sf_ilogb.lo sf_infinity.lo \
|
||||||
sf_isinf.lo sf_isinff.lo sf_isnan.lo sf_isnanf.lo sf_log1p.lo \
|
sf_isinf.lo sf_isinff.lo sf_isnan.lo sf_isnanf.lo sf_log1p.lo \
|
||||||
sf_nan.lo sf_nextafter.lo sf_pow10.lo sf_rint.lo sf_logb.lo \
|
sf_nan.lo sf_nextafter.lo sf_pow10.lo sf_rint.lo sf_logb.lo \
|
||||||
sf_log2.lo sf_fdim.lo sf_fma.lo sf_fmax.lo sf_fmin.lo \
|
sf_log2.lo sf_fdim.lo sf_fma.lo sf_fmax.lo sf_fmin.lo \
|
||||||
sf_fpclassify.lo sf_lrint.lo sf_lround.lo sf_llround.lo \
|
sf_fpclassify.lo sf_lrint.lo sf_llrint.lo sf_lround.lo \
|
||||||
sf_nearbyint.lo sf_remquo.lo sf_round.lo sf_scalbln.lo \
|
sf_llround.lo sf_nearbyint.lo sf_remquo.lo sf_round.lo \
|
||||||
sf_trunc.lo
|
sf_scalbln.lo sf_trunc.lo
|
||||||
@USE_LIBTOOL_TRUE@am_libcommon_la_OBJECTS = $(am__objects_3) \
|
@USE_LIBTOOL_TRUE@am_libcommon_la_OBJECTS = $(am__objects_3) \
|
||||||
@USE_LIBTOOL_TRUE@ $(am__objects_4)
|
@USE_LIBTOOL_TRUE@ $(am__objects_4)
|
||||||
libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS)
|
libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS)
|
||||||
|
@ -282,7 +282,8 @@ src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \
|
||||||
s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
|
s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
|
||||||
s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
|
s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
|
||||||
s_rint.c s_logb.c s_log2.c s_matherr.c s_lib_ver.c \
|
s_rint.c s_logb.c s_log2.c s_matherr.c s_lib_ver.c \
|
||||||
s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c s_lrint.c \
|
s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
|
||||||
|
s_lrint.c s_llrint.c \
|
||||||
s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
|
s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
|
||||||
s_signbit.c s_trunc.c
|
s_signbit.c s_trunc.c
|
||||||
|
|
||||||
|
@ -291,7 +292,8 @@ fsrc = sf_finite.c sf_copysign.c sf_modf.c sf_scalbn.c \
|
||||||
sf_infinity.c sf_isinf.c sf_isinff.c sf_isnan.c sf_isnanf.c \
|
sf_infinity.c sf_isinf.c sf_isinff.c sf_isnan.c sf_isnanf.c \
|
||||||
sf_log1p.c sf_nan.c sf_nextafter.c sf_pow10.c \
|
sf_log1p.c sf_nan.c sf_nextafter.c sf_pow10.c \
|
||||||
sf_rint.c sf_logb.c sf_log2.c \
|
sf_rint.c sf_logb.c sf_log2.c \
|
||||||
sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_fpclassify.c sf_lrint.c \
|
sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_fpclassify.c \
|
||||||
|
sf_lrint.c sf_llrint.c \
|
||||||
sf_lround.c sf_llround.c sf_nearbyint.c sf_remquo.c sf_round.c \
|
sf_lround.c sf_llround.c sf_nearbyint.c sf_remquo.c sf_round.c \
|
||||||
sf_scalbln.c sf_trunc.c
|
sf_scalbln.c sf_trunc.c
|
||||||
|
|
||||||
|
@ -556,6 +558,12 @@ lib_a-s_lrint.o: s_lrint.c
|
||||||
lib_a-s_lrint.obj: s_lrint.c
|
lib_a-s_lrint.obj: s_lrint.c
|
||||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lrint.obj `if test -f 's_lrint.c'; then $(CYGPATH_W) 's_lrint.c'; else $(CYGPATH_W) '$(srcdir)/s_lrint.c'; fi`
|
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lrint.obj `if test -f 's_lrint.c'; then $(CYGPATH_W) 's_lrint.c'; else $(CYGPATH_W) '$(srcdir)/s_lrint.c'; fi`
|
||||||
|
|
||||||
|
lib_a-s_llrint.o: s_llrint.c
|
||||||
|
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_llrint.o `test -f 's_llrint.c' || echo '$(srcdir)/'`s_llrint.c
|
||||||
|
|
||||||
|
lib_a-s_llrint.obj: s_llrint.c
|
||||||
|
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_llrint.obj `if test -f 's_llrint.c'; then $(CYGPATH_W) 's_llrint.c'; else $(CYGPATH_W) '$(srcdir)/s_llrint.c'; fi`
|
||||||
|
|
||||||
lib_a-s_lround.o: s_lround.c
|
lib_a-s_lround.o: s_lround.c
|
||||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lround.o `test -f 's_lround.c' || echo '$(srcdir)/'`s_lround.c
|
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lround.o `test -f 's_lround.c' || echo '$(srcdir)/'`s_lround.c
|
||||||
|
|
||||||
|
@ -760,6 +768,12 @@ lib_a-sf_lrint.o: sf_lrint.c
|
||||||
lib_a-sf_lrint.obj: sf_lrint.c
|
lib_a-sf_lrint.obj: sf_lrint.c
|
||||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_lrint.obj `if test -f 'sf_lrint.c'; then $(CYGPATH_W) 'sf_lrint.c'; else $(CYGPATH_W) '$(srcdir)/sf_lrint.c'; fi`
|
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_lrint.obj `if test -f 'sf_lrint.c'; then $(CYGPATH_W) 'sf_lrint.c'; else $(CYGPATH_W) '$(srcdir)/sf_lrint.c'; fi`
|
||||||
|
|
||||||
|
lib_a-sf_llrint.o: sf_llrint.c
|
||||||
|
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_llrint.o `test -f 'sf_llrint.c' || echo '$(srcdir)/'`sf_llrint.c
|
||||||
|
|
||||||
|
lib_a-sf_llrint.obj: sf_llrint.c
|
||||||
|
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_llrint.obj `if test -f 'sf_llrint.c'; then $(CYGPATH_W) 'sf_llrint.c'; else $(CYGPATH_W) '$(srcdir)/sf_llrint.c'; fi`
|
||||||
|
|
||||||
lib_a-sf_lround.o: sf_lround.c
|
lib_a-sf_lround.o: sf_lround.c
|
||||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_lround.o `test -f 'sf_lround.c' || echo '$(srcdir)/'`sf_lround.c
|
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_lround.o `test -f 'sf_lround.c' || echo '$(srcdir)/'`sf_lround.c
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
/* lrint adapted to be llrint for Newlib, 2009 by Craig Howland. */
|
||||||
|
/* @(#)s_lrint.c 5.1 93/09/24 */
|
||||||
|
/*
|
||||||
|
* ====================================================
|
||||||
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||||
|
* Permission to use, copy, modify, and distribute this
|
||||||
|
* software is freely granted, provided that this notice
|
||||||
|
* is preserved.
|
||||||
|
* ====================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* llrint(x)
|
||||||
|
* Return x rounded to integral value according to the prevailing
|
||||||
|
* rounding mode.
|
||||||
|
* Method:
|
||||||
|
* Using floating addition.
|
||||||
|
* Exception:
|
||||||
|
* Inexact flag raised if x not equal to llrint(x).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "fdlibm.h"
|
||||||
|
|
||||||
|
#ifndef _DOUBLE_IS_32BITS
|
||||||
|
|
||||||
|
#ifdef __STDC__
|
||||||
|
static const double
|
||||||
|
#else
|
||||||
|
static double
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Adding a double, x, to 2^52 will cause the result to be rounded based on
|
||||||
|
the fractional part of x, according to the implementation's current rounding
|
||||||
|
mode. 2^52 is the smallest double that can be represented using all 52 significant
|
||||||
|
digits. */
|
||||||
|
TWO52[2]={
|
||||||
|
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
|
||||||
|
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
|
||||||
|
};
|
||||||
|
|
||||||
|
long long int
|
||||||
|
#ifdef __STDC__
|
||||||
|
llrint(double x)
|
||||||
|
#else
|
||||||
|
llrint(x)
|
||||||
|
double x;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
__int32_t i0,j0,sx;
|
||||||
|
__uint32_t i1;
|
||||||
|
double t;
|
||||||
|
volatile double w;
|
||||||
|
long long int result;
|
||||||
|
|
||||||
|
EXTRACT_WORDS(i0,i1,x);
|
||||||
|
|
||||||
|
/* Extract sign bit. */
|
||||||
|
sx = (i0>>31)&1;
|
||||||
|
|
||||||
|
/* Extract exponent field. */
|
||||||
|
j0 = ((i0 & 0x7ff00000) >> 20) - 1023;
|
||||||
|
|
||||||
|
if(j0 < 20)
|
||||||
|
{
|
||||||
|
if(j0 < -1)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
w = TWO52[sx] + x;
|
||||||
|
t = w - TWO52[sx];
|
||||||
|
GET_HIGH_WORD(i0, t);
|
||||||
|
/* Detect the all-zeros representation of plus and
|
||||||
|
minus zero, which fails the calculation below. */
|
||||||
|
if ((i0 & ~(1 << 31)) == 0)
|
||||||
|
return 0;
|
||||||
|
j0 = ((i0 & 0x7ff00000) >> 20) - 1023;
|
||||||
|
i0 &= 0x000fffff;
|
||||||
|
i0 |= 0x00100000;
|
||||||
|
result = i0 >> (20 - j0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (j0 < (int)(8 * sizeof (long long int)) - 1)
|
||||||
|
{
|
||||||
|
if (j0 >= 52)
|
||||||
|
result = ((long long int) ((i0 & 0x000fffff) | 0x0010000) << (j0 - 20)) |
|
||||||
|
(i1 << (j0 - 52));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
w = TWO52[sx] + x;
|
||||||
|
t = w - TWO52[sx];
|
||||||
|
EXTRACT_WORDS (i0, i1, t);
|
||||||
|
j0 = ((i0 & 0x7ff00000) >> 20) - 1023;
|
||||||
|
i0 &= 0x000fffff;
|
||||||
|
i0 |= 0x00100000;
|
||||||
|
result = ((long long int) i0 << (j0 - 20)) | (i1 >> (52 - j0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (long long int) x;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sx ? -result : result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* _DOUBLE_IS_32BITS */
|
|
@ -0,0 +1,101 @@
|
||||||
|
/* lrintf adapted to be llrintf for Newlib, 2009 by Craig Howland. */
|
||||||
|
/* @(#)sf_lrint.c 5.1 93/09/24 */
|
||||||
|
/*
|
||||||
|
* ====================================================
|
||||||
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||||
|
* Permission to use, copy, modify, and distribute this
|
||||||
|
* software is freely granted, provided that this notice
|
||||||
|
* is preserved.
|
||||||
|
* ====================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* llrintf(x)
|
||||||
|
* Return x rounded to integral value according to the prevailing
|
||||||
|
* rounding mode.
|
||||||
|
* Method:
|
||||||
|
* Using floating addition.
|
||||||
|
* Exception:
|
||||||
|
* Inexact flag raised if x not equal to llrintf(x).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "fdlibm.h"
|
||||||
|
|
||||||
|
#ifdef __STDC__
|
||||||
|
static const float
|
||||||
|
#else
|
||||||
|
static float
|
||||||
|
#endif
|
||||||
|
/* Adding a float, x, to 2^23 will cause the result to be rounded based on
|
||||||
|
the fractional part of x, according to the implementation's current rounding
|
||||||
|
mode. 2^23 is the smallest float that can be represented using all 23 significant
|
||||||
|
digits. */
|
||||||
|
TWO23[2]={
|
||||||
|
8.3886080000e+06, /* 0x4b000000 */
|
||||||
|
-8.3886080000e+06, /* 0xcb000000 */
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __STDC__
|
||||||
|
long long int llrintf(float x)
|
||||||
|
#else
|
||||||
|
long long int llrintf(x)
|
||||||
|
float x;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
__int32_t j0,sx;
|
||||||
|
__uint32_t i0;
|
||||||
|
float t;
|
||||||
|
volatile float w;
|
||||||
|
long long int result;
|
||||||
|
|
||||||
|
GET_FLOAT_WORD(i0,x);
|
||||||
|
|
||||||
|
/* Extract sign bit. */
|
||||||
|
sx = (i0 >> 31);
|
||||||
|
|
||||||
|
/* Extract exponent field. */
|
||||||
|
j0 = ((i0 & 0x7f800000) >> 23) - 127;
|
||||||
|
|
||||||
|
if (j0 < (int)(sizeof (long long int) * 8) - 1)
|
||||||
|
{
|
||||||
|
if (j0 < -1)
|
||||||
|
return 0;
|
||||||
|
else if (j0 >= 23)
|
||||||
|
result = (long long int) ((i0 & 0x7fffff) | 0x800000) << (j0 - 23);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
w = TWO23[sx] + x;
|
||||||
|
t = w - TWO23[sx];
|
||||||
|
GET_FLOAT_WORD (i0, t);
|
||||||
|
/* Detect the all-zeros representation of plus and
|
||||||
|
minus zero, which fails the calculation below. */
|
||||||
|
if ((i0 & ~(1 << 31)) == 0)
|
||||||
|
return 0;
|
||||||
|
j0 = ((i0 >> 23) & 0xff) - 0x7f;
|
||||||
|
i0 &= 0x7fffff;
|
||||||
|
i0 |= 0x800000;
|
||||||
|
result = i0 >> (23 - j0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (long long int) x;
|
||||||
|
}
|
||||||
|
return sx ? -result : result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _DOUBLE_IS_32BITS
|
||||||
|
|
||||||
|
#ifdef __STDC__
|
||||||
|
long long int llrint(double x)
|
||||||
|
#else
|
||||||
|
long long int llrint(x)
|
||||||
|
double x;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
return llrintf((float) x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined(_DOUBLE_IS_32BITS) */
|
Loading…
Reference in New Issue