diff options
author | Thomas Fitzsimmons <fitzsim@redhat.com> | 2002-06-07 21:59:57 +0000 |
---|---|---|
committer | Thomas Fitzsimmons <fitzsim@redhat.com> | 2002-06-07 21:59:57 +0000 |
commit | 0953fe640f177b565578ed7ecc77169ec1a914fa (patch) | |
tree | f63c2a55e4d0e5a067da91cea95ae88a7c15af7e /newlib/libm/common | |
parent | 2bd6505b3991588a15c865618e1edb76d4a6373c (diff) | |
download | cygnal-0953fe640f177b565578ed7ecc77169ec1a914fa.tar.gz cygnal-0953fe640f177b565578ed7ecc77169ec1a914fa.tar.bz2 cygnal-0953fe640f177b565578ed7ecc77169ec1a914fa.zip |
* libm/common/s_fdim.c: New file.
* libm/common/s_fma.c: Likewise.
* libm/common/s_fmax.c: Likewise.
* libm/common/s_fmin.c: Likewise.
* libm/common/s_fpclassify.c: Likewise.
* libm/common/s_lrint.c: Likewise.
* libm/common/s_lround.c: Likewise.
* libm/common/s_nearbyint.c: Likewise.
* libm/common/s_remquo.c: Likewise.
* libm/common/s_round.c: Likewise.
* libm/common/s_scalbln.c: Likewise.
* libm/common/s_signbit.c: Likewise.
* libm/common/s_trunc.c: Likewise.
* libm/common/sf_fdim.c: Likewise.
* libm/common/sf_fma.c: Likewise.
* libm/common/sf_fmax.c: Likewise.
* libm/common/sf_fmin.c: Likewise.
* libm/common/sf_lrint.c: Likewise.
* libm/common/sf_lround.c: Likewise.
* libm/common/sf_nearbyint.c: Likewise.
* libm/common/sf_remquo.c: Likewise.
* libm/common/sf_round.c: Likewise.
* libm/common/sf_scalbln.c: Likewise.
* libm/common/sf_trunc.c: Likewise.
* libm/math/w_exp2.c: Likewise.
* libm/math/w_tgamma.c: Likewise.
* libm/math/wf_exp2.c: Likewise.
* libm/math/wf_tgamma.c: Likewise.
* libm/mathfp/s_exp2.c: Likewise.
* libm/mathfp/s_tgamma.c: Likewise.
* libm/mathfp/sf_exp2.c: Likewise.
* libm/mathfp/sf_tgamma.c: Likewise.
* libm/math/er_gamma.c: Fix return value.
* libm/math/erf_gamma.c: Likewise.
* libm/mathfp/er_gamma.c: Likewise.
* libm/mathfp/erf_gamma.c: Likewise.
* libc/include/math.h (!__STRICT_ANSI__): Include ISOC99-specific
declarations and macros.
Regenerated all Makefile.in, aclocal.m4 and configure files to
use new libtool macros in top-level libtool.m4
Diffstat (limited to 'newlib/libm/common')
26 files changed, 1302 insertions, 16 deletions
diff --git a/newlib/libm/common/Makefile.am b/newlib/libm/common/Makefile.am index f044894d2..685219dd0 100644 --- a/newlib/libm/common/Makefile.am +++ b/newlib/libm/common/Makefile.am @@ -7,12 +7,18 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \ s_cbrt.c s_expm1.c s_ilogb.c \ s_infinity.c s_log1p.c s_nan.c s_nextafter.c \ - s_rint.c s_logb.c s_matherr.c s_lib_ver.c + s_rint.c s_logb.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_lround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \ + s_signbit.c s_trunc.c fsrc = sf_finite.c sf_copysign.c sf_modf.c sf_scalbn.c \ sf_cbrt.c sf_expm1.c sf_ilogb.c \ sf_infinity.c sf_log1p.c sf_nan.c sf_nextafter.c \ - sf_rint.c sf_logb.c + sf_rint.c sf_logb.c \ + sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_lrint.c \ + sf_lround.c sf_nearbyint.c sf_remquo.c sf_round.c \ + sf_scalbln.c sf_trunc.c libcommon_la_LDFLAGS = -Xcompiler -nostdlib diff --git a/newlib/libm/common/Makefile.in b/newlib/libm/common/Makefile.in index e24a661f5..44ae1d3a2 100644 --- a/newlib/libm/common/Makefile.in +++ b/newlib/libm/common/Makefile.in @@ -68,8 +68,12 @@ AR = @AR@ AS = @AS@ CC = @CC@ CPP = @CPP@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ DLLTOOL = @DLLTOOL@ EXEEXT = @EXEEXT@ +GCJ = @GCJ@ +GCJFLAGS = @GCJFLAGS@ LDFLAGS = @LDFLAGS@ LIBM_MACHINE_LIB = @LIBM_MACHINE_LIB@ LIBTOOL = @LIBTOOL@ @@ -78,8 +82,10 @@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ NEWLIB_CFLAGS = @NEWLIB_CFLAGS@ OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ RANLIB = @RANLIB@ +STRIP = @STRIP@ VERSION = @VERSION@ aext = @aext@ libm_machine_dir = @libm_machine_dir@ @@ -95,13 +101,19 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \ s_cbrt.c s_expm1.c s_ilogb.c \ s_infinity.c s_log1p.c s_nan.c s_nextafter.c \ - s_rint.c s_logb.c s_matherr.c s_lib_ver.c + s_rint.c s_logb.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_lround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \ + s_signbit.c s_trunc.c fsrc = sf_finite.c sf_copysign.c sf_modf.c sf_scalbn.c \ sf_cbrt.c sf_expm1.c sf_ilogb.c \ sf_infinity.c sf_log1p.c sf_nan.c sf_nextafter.c \ - sf_rint.c sf_logb.c + sf_rint.c sf_logb.c \ + sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_lrint.c \ + sf_lround.c sf_nearbyint.c sf_remquo.c sf_round.c \ + sf_scalbln.c sf_trunc.c libcommon_la_LDFLAGS = -Xcompiler -nostdlib @@ -134,13 +146,32 @@ DEFS = @DEFS@ -I. -I$(srcdir) CPPFLAGS = @CPPFLAGS@ LIBS = @LIBS@ lib_a_LIBADD = -@USE_LIBTOOL_FALSE@lib_a_OBJECTS = s_finite.o s_copysign.o s_modf.o \ -@USE_LIBTOOL_FALSE@s_scalbn.o s_cbrt.o s_expm1.o s_ilogb.o s_infinity.o \ -@USE_LIBTOOL_FALSE@s_log1p.o s_nan.o s_nextafter.o s_rint.o s_logb.o \ -@USE_LIBTOOL_FALSE@s_matherr.o s_lib_ver.o sf_finite.o sf_copysign.o \ -@USE_LIBTOOL_FALSE@sf_modf.o sf_scalbn.o sf_cbrt.o sf_expm1.o \ -@USE_LIBTOOL_FALSE@sf_ilogb.o sf_infinity.o sf_log1p.o sf_nan.o \ -@USE_LIBTOOL_FALSE@sf_nextafter.o sf_rint.o sf_logb.o +@USE_LIBTOOL_FALSE@lib_a_OBJECTS = s_finite.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_copysign.$(OBJEXT) s_modf.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_scalbn.$(OBJEXT) s_cbrt.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_expm1.$(OBJEXT) s_ilogb.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_infinity.$(OBJEXT) s_log1p.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_nan.$(OBJEXT) s_nextafter.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_rint.$(OBJEXT) s_logb.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_matherr.$(OBJEXT) s_lib_ver.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_fdim.$(OBJEXT) s_fma.$(OBJEXT) s_fmax.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_fmin.$(OBJEXT) s_fpclassify.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_lrint.$(OBJEXT) s_lround.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_nearbyint.$(OBJEXT) s_remquo.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_round.$(OBJEXT) s_scalbln.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@s_signbit.$(OBJEXT) s_trunc.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_finite.$(OBJEXT) sf_copysign.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_modf.$(OBJEXT) sf_scalbn.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_cbrt.$(OBJEXT) sf_expm1.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_ilogb.$(OBJEXT) sf_infinity.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_log1p.$(OBJEXT) sf_nan.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_nextafter.$(OBJEXT) sf_rint.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_logb.$(OBJEXT) sf_fdim.$(OBJEXT) sf_fma.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_fmax.$(OBJEXT) sf_fmin.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_lrint.$(OBJEXT) sf_lround.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_nearbyint.$(OBJEXT) sf_remquo.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_round.$(OBJEXT) sf_scalbln.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sf_trunc.$(OBJEXT) LTLIBRARIES = $(noinst_LTLIBRARIES) libcommon_la_LIBADD = @@ -148,10 +179,15 @@ libcommon_la_LIBADD = @USE_LIBTOOL_TRUE@s_modf.lo s_scalbn.lo s_cbrt.lo s_expm1.lo s_ilogb.lo \ @USE_LIBTOOL_TRUE@s_infinity.lo s_log1p.lo s_nan.lo s_nextafter.lo \ @USE_LIBTOOL_TRUE@s_rint.lo s_logb.lo s_matherr.lo s_lib_ver.lo \ -@USE_LIBTOOL_TRUE@sf_finite.lo sf_copysign.lo sf_modf.lo sf_scalbn.lo \ -@USE_LIBTOOL_TRUE@sf_cbrt.lo sf_expm1.lo sf_ilogb.lo sf_infinity.lo \ -@USE_LIBTOOL_TRUE@sf_log1p.lo sf_nan.lo sf_nextafter.lo sf_rint.lo \ -@USE_LIBTOOL_TRUE@sf_logb.lo +@USE_LIBTOOL_TRUE@s_fdim.lo s_fma.lo s_fmax.lo s_fmin.lo \ +@USE_LIBTOOL_TRUE@s_fpclassify.lo s_lrint.lo s_lround.lo s_nearbyint.lo \ +@USE_LIBTOOL_TRUE@s_remquo.lo s_round.lo s_scalbln.lo s_signbit.lo \ +@USE_LIBTOOL_TRUE@s_trunc.lo sf_finite.lo sf_copysign.lo sf_modf.lo \ +@USE_LIBTOOL_TRUE@sf_scalbn.lo sf_cbrt.lo sf_expm1.lo sf_ilogb.lo \ +@USE_LIBTOOL_TRUE@sf_infinity.lo sf_log1p.lo sf_nan.lo sf_nextafter.lo \ +@USE_LIBTOOL_TRUE@sf_rint.lo sf_logb.lo sf_fdim.lo sf_fma.lo sf_fmax.lo \ +@USE_LIBTOOL_TRUE@sf_fmin.lo sf_lrint.lo sf_lround.lo sf_nearbyint.lo \ +@USE_LIBTOOL_TRUE@sf_remquo.lo sf_round.lo sf_scalbln.lo sf_trunc.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -171,7 +207,7 @@ OBJECTS = $(lib_a_OBJECTS) $(libcommon_la_OBJECTS) all: all-redirect .SUFFIXES: -.SUFFIXES: .S .c .def .lo .o .s +.SUFFIXES: .S .c .def .lo .o .obj .s $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) $(srcdir)/../../Makefile.shared cd $(top_srcdir) && $(AUTOMAKE) --cygnus common/Makefile @@ -192,6 +228,11 @@ maintainer-clean-noinstLIBRARIES: .c.o: $(COMPILE) -c $< +# FIXME: We should only use cygpath when building on Windows, +# and only if it is available. +.c.obj: + $(COMPILE) -c `cygpath -w $<` + .s.o: $(COMPILE) -c $< @@ -200,6 +241,7 @@ maintainer-clean-noinstLIBRARIES: mostlyclean-compile: -rm -f *.o core *.core + -rm -f *.$(OBJEXT) clean-compile: diff --git a/newlib/libm/common/s_fdim.c b/newlib/libm/common/s_fdim.c new file mode 100644 index 000000000..0010bf59d --- /dev/null +++ b/newlib/libm/common/s_fdim.c @@ -0,0 +1,26 @@ +/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double fdim(double x, double y) +#else + double fdim(x,y) + double x; + double y; +#endif +{ + int c = __fpclassifyd(x); + if (c == FP_NAN || c == FP_INFINITE) + return HUGE_VAL; + + return x > y ? x - y : 0.0; +} + +#endif /* _DOUBLE_IS_32BITS */ diff --git a/newlib/libm/common/s_fma.c b/newlib/libm/common/s_fma.c new file mode 100644 index 000000000..86958afcb --- /dev/null +++ b/newlib/libm/common/s_fma.c @@ -0,0 +1,18 @@ +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double fma(double x, double y, double z) +#else + double fma(x,y) + double x; + double y; + double z; +#endif +{ + /* Implementation defined. */ + return (x * y) + z; +} + +#endif /* _DOUBLE_IS_32BITS */ diff --git a/newlib/libm/common/s_fmax.c b/newlib/libm/common/s_fmax.c new file mode 100644 index 000000000..2de04efab --- /dev/null +++ b/newlib/libm/common/s_fmax.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double fmax(double x, double y) +#else + double fmax(x,y) + double x; + double y; +#endif +{ + if (__fpclassifyd(x) == FP_NAN) + return x; + if (__fpclassifyd(y) == FP_NAN) + return y; + + return x > y ? x : y; +} + +#endif /* _DOUBLE_IS_32BITS */ diff --git a/newlib/libm/common/s_fmin.c b/newlib/libm/common/s_fmin.c new file mode 100644 index 000000000..f9eb51cdd --- /dev/null +++ b/newlib/libm/common/s_fmin.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double fmin(double x, double y) +#else + double fmin(x,y) + double x; + double y; +#endif +{ + if (__fpclassifyd(x) == FP_NAN) + return x; + if (__fpclassifyd(y) == FP_NAN) + return y; + + return x < y ? x : y; +} + +#endif /* _DOUBLE_IS_32BITS */ diff --git a/newlib/libm/common/s_fpclassify.c b/newlib/libm/common/s_fpclassify.c new file mode 100644 index 000000000..0911915ff --- /dev/null +++ b/newlib/libm/common/s_fpclassify.c @@ -0,0 +1,52 @@ +/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include "fdlibm.h" + +int +__fpclassifyf (float x) +{ + unsigned int w; + + GET_FLOAT_WORD(w,x); + + if (w == 0x00000000 || w == 0x80000000) + return FP_ZERO; + else if ((w >= 0x00800000 && w <= 0x7f7fffff) || + (w >= 0xff7fffff && w <= 0x80800000)) + return FP_NORMAL; + else if ((w >= 0x00000001 && w <= 0x007fffff) || + (w >= 0x807fffff && w <= 0x80000001)) + return FP_SUBNORMAL; + else if (w == 0x7f800000 || w == 0xff800000) + return FP_INFINITE; + else + return FP_NAN; +} + +int +__fpclassifyd (double x) +{ + unsigned int msw, lsw; + + EXTRACT_WORDS(msw,lsw,x); + + if ((msw == 0x00000000 && lsw == 0x00000000) || + (msw == 0x80000000 && lsw == 0x00000000)) + return FP_ZERO; + else if ((msw >= 0x00100000 && msw <= 0x7fefffff) || + (msw >= 0xffefffff && msw <= 0x80100000)) + return FP_NORMAL; + else if ((msw >= 0x00000000 && msw <= 0x000fffff) || + (msw >= 0x800fffff && msw <= 0x80000000)) + /* zero is already handled above */ + return FP_SUBNORMAL; + else if ((msw == 0x7ff00000 && lsw == 0x00000000) || + (msw == 0xfff00000 && lsw == 0x00000000)) + return FP_INFINITE; + else + return FP_NAN; +} diff --git a/newlib/libm/common/s_lrint.c b/newlib/libm/common/s_lrint.c new file mode 100644 index 000000000..541bf2c7e --- /dev/null +++ b/newlib/libm/common/s_lrint.c @@ -0,0 +1,98 @@ + +/* @(#)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. + * ==================================================== + */ + +/* + * lrint(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 lrint(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 */ +}; + +#ifdef __STDC__ + long int lrint(double x) +#else + long int lrint(x) + double x; +#endif +{ + __int32_t i0,j0,sx; + __uint32_t i1; + double t; + volatile double w; + long int result; + + EXTRACT_WORDS(i0,i1,x); + sx = (i0>>31)&1; + 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); + j0 = ((i0 & 0x7ff00000) >> 20) - 1023; + i0 &= 0x000fffff; + i0 |= 0x00100000; + result = i0 >> (20 - j0); + } + } + else if (j0 < (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 & 0x7ff00000) >> 20) - 1023; + i0 &= 0x000fffff; + i0 |= 0x00100000; + result = ((long int) i0 << (j0 - 20)) | (i1 >> (52 - j0)); + } + } + else + { + return (long int) x; + } + + return sx ? -result : result; +} + +#endif /* _DOUBLE_IS_32BITS */ diff --git a/newlib/libm/common/s_lround.c b/newlib/libm/common/s_lround.c new file mode 100644 index 000000000..7bd249f9c --- /dev/null +++ b/newlib/libm/common/s_lround.c @@ -0,0 +1,71 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + long int lround(double x) +#else + long int lround(x) + double x; +#endif +{ + __int32_t sign, exponent_less_1023; + /* Most significant word, least significant word. */ + __uint32_t msw, lsw; + long int result; + + EXTRACT_WORDS(msw, lsw, x); + + /* Extract sign. */ + sign = ((msw & 0x80000000) ? -1 : 1); + /* Extract exponent field. */ + exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023; + msw &= 0x000fffff; + msw |= 0x00100000; + + if (exponent_less_1023 < 20) + { + if (exponent_less_1023 < 0) + { + if (exponent_less_1023 < -1) + return 0; + else + return sign; + } + else + { + msw += 0x80000 >> exponent_less_1023; + result = msw >> (20 - exponent_less_1023); + } + } + else if (exponent_less_1023 < (8 * sizeof (long int)) - 1) + { + if (exponent_less_1023 >= 52) + result = ((long int) msw << (exponent_less_1023 - 20)) | (lsw << (exponent_less_1023 - 52)); + else + { + unsigned int tmp = lsw + (0x80000000 >> (exponent_less_1023 - 20)); + if (tmp < lsw) + ++msw; + result = ((long int) msw << (exponent_less_1023 - 20)) | (tmp >> (52 - exponent_less_1023)); + } + } + else + /* Result is too large to be represented by a long int. */ + return (long int)x; + + return sign * result; +} + +#endif /* _DOUBLE_IS_32BITS */ diff --git a/newlib/libm/common/s_nearbyint.c b/newlib/libm/common/s_nearbyint.c new file mode 100644 index 000000000..25e629b65 --- /dev/null +++ b/newlib/libm/common/s_nearbyint.c @@ -0,0 +1,27 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +#include <math.h> +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double nearbyint(double x) +#else + double nearbyint(x) + double x; +#endif +{ + return rint(x); +} + +#endif /* _DOUBLE_IS_32BITS */ diff --git a/newlib/libm/common/s_remquo.c b/newlib/libm/common/s_remquo.c new file mode 100644 index 000000000..bd52f39fc --- /dev/null +++ b/newlib/libm/common/s_remquo.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double remquo(double x, double y, int *quo) /* wrapper remquo */ +#else + double remquo(x,y,quo) /* wrapper remquo */ + double x,y; + int *quo; +#endif +{ + int signx, signy, signres; + int mswx; + int mswy; + double x_over_y; + + GET_HIGH_WORD(mswx, x); + GET_HIGH_WORD(mswy, y); + + signx = (mswx & 0x80000000) >> 31; + signy = (mswy & 0x80000000) >> 31; + + signres = (signx ^ signy) ? -1 : 1; + + x_over_y = fabs(x / y); + + *quo = signres * (lrint(x_over_y) & 0x7f); + + return remainder(x,y); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/common/s_round.c b/newlib/libm/common/s_round.c new file mode 100644 index 000000000..09f19de64 --- /dev/null +++ b/newlib/libm/common/s_round.c @@ -0,0 +1,83 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double round(double x) +#else + double round(x) + double x; +#endif +{ + /* Most significant word, least significant word. */ + __int32_t msw, exponent_less_1023; + __uint32_t lsw; + + EXTRACT_WORDS(msw, lsw, x); + + /* Extract exponent field. */ + exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023; + + if (exponent_less_1023 < 20) + { + if (exponent_less_1023 < 0) + { + msw &= 0x80000000; + if (exponent_less_1023 == -1) + /* Result is +1.0 or -1.0. */ + msw |= (1023 << 20); + lsw = 0; + } + else + { + __uint32_t exponent_mask = 0x000fffff >> exponent_less_1023; + if ((msw & exponent_mask) == 0 && lsw == 0) + /* x in an integral value. */ + return x; + + msw += 0x00080000 >> exponent_less_1023; + msw &= ~exponent_mask; + lsw = 0; + } + } + else if (exponent_less_1023 > 51) + { + if (exponent_less_1023 == 1024) + /* x is NaN or infinite. */ + return x + x; + else + return x; + } + else + { + __uint32_t exponent_mask = 0xffffffff >> (exponent_less_1023 - 20); + __uint32_t tmp; + + if ((lsw & exponent_mask) == 0) + /* x is an integral value. */ + return x; + + tmp = lsw + (1 << (51 - exponent_less_1023)); + if (tmp < lsw) + msw += 1; + lsw = tmp; + + lsw &= ~exponent_mask; + } + INSERT_WORDS(x, msw, lsw); + + return x; +} + +#endif /* _DOUBLE_IS_32BITS */ diff --git a/newlib/libm/common/s_scalbln.c b/newlib/libm/common/s_scalbln.c new file mode 100644 index 000000000..5af9d89e7 --- /dev/null +++ b/newlib/libm/common/s_scalbln.c @@ -0,0 +1,64 @@ +/* @(#)s_scalbn.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. + * ==================================================== + */ + +/* + * scalbn (double x, int n) + * scalbn(x,n) returns x* 2**n computed by exponent + * manipulation rather than by actually performing an + * exponentiation or a multiplication. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ +twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ +huge = 1.0e+300, +tiny = 1.0e-300; + +#ifdef __STDC__ + double scalbln (double x, long int n) +#else + double scalbln (x,n) + double x; long int n; +#endif +{ + __int32_t k,hx,lx; + EXTRACT_WORDS(hx,lx,x); + k = (hx&0x7ff00000)>>20; /* extract exponent */ + if (k==0) { /* 0 or subnormal x */ + if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */ + x *= two54; + GET_HIGH_WORD(hx,x); + k = ((hx&0x7ff00000)>>20) - 54; + } + if (k==0x7ff) return x+x; /* NaN or Inf */ + k = k+n; + if (n> 50000 || k > 0x7fe) + return huge*copysign(huge,x); /* overflow */ + if (n< -50000) return tiny*copysign(tiny,x); /*underflow*/ + if (k > 0) /* normal result */ + {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;} + if (k <= -54) + return tiny*copysign(tiny,x); /*underflow*/ + k += 54; /* subnormal result */ + SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); + return x*twom54; +} + +#endif /* _DOUBLE_IS_32BITS */ diff --git a/newlib/libm/common/s_signbit.c b/newlib/libm/common/s_signbit.c new file mode 100644 index 000000000..d7d49cbb1 --- /dev/null +++ b/newlib/libm/common/s_signbit.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include "fdlibm.h" + +int __signbitf (float x); +int __signbitd (double x); + +int +__signbitf (float x) +{ + unsigned int w; + + GET_FLOAT_WORD(w,x); + + return (w & 0x80000000); +} + +int +__signbitd (double x) +{ + unsigned int msw; + + GET_HIGH_WORD(msw, x); + + return (msw & 0x80000000); +} diff --git a/newlib/libm/common/s_trunc.c b/newlib/libm/common/s_trunc.c new file mode 100644 index 000000000..c3ca154d9 --- /dev/null +++ b/newlib/libm/common/s_trunc.c @@ -0,0 +1,69 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double trunc(double x) +#else + double trunc(x) + double x; +#endif +{ + int signbit; + /* Most significant word, least significant word. */ + int msw; + unsigned int lsw; + int exponent_less_1023; + + EXTRACT_WORDS(msw, lsw, x); + + /* Extract sign bit. */ + signbit = msw & 0x80000000; + + /* Extract exponent field. */ + exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023; + + if (exponent_less_1023 < 20) + { + /* All significant digits are in msw. */ + if (exponent_less_1023 < 0) + { + /* -1 < x < 1, so result is +0 or -0. */ + INSERT_WORDS(x, signbit, 0); + } + else + { + /* All relevant fraction bits are in msw, so lsw of the result is 0. */ + INSERT_WORDS(x, signbit | (msw & ~(0x000fffff >> exponent_less_1023)), 0); + } + } + else if (exponent_less_1023 > 51) + { + if (exponent_less_1023 == 1024) + { + /* x is infinite, or not a number, so trigger an exception. */ + return x + x; + } + /* All bits in the fraction fields of the msw and lsw are needed in the result. */ + } + else + { + /* All fraction bits in msw are relevant. Truncate irrelevant + bits from lsw. */ + INSERT_WORDS(x, msw, lsw & ~(0xffffffffu >> (exponent_less_1023 - 20))); + } + return x; +} + +#endif /* _DOUBLE_IS_32BITS */ diff --git a/newlib/libm/common/sf_fdim.c b/newlib/libm/common/sf_fdim.c new file mode 100644 index 000000000..80221ace1 --- /dev/null +++ b/newlib/libm/common/sf_fdim.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + float fdimf(float x, float y) +#else + float fdimf(x,y) + float x; + float y; +#endif +{ + int c = __fpclassifyf(x); + if (c == FP_NAN || c == FP_INFINITE) + return HUGE_VAL; + + return x > y ? x - y : 0.0; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double fdim(double x, double y) +#else + double fdim(x,y) + double x; + double y; +#endif +{ + return (double) fdimf((float) x, (float) y); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/common/sf_fma.c b/newlib/libm/common/sf_fma.c new file mode 100644 index 000000000..3b4bcc1ce --- /dev/null +++ b/newlib/libm/common/sf_fma.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + float fmaf(float x, float y, float z) +#else + float fmaf(x,y,z) + float x; + float y; + float z; +#endif +{ + /* Let the implementation handle this. */ + return (x * y) + z; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double fma(double x, double y, double z) +#else + double fma(x,y,z) + double x; + double y; + double z; +#endif +{ + return (double) fmaf((float) x, (float) y, (float) z); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/common/sf_fmax.c b/newlib/libm/common/sf_fmax.c new file mode 100644 index 000000000..292b99edf --- /dev/null +++ b/newlib/libm/common/sf_fmax.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + float fmaxf(float x, float y) +#else + float fmaxf(x,y) + float x; + float y; +#endif +{ + if (__fpclassifyf(x) == FP_NAN) + return x; + if (__fpclassifyf(y) == FP_NAN) + return y; + + return x > y ? x : y; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double fmax(double x, double y) +#else + double fmax(x,y) + double x; + double y; +#endif +{ + return (double) fmaxf((float) x, (float) y); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/common/sf_fmin.c b/newlib/libm/common/sf_fmin.c new file mode 100644 index 000000000..4ef3510aa --- /dev/null +++ b/newlib/libm/common/sf_fmin.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + float fminf(float x, float y) +#else + float fminf(x,y) + float x; + float y; +#endif +{ + if (__fpclassifyf(x) == FP_NAN) + return x; + if (__fpclassifyf(y) == FP_NAN) + return y; + + return x < y ? x : y; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double fmin(double x, double y) +#else + double fmin(x,y) + double x; + double y; +#endif +{ + return (double) fminf((float) x, (float) y); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/common/sf_lrint.c b/newlib/libm/common/sf_lrint.c new file mode 100644 index 000000000..a58508f02 --- /dev/null +++ b/newlib/libm/common/sf_lrint.c @@ -0,0 +1,93 @@ + +/* @(#)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. + * ==================================================== + */ + +/* + * lrintf(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 lrintf(x). + */ + +#include "fdlibm.h" + +#ifdef __STDC__ +static const float +#else +static float +#endif +TWO23[2]={ + 8.3886080000e+06, /* 0x4b000000 */ + -8.3886080000e+06, /* 0xcb000000 */ +}; + +#ifdef __STDC__ + long int lrintf(float x) +#else + long int lrintf(x) + float x; +#endif +{ + __int32_t j0,sx; + __uint32_t i0; + float t; + volatile float w; + long int result; + + GET_FLOAT_WORD(i0,x); + + /* Extract sign bit. */ + sx = (i0 >> 31); + + /* Extract exponent field. */ + j0 = ((i0 & 0x7f800000) >> 23) - 127; + + if (j0 < (sizeof (long int) * 8) - 1) + { + if (j0 < -1) + return 0; + else 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 = i0 >> (23 - j0); + } + } + else + { + return (long int) x; + } + return sx ? -result : result; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + long int lrint(double x) +#else + long int lrint(x) + double x; +#endif +{ + return (double) lrintf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/common/sf_lround.c b/newlib/libm/common/sf_lround.c new file mode 100644 index 000000000..e2e4227e2 --- /dev/null +++ b/newlib/libm/common/sf_lround.c @@ -0,0 +1,62 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + long int lroundf(float x) +#else + long int lroundf(x) + float x; +#endif +{ + __int32_t exponent_less_127; + __uint32_t w; + long int result; + __int32_t sign; + + GET_FLOAT_WORD (w, x); + exponent_less_127 = ((w & 0x7f800000) >> 23) - 127; + sign = (w & 0x80000000) != 0 ? -1 : 1; + w &= 0x7fffff; + w |= 0x800000; + + if (exponent_less_127 < (8 * sizeof (long int)) - 1) + { + if (exponent_less_127 < 0) + return exponent_less_127 < -1 ? 0 : sign; + else if (exponent_less_127 >= 23) + result = (long int) w << (exponent_less_127 - 23); + else + { + w += 0x400000 >> exponent_less_127; + result = w >> (23 - exponent_less_127); + } + } + else + return (long int) x; + + return sign * result; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + long int round(double x) +#else + long int round(x) + double x; +#endif +{ + return (double) roundf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/common/sf_nearbyint.c b/newlib/libm/common/sf_nearbyint.c new file mode 100644 index 000000000..0073b6d65 --- /dev/null +++ b/newlib/libm/common/sf_nearbyint.c @@ -0,0 +1,38 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + + +#include <math.h> +#include "fdlibm.h" + +#ifdef __STDC__ + float nearbyintf(float x) +#else + float nearbyintf(x) + float x; +#endif +{ + return rintf(x); +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double nearbyint(double x) +#else + double nearbyint(x) + double x; +#endif +{ + return (double) nearbyintf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/common/sf_remquo.c b/newlib/libm/common/sf_remquo.c new file mode 100644 index 000000000..f620f518e --- /dev/null +++ b/newlib/libm/common/sf_remquo.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + float remquof(float x, float y, int *quo) /* wrapper remquof */ +#else + float remquof(x,y,quo) /* wrapper remquof */ + float x,y; + int *quo; +#endif +{ + int signx, signy, signres; + int wx; + int wy; + float x_over_y; + + GET_FLOAT_WORD(wx, x); + GET_FLOAT_WORD(wy, y); + + signx = (wx & 0x80000000) >> 31; + signy = (wy & 0x80000000) >> 31; + + signres = (signx ^ signy) ? -1 : 1; + + x_over_y = fabsf(x / y); + + *quo = signres * (lrintf(x_over_y) & 0x7f); + + return remainderf(x,y); +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double remquo(double x, double y, int *quo) /* wrapper remquof */ +#else + double remquo(x,y,quo) /* wrapper remquof */ + double x,y; + int *quo; +#endif +{ + return (double) remquof((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/common/sf_round.c b/newlib/libm/common/sf_round.c new file mode 100644 index 000000000..75a72fe75 --- /dev/null +++ b/newlib/libm/common/sf_round.c @@ -0,0 +1,78 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + float roundf(float x) +#else + float roundf(x) + float x; +#endif +{ + int signbit; + int w; + /* Most significant word, least significant word. */ + int exponent_less_127; + + GET_FLOAT_WORD(w, x); + + /* Extract sign bit. */ + signbit = w & 0x80000000; + + /* Extract exponent field. */ + exponent_less_127 = ((w & 0x7f800000) >> 23) - 127; + + if (exponent_less_127 < 23) + { + if (exponent_less_127 < 0) + { + w &= 0x80000000; + if (exponent_less_127 == -1) + /* Result is +1.0 or -1.0. */ + w |= (127 << 23); + } + else + { + unsigned int exponent_mask = 0x007fffff >> exponent_less_127; + if ((w & exponent_mask) == 0) + /* x has an integral value. */ + return x; + + w += 0x00400000 >> exponent_less_127; + w &= ~exponent_mask; + } + } + else + { + if (exponent_less_127 == 128) + /* x is NaN or infinite. */ + return x + x; + else + return x; + } + SET_FLOAT_WORD(x, w); + return x; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double round(double x) +#else + double round(x) + double x; +#endif +{ + return (double) roundf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/common/sf_scalbln.c b/newlib/libm/common/sf_scalbln.c new file mode 100644 index 000000000..dd4baf56a --- /dev/null +++ b/newlib/libm/common/sf_scalbln.c @@ -0,0 +1,71 @@ +/* s_scalbnf.c -- float version of s_scalbn.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * 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. + * ==================================================== + */ + +#include "fdlibm.h" + +#ifdef __STDC__ +static const float +#else +static float +#endif +two25 = 3.355443200e+07, /* 0x4c000000 */ +twom25 = 2.9802322388e-08, /* 0x33000000 */ +huge = 1.0e+30, +tiny = 1.0e-30; + +#ifdef __STDC__ + float scalblnf (float x, long int n) +#else + float scalblnf (x,n) + float x; long int n; +#endif +{ + __int32_t k,ix; + GET_FLOAT_WORD(ix,x); + k = (ix&0x7f800000)>>23; /* extract exponent */ + if (k==0) { /* 0 or subnormal x */ + if ((ix&0x7fffffff)==0) return x; /* +-0 */ + x *= two25; + GET_FLOAT_WORD(ix,x); + k = ((ix&0x7f800000)>>23) - 25; + } + if (k==0xff) return x+x; /* NaN or Inf */ + k = k+n; + if (n> 50000 || k > 0xfe) + return huge*copysignf(huge,x); /* overflow */ + if (n< -50000) + return tiny*copysignf(tiny,x); /*underflow*/ + if (k > 0) /* normal result */ + {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;} + if (k <= -25) + return tiny*copysignf(tiny,x); /*underflow*/ + k += 25; /* subnormal result */ + SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); + return x*twom25; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double scalbln (double x, long int n) +#else + double scalbln (x,n) + double x; long int n; +#endif +{ + return (double) scalblnf((float) x, n); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/common/sf_trunc.c b/newlib/libm/common/sf_trunc.c new file mode 100644 index 000000000..74ea933ce --- /dev/null +++ b/newlib/libm/common/sf_trunc.c @@ -0,0 +1,66 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + float truncf(float x) +#else + float truncf(x) + float x; +#endif +{ + __int32_t signbit, w, exponent_less_127; + + GET_FLOAT_WORD(w,x); + + /* Extract sign bit. */ + signbit = w & 0x80000000; + + /* Extract exponent field. */ + exponent_less_127 = ((w & 0x7f800000) >> 23) - 127; + + if (exponent_less_127 < 23) + { + if (exponent_less_127 < 0) + { + /* -1 < x < 1, so result is +0 or -0. */ + SET_FLOAT_WORD(x, signbit); + } + else + { + SET_FLOAT_WORD(x, signbit | (w & ~(0x007fffff >> exponent_less_127))); + } + } + else + { + if (exponent_less_127 == 255) + /* x is NaN or infinite. */ + return x + x; + + /* All bits in the fraction field are relevant. */ + } + return x; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double trunc(double x) +#else + double trunc(x) + double x; +#endif +{ + return (double) truncf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ |