Index: /trunk/libc/Config.kmk
===================================================================
--- /trunk/libc/Config.kmk	(revision 3891)
+++ /trunk/libc/Config.kmk	(revision 3892)
@@ -178,5 +178,5 @@
 # Only permit #include <include/emx/bigint.h>.
 TEMPLATE_bldprog = Build programs
-TEMPLATE_bldprog_DEFS = __LIBC_BUILD_PROGRAM__
+TEMPLATE_bldprog_DEFS = __LIBC_BUILD_PROGRAM__ __KLIBC_BUILD_PROGRAM__
 TEMPLATE_bldprog_LIBSUFF = .a
 if defined(CFG_LIBC_USE_WATCOM)
@@ -184,5 +184,8 @@
  TEMPLATE_bldprog_INCS = $(TOOL_OPENWATCOM_CXXINCS) $(PATH_LIBC_ROOT)
  TEMPLATE_bldprog_BLD_TRG_ARCH = x86
- TEMPLATE_bldprog_CFLAGS = -za99 -aa -ecc
+ TEMPLATE_bldprog_CFLAGS = -za99 -aa -ecc -d2
+ TEMPLATE_bldprog_CFLAGS.win = -hc
+ TEMPLATE_bldprog_LDFLAGS = -d2
+ TEMPLATE_bldprog_LDFLAGS.win = -hc
 else
  TEMPLATE_bldprog_TOOL = GCC3
Index: /trunk/libc/include/sys/bsd/cdefs.h
===================================================================
--- /trunk/libc/include/sys/bsd/cdefs.h	(revision 3891)
+++ /trunk/libc/include/sys/bsd/cdefs.h	(revision 3892)
@@ -484,6 +484,10 @@
 #endif	/* __GNUC__ || __INTEL_COMPILER */
 #else                                                                       /* bird */
-#define	__strong_reference(sym,aliassym)	\
+# ifdef __GNUC__                                                            /* bird */
+#  define __strong_reference(sym,aliassym)	\
 	extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)));  /* bird */
+# else                                                                      /* bird */
+#  define __strong_reference(sym,aliassym)	                            /* bird */
+# endif                                                                     /* bird */
 #endif                                                                      /* bird */
 
Index: /trunk/libc/include/sys/cdefs.h
===================================================================
--- /trunk/libc/include/sys/cdefs.h	(revision 3891)
+++ /trunk/libc/include/sys/cdefs.h	(revision 3892)
@@ -122,6 +122,6 @@
  * Include the other cdefs.h  Fortunately, they use different blocker macros.
  */
-#include <sys/bsd/cdefs.h>
-#include <sys/gnu/cdefs.h>
+#include "bsd/cdefs.h"
+#include "gnu/cdefs.h"
 
 /*
Index: /trunk/libc/src/fbsdlibc/gdtoa/gdtoa.h
===================================================================
--- /trunk/libc/src/fbsdlibc/gdtoa/gdtoa.h	(revision 3891)
+++ /trunk/libc/src/fbsdlibc/gdtoa/gdtoa.h	(revision 3892)
@@ -114,6 +114,8 @@
 			int mode, int ndigits, int *decpt, char **rve));
 extern void freedtoa ANSI((char*));
+#ifndef __KLIBC_BUILD_PROGRAM__
 extern float  strtof ANSI((CONST char *, char **));
 extern double strtod ANSI((CONST char *, char **));
+#endif
 extern int strtodg ANSI((CONST char*, char**, FPI*, Long*, ULong*));
 
Index: /trunk/libc/src/fbsdlibc/gdtoa/gdtoaimp.h
===================================================================
--- /trunk/libc/src/fbsdlibc/gdtoa/gdtoaimp.h	(revision 3891)
+++ /trunk/libc/src/fbsdlibc/gdtoa/gdtoaimp.h	(revision 3892)
@@ -195,6 +195,8 @@
 #include "namespace.h"
 #ifdef __IN_KLIBC__
-#include <386/builtin.h>
-#include <sys/fmutex.h>
+# ifndef __KLIBC_BUILD_PROGRAM__
+#  include <386/builtin.h>
+#  include <sys/fmutex.h>
+# endif
 #else /* !__IN_KLIBC__ */
 #include <pthread.h>
@@ -477,6 +479,11 @@
 #endif
 
+#ifdef __KLIBC_BUILD_PROGRAM__
+# undef MULTIPLE_THREADS
+# define ACQUIRE_DTOA_LOCK(n)    do {} while (0)
+# define FREE_DTOA_LOCK(n)       do {} while (0)
+#else
 #define MULTIPLE_THREADS
-#ifdef __IN_KLIBC__
+# ifdef __IN_KLIBC__
 extern _fmutex __libc_gdtoa_locks[2];
 #define ACQUIRE_DTOA_LOCK(n)	do {				\
@@ -488,5 +495,5 @@
     _fmutex_checked_release(&__libc_gdtoa_locks[n]);                 \
 } while(0)
-#else /* !__IN_KLIBC__ */
+# else /* !__IN_KLIBC__ */
 extern pthread_mutex_t __gdtoa_locks[2];
 #define ACQUIRE_DTOA_LOCK(n)	do {				\
@@ -498,5 +505,6 @@
 		_pthread_mutex_unlock(&__gdtoa_locks[n]);	\
 } while(0)
-#endif /* !__IN_KLIBC__ */
+# endif /* !__IN_KLIBC__ */
+#endif /* !__KLIBC_BUILD_PROGRAM__ */
 
 #define Kmax 15
@@ -521,4 +529,6 @@
 #endif /* NO_STRING_H */
 
+#ifndef __KLIBC_BUILD_PROGRAM__
+#error
 /*
  * Paranoia: Protect exported symbols, including ones in files we don't
@@ -603,4 +613,5 @@
 #define	trailz		__trailz_D2A
 #define	ulp		__ulp_D2A
+#endif /* !__KLIBC_BUILD_PROGRAM__ */
 
  extern char *dtoa_result;
Index: /trunk/libc/src/fbsdlibc/gdtoa/glue/machdep_ldisx.c
===================================================================
--- /trunk/libc/src/fbsdlibc/gdtoa/glue/machdep_ldisx.c	(revision 3891)
+++ /trunk/libc/src/fbsdlibc/gdtoa/glue/machdep_ldisx.c	(revision 3892)
@@ -40,6 +40,10 @@
 #endif
 
+#ifdef __KLIBC_BUILD_PROGRAM__
+long double gdtoa_strtold(const char *s, char **sp)
+#else
 long double
 _STD(strtold)(const char * __restrict s, char ** __restrict sp)
+#endif
 {
 	long double result;
Index: /trunk/libc/src/fbsdlibc/gdtoa/strtod.c
===================================================================
--- /trunk/libc/src/fbsdlibc/gdtoa/strtod.c	(revision 3891)
+++ /trunk/libc/src/fbsdlibc/gdtoa/strtod.c	(revision 3892)
@@ -42,4 +42,5 @@
 #define Avoid_Underflow
 #undef tinytens
+#define tinytens local_tinytens /* bird - scope changed. */
 /* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */
 /* flag unnecessarily.  It leads to a song and dance at the end of strtod. */
@@ -58,4 +59,7 @@
 #endif
 
+#ifdef __KLIBC_BUILD_PROGRAM__
+double gdtoa_strtod(const char *s00, char **se)
+#else /* !__KLIBC_BUILD_PROGRAM__ */
  double
 #ifdef __IN_KLIBC__
@@ -69,4 +73,5 @@
 	(CONST char *s00, char **se)
 #endif
+#endif /* !__KLIBC_BUILD_PROGRAM__ */
 {
 #ifdef Avoid_Underflow
Index: /trunk/libc/src/fbsdlibc/gdtoa/strtof.c
===================================================================
--- /trunk/libc/src/fbsdlibc/gdtoa/strtof.c	(revision 3891)
+++ /trunk/libc/src/fbsdlibc/gdtoa/strtof.c	(revision 3892)
@@ -39,4 +39,7 @@
 #include <stdlib.h>
 
+#ifdef __KLIBC_BUILD_PROGRAM__
+float gdtoa_strtof(const char *s, char **sp)
+#else
  float
 #ifdef KR_headers
@@ -44,4 +47,5 @@
 #else
 _STD(strtof)(CONST char *s, char **sp)
+#endif
 #endif
 {
Index: /trunk/libc/src/fbsdlibc/include/fpmath.h
===================================================================
--- /trunk/libc/src/fbsdlibc/include/fpmath.h	(revision 3891)
+++ /trunk/libc/src/fbsdlibc/include/fpmath.h	(revision 3892)
@@ -30,4 +30,8 @@
 #include <sys/endian.h>
 #include "_fpmath.h"
+
+#ifdef __WATCOMC__
+# define huge myhuge /* huge is a reserved keyword. Used for constants by the sources. */
+#endif
 
 union IEEEf2bits {
Index: /trunk/libc/src/msun/Makefile.kmk
===================================================================
--- /trunk/libc/src/msun/Makefile.kmk	(revision 3891)
+++ /trunk/libc/src/msun/Makefile.kmk	(revision 3892)
@@ -108,10 +108,4 @@
 	$(PATH_LIBC_SRC)/msun/src/s_ceilf.c \
 	$(PATH_LIBC_SRC)/msun/src/s_ceill.c \
-	$(PATH_LIBC_SRC)/msun/src/s_cimag.c \
-	$(PATH_LIBC_SRC)/msun/src/s_cimagf.c \
-	$(PATH_LIBC_SRC)/msun/src/s_cimagl.c \
-	$(PATH_LIBC_SRC)/msun/src/s_conj.c \
-	$(PATH_LIBC_SRC)/msun/src/s_conjf.c \
-	$(PATH_LIBC_SRC)/msun/src/s_conjl.c \
 	$(PATH_LIBC_SRC)/msun/src/s_copysign.c \
 	$(PATH_LIBC_SRC)/msun/src/s_copysignf.c \
@@ -119,7 +113,4 @@
 	$(PATH_LIBC_SRC)/msun/src/s_cos.c \
 	$(PATH_LIBC_SRC)/msun/src/s_cosf.c \
-	$(PATH_LIBC_SRC)/msun/src/s_creal.c \
-	$(PATH_LIBC_SRC)/msun/src/s_crealf.c \
-	$(PATH_LIBC_SRC)/msun/src/s_creall.c \
 	$(PATH_LIBC_SRC)/msun/src/s_erf.c \
 	$(PATH_LIBC_SRC)/msun/src/s_erff.c \
@@ -201,8 +192,22 @@
 	$(PATH_LIBC_SRC)/msun/src/s_truncf.c \
 	$(PATH_LIBC_SRC)/msun/src/s_truncl.c \
-	$(PATH_LIBC_SRC)/msun/src/w_cabs.c \
-	$(PATH_LIBC_SRC)/msun/src/w_cabsf.c \
 	$(PATH_LIBC_SRC)/msun/src/w_drem.c \
 	$(PATH_LIBC_SRC)/msun/src/w_dremf.c \
+
+ifndef CFG_LIBC_USE_WATCOM # complex crap
+libc_msun_SOURCES += \
+	$(PATH_LIBC_SRC)/msun/src/s_cimag.c \
+	$(PATH_LIBC_SRC)/msun/src/s_cimagf.c \
+	$(PATH_LIBC_SRC)/msun/src/s_cimagl.c \
+	$(PATH_LIBC_SRC)/msun/src/s_conj.c \
+	$(PATH_LIBC_SRC)/msun/src/s_conjf.c \
+	$(PATH_LIBC_SRC)/msun/src/s_conjl.c \
+	$(PATH_LIBC_SRC)/msun/src/s_creal.c \
+	$(PATH_LIBC_SRC)/msun/src/s_crealf.c \
+	$(PATH_LIBC_SRC)/msun/src/s_creall.c \
+	$(PATH_LIBC_SRC)/msun/src/w_cabs.c \
+	$(PATH_LIBC_SRC)/msun/src/w_cabsf.c
+endif
+
 
 MSUN_ARCH.x86 := \
@@ -274,5 +279,58 @@
 BLDPROGS += hextodecfp
 hextodecfp_TEMPLATE = bldprog
-hextodecfp_SOURCES = hextodecfp.c
+hextodecfp_INCS = hextodecfp-incs
+hextodecfp_SOURCES = \
+	hextodecfp.c \
+       \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/dtoa.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/dmisc.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/gdtoa.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/gethex.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/gmisc.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/hd_init.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/hexnan.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/misc.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/smisc.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtodg.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtodI.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtoId.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtoIdd.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtoIf.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtoIg.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtoIQ.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtoIx.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtoIxL.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtopd.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtopdd.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtopf.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtopQ.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtopx.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtopxL.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtord.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtordd.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtorf.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtorQ.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtorx.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtorxL.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/sum.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/ulp.c \
+       \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/glue/machdep_ldisx.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtof.c \
+	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtod.c \
+
+#	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/g_ddfmt.c \
+#	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/g_dfmt.c \
+#	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/g_ffmt.c \
+#	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/g_Qfmt.c \
+#	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/g_xfmt.c \
+#	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/g_xLfmt.c \
+#	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/g__fmt.c \
+
+#	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/glue/_hdtoa.c \
+#	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/glue/_ldtoa.c \
+#	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/glue/glue.c \
+
+#	$(PATH_LIBC_SRC)/fbsdlibc/gdtoa/strtof.c \
 
 
@@ -280,2 +338,25 @@
 include $(PATH_KBUILD)/subfooter.kmk
 
+
+#
+# For regenerating the decimal constant sources.
+# Requires Watcom or GCC.
+#
+MSUN_HEXADECIMAL_CONSTANT_SOURCES = \
+	$(PATH_LIBC_SRC)/msun/bsdsrc/b_exp.c \
+	$(PATH_LIBC_SRC)/msun/src/s_exp2.c \
+	$(PATH_LIBC_SRC)/msun/src/s_exp2f.c \
+	$(PATH_LIBC_SRC)/msun/src/s_fma.c \
+	$(PATH_LIBC_SRC)/msun/src/s_fmal.c \
+	$(PATH_LIBC_SRC)/msun/src/s_frexpl.c \
+	$(PATH_LIBC_SRC)/msun/src/s_remquo.c \
+	$(PATH_LIBC_SRC)/msun/src/s_remquof.c \
+	$(PATH_LIBC_SRC)/msun/src/s_scalbnl.c \
+
+#$(error x=$(foreach file,$(MSUN_HEXADECIMAL_CONSTANT_SOURCES),$(basename $(file))-decimal-constants.c))
+$(foreach file,$(MSUN_HEXADECIMAL_CONSTANT_SOURCES),$(basename $(file))-decimal-constants.c): \
+		$$(dir $$@)$$(firstword $$(subst -, ,$$(notdir $$@))).c $(hextodecfp_1_TARGET)
+	$(hextodecfp_1_TARGET) -i $< -o $@
+
+msun_decimal_constants: $(foreach file,$(MSUN_HEXADECIMAL_CONSTANT_SOURCES),$(basename $(file))-decimal-constants.c)
+
Index: /trunk/libc/src/msun/bsdsrc/b_exp-decimal-constants.c
===================================================================
--- /trunk/libc/src/msun/bsdsrc/b_exp-decimal-constants.c	(revision 3892)
+++ /trunk/libc/src/msun/bsdsrc/b_exp-decimal-constants.c	(revision 3892)
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 1985, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "b_exp-decimal-constants.c"
+#else
+
+#include "namespace.h"
+#ifndef lint
+static char sccsid[] = "@(#)exp.c	8.1 (Berkeley) 6/4/93";
+#endif /* not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/msun/bsdsrc/b_exp.c,v 1.7 2004/12/16 20:40:37 das Exp $");
+
+
+/* EXP(X)
+ * RETURN THE EXPONENTIAL OF X
+ * DOUBLE PRECISION (IEEE 53 bits, VAX D FORMAT 56 BITS)
+ * CODED IN C BY K.C. NG, 1/19/85;
+ * REVISED BY K.C. NG on 2/6/85, 2/15/85, 3/7/85, 3/24/85, 4/16/85, 6/14/86.
+ *
+ * Required system supported functions:
+ *	scalb(x,n)
+ *	copysign(x,y)
+ *	finite(x)
+ *
+ * Method:
+ *	1. Argument Reduction: given the input x, find r and integer k such
+ *	   that
+ *	                   x = k*ln2 + r,  |r| <= 0.5*ln2 .
+ *	   r will be represented as r := z+c for better accuracy.
+ *
+ *	2. Compute exp(r) by
+ *
+ *		exp(r) = 1 + r + r*R1/(2-R1),
+ *	   where
+ *		R1 = x - x^2*(p1+x^2*(p2+x^2*(p3+x^2*(p4+p5*x^2)))).
+ *
+ *	3. exp(x) = 2^k * exp(r) .
+ *
+ * Special cases:
+ *	exp(INF) is INF, exp(NaN) is NaN;
+ *	exp(-INF)=  0;
+ *	for finite argument, only exp(0)=1 is exact.
+ *
+ * Accuracy:
+ *	exp(x) returns the exponential of x nearly rounded. In a test run
+ *	with 1,156,000 random arguments on a VAX, the maximum observed
+ *	error was 0.869 ulps (units in the last place).
+ */
+
+#include "mathimpl.h"
+
+const static double p1 = 1.6666666666666601903000e-01;
+const static double p2 = -2.7777777777015593384000e-03;
+const static double p3 = 6.6137563214379343610000e-05;
+const static double p4 = -1.6533902205465251538000e-06;
+const static double p5 = 4.1381367970572384603000e-08;
+const static double ln2hi = 6.9314718036912381649000e-01;
+const static double ln2lo = 1.9082149292705877000000e-10;
+const static double lnhuge = 7.1602103751842355450000e+02;
+const static double lntiny = -7.5137154372698068983000e+02;
+const static double invln2 = 1.4426950408889633870000e+00;
+
+#if 0
+double exp(x)
+double x;
+{
+	double  z,hi,lo,c;
+	int k;
+
+#if !defined(vax)&&!defined(tahoe)
+	if(x!=x) return(x);	/* x is NaN */
+#endif	/* !defined(vax)&&!defined(tahoe) */
+	if( x <= lnhuge ) {
+		if( x >= lntiny ) {
+
+		    /* argument reduction : x --> x - k*ln2 */
+
+			k=invln2*x+copysign(0.5,x);	/* k=NINT(x/ln2) */
+
+		    /* express x-k*ln2 as hi-lo and let x=hi-lo rounded */
+
+			hi=x-k*ln2hi;
+			x=hi-(lo=k*ln2lo);
+
+		    /* return 2^k*[1+x+x*c/(2+c)]  */
+			z=x*x;
+			c= x - z*(p1+z*(p2+z*(p3+z*(p4+z*p5))));
+			return  scalb(1.0+(hi-(lo-(x*c)/(2.0-c))),k);
+
+		}
+		/* end of x > lntiny */
+
+		else
+		     /* exp(-big#) underflows to zero */
+		     if(finite(x))  return(scalb(1.0,-5000));
+
+		     /* exp(-INF) is zero */
+		     else return(0.0);
+	}
+	/* end of x < lnhuge */
+
+	else
+	/* exp(INF) is INF, exp(+big#) overflows to INF */
+	    return( finite(x) ?  scalb(1.0,5000)  : x);
+}
+#endif
+
+/* returns exp(r = x + c) for |c| < |x| with no overlap.  */
+
+double __exp__D(x, c)
+double x, c;
+{
+	double  z,hi,lo;
+	int k;
+
+	if (x != x)	/* x is NaN */
+		return(x);
+	if ( x <= lnhuge ) {
+		if ( x >= lntiny ) {
+
+		    /* argument reduction : x --> x - k*ln2 */
+			z = invln2*x;
+			k = z + copysign(.5, x);
+
+		    /* express (x+c)-k*ln2 as hi-lo and let x=hi-lo rounded */
+
+			hi=(x-k*ln2hi);			/* Exact. */
+			x= hi - (lo = k*ln2lo-c);
+		    /* return 2^k*[1+x+x*c/(2+c)]  */
+			z=x*x;
+			c= x - z*(p1+z*(p2+z*(p3+z*(p4+z*p5))));
+			c = (x*c)/(2.0-c);
+
+			return  scalb(1.+(hi-(lo - c)), k);
+		}
+		/* end of x > lntiny */
+
+		else
+		     /* exp(-big#) underflows to zero */
+		     if(finite(x))  return(scalb(1.0,-5000));
+
+		     /* exp(-INF) is zero */
+		     else return(0.0);
+	}
+	/* end of x < lnhuge */
+
+	else
+	/* exp(INF) is INF, exp(+big#) overflows to INF */
+	    return( finite(x) ?  scalb(1.0,5000)  : x);
+}
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/bsdsrc/b_exp.c
===================================================================
--- /trunk/libc/src/msun/bsdsrc/b_exp.c	(revision 3891)
+++ /trunk/libc/src/msun/bsdsrc/b_exp.c	(revision 3892)
@@ -31,4 +31,9 @@
  * SUCH DAMAGE.
  */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "b_exp-decimal-constants.c"
+#else
 
 #include "namespace.h"
@@ -177,2 +182,4 @@
 	    return( finite(x) ?  scalb(1.0,5000)  : x);
 }
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/bsdsrc/b_tgamma.c
===================================================================
--- /trunk/libc/src/msun/bsdsrc/b_tgamma.c	(revision 3891)
+++ /trunk/libc/src/msun/bsdsrc/b_tgamma.c	(revision 3892)
@@ -152,4 +152,7 @@
 		if (x == 0.0)
 			return (one/x);
+#ifdef __WATCOMC__ /* This is not meaningless use of an expression, dear watcom... */
+		volatile double tmp =
+#endif
 		one+1e-20;		/* Raise inexact flag. */
 		return (one/x);
Index: /trunk/libc/src/msun/hextodecfp-incs/arith.h
===================================================================
--- /trunk/libc/src/msun/hextodecfp-incs/arith.h	(revision 3892)
+++ /trunk/libc/src/msun/hextodecfp-incs/arith.h	(revision 3892)
@@ -0,0 +1,4 @@
+#define IEEE_8087
+#define Arith_Kind_ASL 1
+#define Double_Align
+
Index: /trunk/libc/src/msun/hextodecfp-incs/features.h
===================================================================
--- /trunk/libc/src/msun/hextodecfp-incs/features.h	(revision 3892)
+++ /trunk/libc/src/msun/hextodecfp-incs/features.h	(revision 3892)
@@ -0,0 +1,1 @@
+#include "../../../../include/features.h"
Index: /trunk/libc/src/msun/hextodecfp-incs/sys/cdefs.h
===================================================================
--- /trunk/libc/src/msun/hextodecfp-incs/sys/cdefs.h	(revision 3892)
+++ /trunk/libc/src/msun/hextodecfp-incs/sys/cdefs.h	(revision 3892)
@@ -0,0 +1,2 @@
+#include "../../../../include/sys/cdefs.h"
+
Index: /trunk/libc/src/msun/hextodecfp.c
===================================================================
--- /trunk/libc/src/msun/hextodecfp.c	(revision 3891)
+++ /trunk/libc/src/msun/hextodecfp.c	(revision 3892)
@@ -17,9 +17,13 @@
 #include <string.h>
 
+extern float        gdtoa_strtof(const char *, char **);
+extern double       gdtoa_strtod(const char *, char **);
+extern long double  gdtoa_strtold(const char *, char **);
+
 
 static int Error(const char *pszMsg, ...)
 {
     va_list va;
-    fprintf(stderr, "hextodecfp: error: ");
+    fprintf(stderr, "hextodecfp: error! ");
     va_start(va, pszMsg);
     vfprintf(stderr, pszMsg, va);
@@ -33,14 +37,23 @@
     char chSaved = pszInput[cchInput];
 
+#ifndef _MSC_VER
     if (chType == 'l')
     {
-        long double lrd = strtold(pszInput, NULL);
-        sprintf(pszOutput, "%Le", lrd);
-
+        long double lrdIn, lrdOut;
+        lrdIn = gdtoa_strtold(pszInput, NULL);
+        sprintf(pszOutput, "%.22Le", lrdIn);
+        lrdOut = gdtoa_strtold(pszOutput, NULL);
+        if (lrdIn != lrdOut)
+            fprintf(stderr, "hextodecfp: warning! roundtrip failure for '%.*s' (%Le vs %Le)\n", cchInput, pszInput, lrdIn, lrdOut);
     }
     else
-    {
-        double rd = strtod(pszInput, NULL);
-        sprintf(pszOutput, "%e", rd);
+#endif
+    {
+        double rdIn, rdOut;
+        rdIn = gdtoa_strtod(pszInput, NULL);
+        sprintf(pszOutput, "%.22e", rdIn);
+        rdOut = gdtoa_strtod(pszOutput, NULL);
+        if (rdIn != rdOut)
+            fprintf(stderr, "hextodecfp: warning! roundtrip failure for '%.*s' (%e vs %e)\n", cchInput, pszInput, rdIn, rdOut);
     }
 
@@ -65,4 +78,5 @@
         if (*psz == '-')
         {
+            char ch;
             psz++;
 
@@ -79,9 +93,9 @@
 
             /* Process short options. */
-            while (*psz)
+            while ((ch = *psz) != '\0')
             {
                 /* Check out options taking arguments first. */
                 const char *pszValue = NULL;
-                switch (*psz)
+                switch (ch)
                 {
                     case 'i':
@@ -93,5 +107,5 @@
                             i++;
                             if (i >= argc)
-                                return Error("Expected value after -%c.", *psz);
+                                return Error("Expected value after -%c.", ch);
                             pszValue = argv[i];
                         }
@@ -101,5 +115,5 @@
 
                 /* Now the real switch */
-                switch (*psz)
+                switch (ch)
                 {
                     case 'i':
@@ -135,5 +149,5 @@
 
                     default:
-                        return Error("Unknown option -%c.", *psz);
+                        return Error("Unknown option -%c.", ch);
                 }
 
@@ -174,5 +188,5 @@
                 /* Potential hexadecimal floating-point constant. */
                 unsigned u;
-                unsigned off = 1;
+                unsigned off = 2;
                 while (   (u = (unsigned)pszCur[off]) != '\0'
                        && (   (u - (unsigned)'0' <= 9U)
@@ -180,5 +194,5 @@
                            || (u - (unsigned)'A' <= 6U) ) )
                     off++;
-                if (u == '.')
+                if (u == '.' || u == 'p' || u == 'P')
                 {
                     /*
@@ -186,10 +200,12 @@
                      */
                     char chType;
+                    if (u == '.')
+                        off++;
 
                     /* Fraction. */
                     while (   (u = (unsigned)pszCur[off]) != '\0'
                            && (   (u - (unsigned)'0' <= 9U)
-                               || (u - (unsigned)'a' <= 6U)
-                               || (u - (unsigned)'A' <= 6U) ) )
+                               || (u - (unsigned)'a' <= 5U)
+                               || (u - (unsigned)'A' <= 5U) ) )
                         off++;
 
Index: /trunk/libc/src/msun/i387/fenv.c
===================================================================
--- /trunk/libc/src/msun/i387/fenv.c	(revision 3891)
+++ /trunk/libc/src/msun/i387/fenv.c	(revision 3892)
@@ -50,4 +50,38 @@
 #endif
 
+#ifdef __WATCOMC__
+int getfl_worker(void);
+# pragma aux getfl_worker = \
+	"pushfd" \
+	"pop eax" \
+	value [eax]
+# define getfl(x) (*(x) = getfl_worker())
+
+void setfl_worker(int flags);
+# pragma aux setfl_worker = \
+	"push eax" \
+	"popfd" \
+	parm [eax] modify exact
+# define setfl(x) setfl_worker(x)
+
+int cpuid_dx_worker(void);
+# pragma aux getfl_worker = \
+	"mov eax, 1" \
+	"cpuid" \
+	value [edx] modify [eax ebx ecx edx]
+#define cpuid_dx(x) (*(x) = cpuid_dx_worker())
+
+#elif _MSC_VER
+# define getfl(x) ((*x) = __readeflags())
+# define setfl(x) __writeeflags(x)
+static inline int cpuid_dx_worker()
+{
+    int info[4];
+    __cpuid(1, info);
+    return info[3];
+}
+# define cpuid_dx(x) (*(x) = cpuid_dx_worker())
+
+#else
 #define	getfl(x)	__asm __volatile("pushfl\n\tpopl %0" : "=mr" (*(x)))
 #define	setfl(x)	__asm __volatile("pushl %0\n\tpopfl" : : "g" (x))
@@ -55,4 +89,5 @@
 					 "cpuid\n\tpopl %%ebx"		      \
 					: "=d" (*(x)) : : "eax", "ecx")
+#endif
 
 /*
Index: /trunk/libc/src/msun/src/math_private.h
===================================================================
--- /trunk/libc/src/msun/src/math_private.h	(revision 3891)
+++ /trunk/libc/src/msun/src/math_private.h	(revision 3892)
@@ -20,4 +20,12 @@
 #include <sys/types.h>
 #include <machine/endian.h>
+
+#if defined(__WATCOMC__) && defined(__SW_OA)
+# error "The msun sources must be compiled without relaxed aliasing optimization (/oa)."
+#endif
+
+#ifdef __WATCOMC__
+# define huge myhuge /* huge is a reserved keyword. msun uses it for constants. */
+#endif
 
 /*
Index: /trunk/libc/src/msun/src/s_ceill.c
===================================================================
--- /trunk/libc/src/msun/src/s_ceill.c	(revision 3891)
+++ /trunk/libc/src/msun/src/s_ceill.c	(revision 3892)
@@ -57,6 +57,14 @@
 ceill(long double x)
 {
+#ifdef __GNUC__
 	union IEEEl2bits u = { .e = x };
 	int e = u.bits.exp - LDBL_MAX_EXP + 1;
+#else
+	union IEEEl2bits u;
+	int e;
+
+	u.e = x;
+	e = u.bits.exp - LDBL_MAX_EXP + 1;
+#endif
 
 	if (e < MANH_SIZE - 1) {
Index: /trunk/libc/src/msun/src/s_exp2-decimal-constants.c
===================================================================
--- /trunk/libc/src/msun/src/s_exp2-decimal-constants.c	(revision 3892)
+++ /trunk/libc/src/msun/src/s_exp2-decimal-constants.c	(revision 3892)
@@ -0,0 +1,397 @@
+/*-
+ * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_exp2-decimal-constants.c"
+#else
+
+#include "namespace.h"
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/msun/src/s_exp2.c,v 1.1 2005/04/05 02:57:15 das Exp $");
+
+#include "math.h"
+#include "math_private.h"
+
+#define	TBLBITS	8
+#define	TBLSIZE	(1 << TBLBITS)
+
+static const double
+    huge     = 1.0715086071862673210000e+301,
+    twom1000 = 9.3326361850321887900000e-302,
+    redux    = 6.7553994410557440000000e+15 / TBLSIZE,
+    P1	     = 6.9314718055994528622000e-01,
+    P2	     = 2.4022650695910000018000e-01,
+    P3	     = 5.5504108664821402708000e-02,
+    P4	     = 9.6181298421260663645000e-03,
+    P5	     = 1.3333559164630222685000e-03;
+
+static const double tbl[TBLSIZE * 2] = {
+/*	exp2(z + eps)		eps	*/
+	7.0710678118659198165000e-01,	 9.0705221111875289350000e-14,
+	7.0902394216020825368000e-01,	 1.3322676295501878485000e-15,
+	7.1094630108456136063000e-01,	-4.3465231414074878558000e-14,
+	7.1287387205276064872000e-01,	 2.7311486405778850894000e-14,
+	7.1480666919598434549000e-01,	-1.3322676295501878485000e-15,
+	7.1674470668389422822000e-01,	-3.8857805861880478915000e-16,
+	7.1868799872446298415000e-01,	-5.6565863104651725735000e-14,
+	7.2063655956428751547000e-01,	-5.0681681074138396070000e-14,
+	7.2259040348853209589000e-01,	 1.7541523789077473339000e-14,
+	7.2454954482097433388000e-01,	-8.5931262105987116220000e-14,
+	7.2651399792452253656000e-01,	-7.4384942649885488208000e-15,
+	7.2848377720075019325000e-01,	 5.6010751592339147464000e-14,
+	7.3045889709032796321000e-01,	 8.8262730457699944964000e-15,
+	7.3243937207318143833000e-01,	-4.2299497238218464190000e-14,
+	7.3442521666849014394000e-01,	-1.6098233857064769836000e-15,
+	7.3641644543468487427000e-01,	 2.1094237467877974268000e-15,
+	7.3841307296974800777000e-01,	-3.2196467714129539672000e-15,
+	7.4041511391125069962000e-01,	 2.8865798640254070051000e-14,
+	7.4242258293637630739000e-01,	 1.1102230246251565404000e-16,
+	7.4443549476217785176000e-01,	-4.0079051188968151109000e-14,
+	7.4645386414562808763000e-01,	-8.3821838359199318802000e-15,
+	7.4847770588359896493000e-01,	-3.6137759451548845391000e-14,
+	7.5050703481324787524000e-01,	 6.7501559897209517650000e-14,
+	7.5254186581171045311000e-01,	 1.3766765505351941101000e-14,
+	7.5458221379669487838000e-01,	-3.1530333899354445748000e-14,
+	7.5662809372632899851000e-01,	 4.5852210917018965119000e-14,
+	7.5867952059919352425000e-01,	 1.6386891843467310536000e-13,
+	7.6073650945442450321000e-01,	 3.2640556923979602288000e-14,
+	7.6279907537223390345000e-01,	-6.6668892628740650250000e-14,
+	7.6486723347362561842000e-01,	-3.3750779948604758829000e-14,
+	7.6694099892045297650000e-01,	-4.7073456244106637314000e-14,
+	7.6902038691582674800000e-01,	-3.2196467714129539672000e-15,
+	7.7110541270400678737000e-01,	 6.8056671409522095920000e-14,
+	7.7319609157058200032000e-01,	 1.3289369604763123788000e-13,
+	7.7529243884247056595000e-01,	-5.4733995114020217443000e-14,
+	7.7739446988852867193000e-01,	-2.8976820942716585705000e-14,
+	7.7950220011894166827000e-01,	 4.2910119901762300287000e-14,
+	7.8161564498566504788000e-01,	-2.5479618415147342603000e-14,
+	7.8373481998277116922000e-01,	-9.7144514654701197287000e-15,
+	7.8585974064617325485000e-01,	 4.7184478546569152968000e-15,
+	7.8799042255395446154000e-01,	 2.0539125955565395998000e-14,
+	7.9012688132640618299000e-01,	-1.1102230246251565404000e-14,
+	7.9226913262626774692000e-01,	 3.8025138593411611510000e-14,
+	7.9441719215853734414000e-01,	-8.1046280797636427450000e-14,
+	7.9657107567112928059000e-01,	-7.5495165674510644749000e-15,
+	7.9873079895434206942000e-01,	 5.1514348342607263476000e-14,
+	8.0089637784129807940000e-01,	-8.7541085491693593210000e-14,
+	8.0306782820842770309000e-01,	 7.5883743733129449530000e-14,
+	8.0524516597464967926000e-01,	 4.0356606945124440244000e-14,
+	8.0742840710242858026000e-01,	-3.1086244689504383132000e-15,
+	8.0961756759744374356000e-01,	 2.1149748619109232095000e-14,
+	8.1181266350867553605000e-01,	 1.9761969838327786420000e-14,
+	8.1401371092867125245000e-01,	-4.6629367034256574698000e-15,
+	8.1622072599364403622000e-01,	 1.1490808304870370193000e-14,
+	8.1843372488350929483000e-01,	 4.7684078907650473411000e-14,
+	8.2065272382198950484000e-01,	-2.3925306180672123446000e-14,
+	8.2287773907698935627000e-01,	 1.2156942119645464118000e-14,
+	8.2510878696035871993000e-01,	 8.7152507433074788420000e-14,
+	8.2734588382810592133000e-01,	 1.5210055437364644604000e-14,
+	8.2958904608081385223000e-01,	 1.0103029524088924518000e-14,
+	8.3183829016334187578000e-01,	-4.5685677463325191638000e-14,
+	8.3409363256531943164000e-01,	 4.8738790781044372125000e-14,
+	8.3635508982079909134000e-01,	 1.3877787807814456755000e-15,
+	8.3862267850894056664000e-01,	 2.2204460492503130808000e-15,
+	8.4089641525368497010000e-01,	-5.0737192225369653897000e-14,
+	8.4317631672420823019000e-01,	 1.9817480989559044247000e-14,
+	8.4546239963468572398000e-01,	 5.6538107529036096821000e-14,
+	8.4775468074467597023000e-01,	 1.6375789613221058971000e-14,
+	8.5005317685938430738000e-01,	 2.0802803923913870676000e-13,
+	8.5235790482897477726000e-01,	-8.6042284408449631880000e-14,
+	8.5466888155023146289000e-01,	 8.3266726846886740531000e-17,
+	8.5698612396497009235000e-01,	 1.1907141939104803896000e-14,
+	8.5930964906123996627000e-01,	 1.6930901125533637241000e-15,
+	8.6163947387313144510000e-01,	-9.2148511043887992855000e-15,
+	8.6397561548091095229000e-01,	-1.3072876114961218263000e-14,
+	8.6631809101116341587000e-01,	 1.3128387266192476091000e-14,
+	8.6866691763685810467000e-01,	 8.2711615334574162262000e-15,
+	8.7102211257756134710000e-01,	-2.7949864644938315905000e-14,
+	8.7338369309957553099000e-01,	-1.4765966227514581988000e-14,
+	8.7575167651592977779000e-01,	-1.5321077739827160258000e-14,
+	8.7812608018665727627000e-01,	 1.2378986724570495426000e-14,
+	8.8050692151878506841000e-01,	-1.1213252548714081058000e-14,
+	8.8289421796662803654000e-01,	-1.3683498778505054361000e-14,
+	8.8528798703183275708000e-01,	 9.0233376326409597820000e-14,
+	8.8768824626324638327000e-01,	-2.3148150063434513868000e-14,
+	8.9009501325749940114000e-01,	-3.4491853817542050819000e-13,
+	8.9250830565945304950000e-01,	-2.3342439092743916262000e-14,
+	8.9492814116070096286000e-01,	 7.4940054162198066479000e-16,
+	8.9735453750155835805000e-01,	 7.6605388699135801289000e-15,
+	8.9978751247026977910000e-01,	 3.5804692544161298429000e-15,
+	9.0222708390331463057000e-01,	 4.3021142204224815941000e-15,
+	9.0467326968550965116000e-01,	-1.0019762797242037777000e-14,
+	9.0712608775020653339000e-01,	 1.1379786002407854539000e-14,
+	9.0958555607929203468000e-01,	-1.9428902930940239457000e-14,
+	9.1205169270354302657000e-01,	 2.5895952049381776305000e-14,
+	9.1452451570245363310000e-01,	 7.8270723236073536100000e-15,
+	9.1700404320467232555000e-01,	 1.7208456881689926377000e-15,
+	9.1949029338794130428000e-01,	-8.7152507433074788423000e-15,
+	9.2198328447930477658000e-01,	-1.2809198146612743585000e-14,
+	9.2448303475522841665000e-01,	 4.6074255521943996428000e-15,
+	9.2698956254169728730000e-01,	 7.0082828429463006614000e-15,
+	9.2950288621441201630000e-01,	 2.8310687127941491781000e-15,
+	9.3202302419889149209000e-01,	-4.6906922790412863833000e-15,
+	9.3454999497060231572000e-01,	-2.6145752229922436527000e-14,
+	9.3708381705513721371000e-01,	-1.9609314172441827395000e-14,
+	9.3962450902828797971000e-01,	 1.2115308756222020747000e-14,
+	9.4217208951624520363000e-01,	 1.1940448629843558592000e-13,
+	9.4472657719547781240000e-01,	 1.2614909117303341191000e-14,
+	9.4728799079347547618000e-01,	-1.1185496973098452145000e-14,
+	9.4985634908827609734000e-01,	-2.3314683517128287349000e-15,
+	9.5243167090883007475000e-01,	-1.0644263248593688331000e-14,
+	9.5501397513519203918000e-01,	-4.3159920082302960509000e-15,
+	9.5760328069857525434000e-01,	 2.4216739724636227038000e-15,
+	9.6019960658153680199000e-01,	 1.9630130854153549080000e-14,
+	9.6280297181806562267000e-01,	 4.7323256424647297536000e-15,
+	9.6541339549381399720000e-01,	 6.1756155744774332561000e-16,
+	9.6803089674614495319000e-01,	-3.3861802251067274483000e-15,
+	9.7065549476431622899000e-01,	-5.8911209244172368926000e-15,
+	9.7328720878958241424000e-01,	-5.0737192225369653897000e-14,
+	9.7592605811548926997000e-01,	 1.8041124150158793782000e-16,
+	9.7857206208769698108000e-01,	-4.6490589156178430130000e-15,
+	9.8122524010446421360000e-01,	 7.3552275381416620803000e-16,
+	9.8388561161659193743000e-01,	 5.9362237347926338771000e-15,
+	9.8655319612761638303000e-01,	-1.1310397063368782256000e-15,
+	9.8922801319396724828000e-01,	-1.2011225347663412322000e-14,
+	9.9191008242510936288000e-01,	-4.6837533851373791549000e-16,
+	9.9459942348362284647000e-01,	-1.4982806662011682874000e-14,
+	9.9729605608547244877000e-01,	 3.3597256920980811401000e-15,
+	1.0000000000000000000000e+00,	 0.0000000000000000000000e+00,
+	1.0027112750502022998000e+00,	-2.6714741530042829254000e-16,
+	1.0054299011127916241000e+00,	-1.6067008834497187308000e-14,
+	1.0081558981184177703000e+00,	 3.6429192995512948983000e-16,
+	1.0108892860517029177000e+00,	 3.5076108684251039449000e-15,
+	1.0136300849514889855000e+00,	-6.4531713306337223912000e-16,
+	1.0163783149109539838000e+00,	 1.3426759704060486911000e-15,
+	1.0191339960777214824000e+00,	-2.3311214070176333735000e-14,
+	1.0218971486541108540000e+00,	-8.2225892761300656275000e-15,
+	1.0246677928971383853000e+00,	 3.8580250105724189780000e-15,
+	1.0274459491187770688000e+00,	 1.8776646903972959990000e-14,
+	1.0302316376860389813000e+00,	-2.8449465006019636348000e-15,
+	1.0330248790212301913000e+00,	 2.4702462297909733024000e-15,
+	1.0358256936019518690000e+00,	-7.3135941747182187100000e-15,
+	1.0386341019613787306000e+00,	-8.3266726846886740531000e-17,
+	1.0414501246883212104000e+00,	 7.0221606307541151182000e-15,
+	1.0442737824274095360000e+00,	-5.9466320756484947196000e-15,
+	1.0471050958792909036000e+00,	 1.4294121442048890458000e-15,
+	1.0499440858006940935000e+00,	 9.3813845580825727666000e-15,
+	1.0527907730046219825000e+00,	-5.9535709695524019480000e-15,
+	1.0556451783605751427000e+00,	 2.4577562207639402914000e-14,
+	1.0585073227945058782000e+00,	-9.2842400434278715693000e-15,
+	1.0613772272892525450000e+00,	-1.2961853812498702609000e-14,
+	1.0642549128844673856000e+00,	 3.8441472227646045212000e-15,
+	1.0671404006768259176000e+00,	 3.1086244689504383132000e-15,
+	1.0700337118202567499000e+00,	 2.0192181260370034579000e-14,
+	1.0729348675259775536000e+00,	 2.6922908347160046105000e-15,
+	1.0758438890627808338000e+00,	-1.3683498778505054361000e-14,
+	1.0787607977571218587000e+00,	 2.7616797737550768943000e-15,
+	1.0816856149932174702000e+00,	 3.0253577421035515727000e-15,
+	1.0846183622133163116000e+00,	 9.4091401336982016801000e-15,
+	1.0875590609177760992000e+00,	 8.5348395018058909045000e-15,
+	1.0905077326652909964000e+00,	 4.4103609653234343568000e-14,
+	1.0934643990728785123000e+00,	-9.6866958898544908152000e-15,
+	1.0964290818163575647000e+00,	-2.5340840537069198035000e-14,
+	1.0994018026302341262000e+00,	 1.5931700403370996355000e-14,
+	1.1023825833078519931000e+00,	 1.4460654895742663939000e-14,
+	1.1053714457016148298000e+00,	-1.6500689703491389082000e-13,
+	1.1083684117237071476000e+00,	 3.7109204598095857364000e-14,
+	1.1113735033448086664000e+00,	-1.1601830607332885847000e-14,
+	1.1143867425958942086000e+00,	 2.1649348980190552538000e-15,
+	1.1174081515673714993000e+00,	 2.9698465908722937456000e-15,
+	1.1204377524096127416000e+00,	 7.7993167479917246965000e-15,
+	1.1234755673330008019000e+00,	-2.4397150966137814976000e-14,
+	1.1265216186082829264000e+00,	 5.2541304640385533276000e-14,
+	1.1295759285662891891000e+00,	 1.3322676295501878485000e-15,
+	1.1326385195987571652000e+00,	 4.8322457146809938422000e-14,
+	1.1357094141578236712000e+00,	 2.3064883336587627127000e-14,
+	1.1387886347566735790000e+00,	-2.2898349882893853646000e-14,
+	1.1418762039695680155000e+00,	 8.0768725041480138316000e-15,
+	1.1449721444317906283000e+00,	-1.7125190154843039636000e-14,
+	1.1480764788401920384000e+00,	 1.6375789613221058971000e-14,
+	1.1511892299529953299000e+00,	 1.5820678100908480701000e-14,
+	1.1543104205902670056000e+00,	 6.3699046037868356500000e-14,
+	1.1574400736337362439000e+00,	-1.8429702208777598571000e-14,
+	1.1605782120274845681000e+00,	-1.7624790515924360079000e-14,
+	1.1637248587775863573000e+00,	 1.0963452368173420837000e-14,
+	1.1668800369524550131000e+00,	-3.2834845953289004683000e-14,
+	1.1700437696832879375000e+00,	 4.6546100307409687957000e-14,
+	1.1732160801636253300000e+00,	-1.4654943925052066334000e-14,
+	1.1763969916502701185000e+00,	-1.3683498778505054361000e-14,
+	1.1795865274628722918000e+00,	-4.4686476741162550752000e-15,
+	1.1827847109843110385000e+00,	-3.6581848661398908007000e-14,
+	1.1859915656609776313000e+00,	-1.9706458687096528593000e-14,
+	1.1892071150026677362000e+00,	-6.4698246760030997390000e-14,
+	1.1924313825823584789000e+00,	-9.5912167097367273527000e-13,
+	1.1956643920398004610000e+00,	-3.2474023470285828807000e-14,
+	1.1989061670743486054000e+00,	-3.8358205500799158472000e-14,
+	1.2021567314527259462000e+00,	 2.7366997557010108721000e-14,
+	1.2054161090051225269000e+00,	-1.5543122344752191566000e-15,
+	1.2086843236265314427000e+00,	-5.9841021027295937520000e-14,
+	1.2119613992768292210000e+00,	 3.3362201889985954040000e-14,
+	1.2152473599804933801000e+00,	 2.9087843245179101359000e-14,
+	1.2185422298273915764000e+00,	-1.9872992140790302074000e-14,
+	1.2218460329727474090000e+00,	-1.1934897514720432810000e-14,
+	1.2251587936370220699000e+00,	-1.4527268277220173331000e-13,
+	1.2284805361068791285000e+00,	 1.0713652187632760615000e-14,
+	1.2318112847341684546000e+00,	 1.0835776720341527834000e-13,
+	1.2351510639369362998000e+00,	 3.4972025275692431023000e-15,
+	1.2384998981997985545000e+00,	-2.0983215165415458614000e-14,
+	1.2418578120735179748000e+00,	 3.9412917374193057185000e-14,
+	1.2452248301751067672000e+00,	-1.7513768213461844425000e-13,
+	1.2486009771891160014000e+00,	-1.0252909632413320650000e-13,
+	1.2519862778663497505000e+00,	 3.8580250105724189780000e-14,
+	1.2553807570247148551000e+00,	 2.7311486405778850894000e-14,
+	1.2587844395497014283000e+00,	-1.7208456881689926377000e-14,
+	1.2621973503942811590000e+00,	 3.4805491821998657542000e-14,
+	1.2656195145788113887000e+00,	 5.7731597280508140102000e-15,
+	1.2690509571917287790000e+00,	-5.0515147620444622589000e-15,
+	1.2724917033893918816000e+00,	-1.2323475573339237599000e-14,
+	1.2759417783963775683000e+00,	-1.6431300764452316798000e-14,
+	1.2794012075057223932000e+00,	 5.9952043329758453180000e-14,
+	1.2828700160787320783000e+00,	-5.1958437552457326092000e-14,
+	1.2863482295460366700000e+00,	 1.2490009027033011080000e-14,
+	1.2898358734066417419000e+00,	-2.6922908347160046105000e-14,
+	1.2933329732290987923000e+00,	 1.0436096431476471480000e-14,
+	1.2968395546509940974000e+00,	-1.7319479184152442031000e-14,
+	1.3003556433796572556000e+00,	 7.3274719625260331668000e-15,
+	1.3038812651919815533000e+00,	 5.0515147620444622589000e-14,
+	1.3074164459346540035000e+00,	-2.5646151868841116084000e-14,
+	1.3109612115247846198000e+00,	 2.2315482794965646463000e-14,
+	1.3145155879493446438000e+00,	-1.0991207943789049750000e-14,
+	1.3180796012660587202000e+00,	-5.7731597280508140102000e-15,
+	1.3216532776033269592000e+00,	 1.8496315590255107963000e-13,
+	1.3252366431597040197000e+00,	-4.0578651550049471552000e-14,
+	1.3288297242058946246000e+00,	-6.4892535789340399780000e-14,
+	1.3324325470833204843000e+00,	 1.7219559111936177941000e-13,
+	1.3360451382041798052000e+00,	 3.6748382115092681488000e-14,
+	1.3396675240534174911000e+00,	 1.2329026688462363381000e-13,
+	1.3432997311867924672000e+00,	-4.5963233219481480774000e-14,
+	1.3469417862329142732000e+00,	-3.3806291099836016656000e-14,
+	1.3505937158922334262000e+00,	 2.1260770921571747749000e-13,
+	1.3542555469368922072000e+00,	-5.5511151231257827021000e-16,
+	1.3579273062129546545000e+00,	 5.6954441163270530520000e-14,
+	1.3616090206381865624000e+00,	-4.0467629247586955898000e-14,
+	1.3653007172041637940000e+00,	 1.6059376051202889357000e-13,
+	1.3690024229745676454000e+00,	-2.4202861936828412581000e-14,
+	1.3727141650876881762000e+00,	 2.0816681711721685133000e-14,
+	1.3764359707545690270000e+00,	 4.0800696154974502861000e-14,
+	1.3801678672602453180000e+00,	 7.5495165674510644749000e-15,
+	1.3839098819638133708000e+00,	-1.9373391779708981630000e-14,
+	1.3876620422985130876000e+00,	-1.6708856520608605933000e-14,
+	1.3914243757719233496000e+00,	-2.9420910152566648321000e-15,
+	1.3951969099661583051000e+00,	-4.3298697960381105077000e-14,
+	1.3989796725393028876000e+00,	 1.0227374502846942050000e-12,
+	1.4027726912201248233000e+00,	-8.2156503822261583990000e-14,
+	1.4065759938190178779000e+00,	 2.4980018054066022160000e-15,
+	1.4103896082172264759000e+00,	-4.5241588253475129022000e-14,
+};
+
+/*
+ * exp2(x): compute the base 2 exponential of x
+ *
+ * Accuracy: Peak error < 0.503 ulp for normalized results.
+ *
+ * Method: (accurate tables)
+ *
+ *   Reduce x:
+ *     x = 2**k + y, for integer k and |y| <= 1/2.
+ *     Thus we have exp2(x) = 2**k * exp2(y).
+ *
+ *   Reduce y:
+ *     y = i/TBLSIZE + z - eps[i] for integer i near y * TBLSIZE.
+ *     Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z - eps[i]),
+ *     with |z - eps[i]| <= 2**-9 + 2**-39 for the table used.
+ *
+ *   We compute exp2(i/TBLSIZE) via table lookup and exp2(z - eps[i]) via
+ *   a degree-5 minimax polynomial with maximum error under 1.3 * 2**-61.
+ *   The values in exp2t[] and eps[] are chosen such that
+ *   exp2t[i] = exp2(i/TBLSIZE + eps[i]), and eps[i] is a small offset such
+ *   that exp2t[i] is accurate to 2**-64.
+ *
+ *   Note that the range of i is +-TBLSIZE/2, so we actually index the tables
+ *   by i0 = i + TBLSIZE/2.  For cache efficiency, exp2t[] and eps[] are
+ *   virtual tables, interleaved in the real table tbl[].
+ *
+ *   This method is due to Gal, with many details due to Gal and Bachelis:
+ *
+ *	Gal, S. and Bachelis, B.  An Accurate Elementary Mathematical Library
+ *	for the IEEE Floating Point Standard.  TOMS 17(1), 26-46 (1991).
+ */
+double
+exp2(double x)
+{
+	double r, t, z;
+	uint32_t hx, hr, ix, lx, i0;
+	int k;
+
+	/* Filter out exceptional cases. */
+	GET_HIGH_WORD(hx,x);
+	ix = hx & 0x7fffffff;		/* high word of |x| */
+	if(ix >= 0x40900000) {			/* |x| >= 1024 */
+		if(ix >= 0x7ff00000) {
+			GET_LOW_WORD(lx,x);
+			if(((ix & 0xfffff) | lx) != 0 || (hx & 0x80000000) == 0)
+				return (x); 	/* x is NaN or +Inf */
+			else
+				return (0.0);	/* x is -Inf */
+		}
+		if(x >= 1.0240000000000000000000e+03)
+			return (huge * huge); /* overflow */
+		if(x <= -1.0750000000000000000000e+03)
+			return (twom1000 * twom1000); /* underflow */
+	} else if (ix < 0x3c900000) {		/* |x| < 5.5511151231257827021000e-17 */
+		return (1.0 + x);
+	}
+
+	/* Reduce x, computing z, i0, and k. */
+	t = x + redux;
+	GET_LOW_WORD(i0, t);
+	i0 += TBLSIZE / 2;
+	k = (i0 >> TBLBITS) << 20;
+	i0 = (i0 & (TBLSIZE - 1)) << 1;
+	t -= redux;
+	z = x - t;
+
+	/* Compute r = exp2(y) = exp2t[i0] * p(z - eps[i]). */
+	t = tbl[i0];		/* exp2t[i0] */
+	z -= tbl[i0 + 1];	/* eps[i0]   */
+	r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));
+
+	/* Scale by 2**(k>>20). */
+	if(k >= -1021 << 20) {
+		if (k != 0) {
+			GET_HIGH_WORD(hr, r);
+			SET_HIGH_WORD(r, hr + k);
+		}
+		return (r);
+	} else {
+		GET_HIGH_WORD(hr, r);
+		SET_HIGH_WORD(r, hr + (k + (1000 << 20)));
+		return (r * twom1000);
+	}
+}
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_exp2.c
===================================================================
--- /trunk/libc/src/msun/src/s_exp2.c	(revision 3891)
+++ /trunk/libc/src/msun/src/s_exp2.c	(revision 3892)
@@ -24,4 +24,9 @@
  * SUCH DAMAGE.
  */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_exp2-decimal-constants.c"
+#else
 
 #include "namespace.h"
@@ -389,2 +394,4 @@
 	}
 }
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_exp2f-decimal-constants.c
===================================================================
--- /trunk/libc/src/msun/src/s_exp2f-decimal-constants.c	(revision 3892)
+++ /trunk/libc/src/msun/src/s_exp2f-decimal-constants.c	(revision 3892)
@@ -0,0 +1,149 @@
+/*-
+ * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_exp2f-decimal-constants.c"
+#else
+
+#include "namespace.h"
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/msun/src/s_exp2f.c,v 1.1 2005/04/05 02:57:15 das Exp $");
+
+#include "math.h"
+#include "math_private.h"
+
+#define	TBLBITS	4
+#define	TBLSIZE	(1 << TBLBITS)
+
+static const float
+    huge    = 1.2676506002282294015000e+30f,
+    twom100 = 7.8886090522101180539000e-31f,
+    redux   = 1.2582912000000000000000e+07f / TBLSIZE,
+    P1	    = 6.9314718246459960937000e-01f,
+    P2	    = 2.4022650718688964843000e-01f,
+    P3	    = 5.5505409836769104004000e-02f,
+    P4	    = 9.6183549612760543823000e-03f;
+
+static const double exp2ft[TBLSIZE] = {
+	7.0710678118654757273000e-01,
+	7.3841307296974967311000e-01,
+	7.7110541270397037205000e-01,
+	8.0524516597462714173000e-01,
+	8.4089641525371450203000e-01,
+	8.7812608018664972675000e-01,
+	9.1700404320467121532000e-01,
+	9.5760328069857370003000e-01,
+	1.0000000000000000000000e+00,
+	1.0442737824274137548000e+00,
+	1.0905077326652576897000e+00,
+	1.1387886347566915646000e+00,
+	1.1892071150027210269000e+00,
+	1.2418578120734840020000e+00,
+	1.2968395546510096406000e+00,
+	1.3542555469368926513000e+00,
+};
+	
+/*
+ * exp2f(x): compute the base 2 exponential of x
+ *
+ * Accuracy: Peak error < 0.501 ulp; location of peak: -0.030110927.
+ *
+ * Method: (equally-spaced tables)
+ *
+ *   Reduce x:
+ *     x = 2**k + y, for integer k and |y| <= 1/2.
+ *     Thus we have exp2f(x) = 2**k * exp2(y).
+ *
+ *   Reduce y:
+ *     y = i/TBLSIZE + z for integer i near y * TBLSIZE.
+ *     Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z),
+ *     with |z| <= 2**-(TBLSIZE+1).
+ *
+ *   We compute exp2(i/TBLSIZE) via table lookup and exp2(z) via a
+ *   degree-4 minimax polynomial with maximum error under 1.4 * 2**-33.
+ *   Using double precision in the final calculation avoids roundoff error.
+ *
+ *   This method is due to Tang, but I do not use his suggested parameters:
+ *
+ *	Tang, P.  Table-driven Implementation of the Exponential Function
+ *	in IEEE Floating-Point Arithmetic.  TOMS 15(2), 144-157 (1989).
+ */
+float
+exp2f(float x)
+{
+	double tv;
+	float r, z;
+	volatile float t;	/* prevent gcc from using too much precision */
+	uint32_t hx, hr, ix, i0;
+	int32_t k;
+
+	/* Filter out exceptional cases. */
+	GET_FLOAT_WORD(hx,x);
+	ix = hx & 0x7fffffff;		/* high word of |x| */
+	if(ix >= 0x43000000) {			/* |x| >= 128 */
+		if(ix >= 0x7f800000) {
+			if ((ix & 0x7fffff) != 0 || (hx & 0x80000000) == 0)
+				return (x); 	/* x is NaN or +Inf */
+			else
+				return (0.0);	/* x is -Inf */
+		}
+		if(x >= 1.2800000000000000000000e+02f)
+			return (huge * huge);	/* overflow */
+		if(x <= -1.5000000000000000000000e+02f)
+			return (twom100 * twom100); /* underflow */
+	} else if (ix <= 0x33000000) {		/* |x| <= 2.9802322387695312500000e-08 */
+		return (1.0f + x);
+	}
+
+	/* Reduce x, computing z, i0, and k. */
+	t = x + redux;
+	GET_FLOAT_WORD(i0, t);
+	i0 += TBLSIZE / 2;
+	k = (i0 >> TBLBITS) << 23;
+	i0 &= TBLSIZE - 1;
+	t -= redux;
+	z = x - t;
+
+	/* Compute r = exp2(y) = exp2ft[i0] * p(z). */
+	tv = exp2ft[i0];
+	r = tv + tv * (z * (P1 + z * (P2 + z * (P3 + z * P4))));
+
+	/* Scale by 2**(k>>23). */
+	if(k >= -125 << 23) {
+		if (k != 0) {
+			GET_FLOAT_WORD(hr, r);
+			SET_FLOAT_WORD(r, hr + k);
+		}
+		return (r);
+	} else {
+		GET_FLOAT_WORD(hr, r);
+		SET_FLOAT_WORD(r, hr + (k + (100 << 23)));
+		return (r * twom100);
+	}
+}
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_exp2f.c
===================================================================
--- /trunk/libc/src/msun/src/s_exp2f.c	(revision 3891)
+++ /trunk/libc/src/msun/src/s_exp2f.c	(revision 3892)
@@ -24,4 +24,9 @@
  * SUCH DAMAGE.
  */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_exp2f-decimal-constants.c"
+#else
 
 #include "namespace.h"
@@ -141,2 +146,4 @@
 	}
 }
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_floorl.c
===================================================================
--- /trunk/libc/src/msun/src/s_floorl.c	(revision 3891)
+++ /trunk/libc/src/msun/src/s_floorl.c	(revision 3892)
@@ -57,6 +57,14 @@
 floorl(long double x)
 {
+#ifdef __GNUC__
 	union IEEEl2bits u = { .e = x };
 	int e = u.bits.exp - LDBL_MAX_EXP + 1;
+#else
+	union IEEEl2bits u;
+	int e;
+
+	u.e = x;
+	e = u.bits.exp - LDBL_MAX_EXP + 1;
+#endif
 
 	if (e < MANH_SIZE - 1) {
Index: /trunk/libc/src/msun/src/s_fma-decimal-constants.c
===================================================================
--- /trunk/libc/src/msun/src/s_fma-decimal-constants.c	(revision 3892)
+++ /trunk/libc/src/msun/src/s_fma-decimal-constants.c	(revision 3892)
@@ -0,0 +1,210 @@
+/*-
+ * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_fma-decimal-constants.c"
+#else
+
+#include "namespace.h"
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/msun/src/s_fma.c,v 1.4 2005/03/18 02:27:59 das Exp $");
+
+#include <fenv.h>
+#include <float.h>
+#include <math.h>
+
+/*
+ * Fused multiply-add: Compute x * y + z with a single rounding error.
+ *
+ * We use scaling to avoid overflow/underflow, along with the
+ * canonical precision-doubling technique adapted from:
+ *
+ *	Dekker, T.  A Floating-Point Technique for Extending the
+ *	Available Precision.  Numer. Math. 18, 224-242 (1971).
+ *
+ * This algorithm is sensitive to the rounding precision.  FPUs such
+ * as the i387 must be set in double-precision mode if variables are
+ * to be stored in FP registers in order to avoid incorrect results.
+ * This is the default on FreeBSD, but not on many other systems.
+ *
+ * Hardware instructions should be used on architectures that support it,
+ * since this implementation will likely be several times slower.
+ */
+#if LDBL_MANT_DIG != 113
+double
+fma(double x, double y, double z)
+{
+	static const double split = 1.3421772800000000000000e+08 + 1.0;
+	double xs, ys, zs;
+	double c, cc, hx, hy, p, q, tx, ty;
+	double r, rr, s;
+	int oround;
+	int ex, ey, ez;
+	int spread;
+
+	if (z == 0.0)
+		return (x * y);
+	if (x == 0.0 || y == 0.0)
+		return (x * y + z);
+
+	/* Results of frexp() are undefined for these cases. */
+	if (!isfinite(x) || !isfinite(y) || !isfinite(z))
+		return (x * y + z);
+
+	xs = frexp(x, &ex);
+	ys = frexp(y, &ey);
+	zs = frexp(z, &ez);
+	oround = fegetround();
+	spread = ex + ey - ez;
+
+	/*
+	 * If x * y and z are many orders of magnitude apart, the scaling
+	 * will overflow, so we handle these cases specially.  Rounding
+	 * modes other than FE_TONEAREST are painful.
+	 */
+	if (spread > DBL_MANT_DIG * 2) {
+		fenv_t env;
+		feraiseexcept(FE_INEXACT);
+		switch(oround) {
+		case FE_TONEAREST:
+			return (x * y);
+		case FE_TOWARDZERO:
+			if (x > 0.0 ^ y < 0.0 ^ z < 0.0)
+				return (x * y);
+			feholdexcept(&env);
+			r = x * y;
+			if (!fetestexcept(FE_INEXACT))
+				r = nextafter(r, 0);
+			feupdateenv(&env);
+			return (r);
+		case FE_DOWNWARD:
+			if (z > 0.0)
+				return (x * y);
+			feholdexcept(&env);
+			r = x * y;
+			if (!fetestexcept(FE_INEXACT))
+				r = nextafter(r, -INFINITY);
+			feupdateenv(&env);
+			return (r);
+		default:	/* FE_UPWARD */
+			if (z < 0.0)
+				return (x * y);
+			feholdexcept(&env);
+			r = x * y;
+			if (!fetestexcept(FE_INEXACT))
+				r = nextafter(r, INFINITY);
+			feupdateenv(&env);
+			return (r);
+		}
+	}
+	if (spread < -DBL_MANT_DIG) {
+		feraiseexcept(FE_INEXACT);
+		if (!isnormal(z))
+			feraiseexcept(FE_UNDERFLOW);
+		switch (oround) {
+		case FE_TONEAREST:
+			return (z);
+		case FE_TOWARDZERO:
+			if (x > 0.0 ^ y < 0.0 ^ z < 0.0)
+				return (z);
+			else
+				return (nextafter(z, 0));
+		case FE_DOWNWARD:
+			if (x > 0.0 ^ y < 0.0)
+				return (z);
+			else
+				return (nextafter(z, -INFINITY));
+		default:	/* FE_UPWARD */
+			if (x > 0.0 ^ y < 0.0)
+				return (nextafter(z, INFINITY));
+			else
+				return (z);
+		}
+	}
+
+	/*
+	 * Use Dekker's algorithm to perform the multiplication and
+	 * subsequent addition in twice the machine precision.
+	 * Arrange so that x * y = c + cc, and x * y + z = r + rr.
+	 */
+	fesetround(FE_TONEAREST);
+
+	p = xs * split;
+	hx = xs - p;
+	hx += p;
+	tx = xs - hx;
+
+	p = ys * split;
+	hy = ys - p;
+	hy += p;
+	ty = ys - hy;
+
+	p = hx * hy;
+	q = hx * ty + tx * hy;
+	c = p + q;
+	cc = p - c + q + tx * ty;
+
+	zs = ldexp(zs, -spread);
+	r = c + zs;
+	s = r - c;
+	rr = (c - (r - s)) + (zs - s) + cc;
+
+	spread = ex + ey;
+	if (spread + ilogb(r) > -1023) {
+		fesetround(oround);
+		r = r + rr;
+	} else {
+		/*
+		 * The result is subnormal, so we round before scaling to
+		 * avoid double rounding.
+		 */
+		p = ldexp(copysign(2.2250738585072013832000e-308, r), -spread);
+		c = r + p;
+		s = c - r;
+		cc = (r - (c - s)) + (p - s) + rr;
+		fesetround(oround);
+		r = (c + cc) - p;
+	}
+	return (ldexp(r, spread));
+}
+#else	/* LDBL_MANT_DIG == 113 */
+/*
+ * 113 bits of precision is more than twice the precision of a double,
+ * so it is enough to represent the intermediate product exactly.
+ */
+double
+fma(double x, double y, double z)
+{
+	return ((long double)x * y + z);
+}
+#endif	/* LDBL_MANT_DIG != 113 */
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(fma, fmal);
+#endif
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_fma.c
===================================================================
--- /trunk/libc/src/msun/src/s_fma.c	(revision 3891)
+++ /trunk/libc/src/msun/src/s_fma.c	(revision 3892)
@@ -24,4 +24,9 @@
  * SUCH DAMAGE.
  */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_fma-decimal-constants.c"
+#else
 
 #include "namespace.h"
@@ -202,2 +207,4 @@
 __weak_reference(fma, fmal);
 #endif
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_fmal-decimal-constants.c
===================================================================
--- /trunk/libc/src/msun/src/s_fmal-decimal-constants.c	(revision 3892)
+++ /trunk/libc/src/msun/src/s_fmal-decimal-constants.c	(revision 3892)
@@ -0,0 +1,190 @@
+/*-
+ * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_fmal-decimal-constants.c"
+#else
+
+#include "namespace.h"
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/msun/src/s_fmal.c,v 1.2 2005/03/18 02:27:59 das Exp $");
+
+#include <fenv.h>
+#include <float.h>
+#include <math.h>
+
+/*
+ * Fused multiply-add: Compute x * y + z with a single rounding error.
+ *
+ * We use scaling to avoid overflow/underflow, along with the
+ * canonical precision-doubling technique adapted from:
+ *
+ *	Dekker, T.  A Floating-Point Technique for Extending the
+ *	Available Precision.  Numer. Math. 18, 224-242 (1971).
+ */
+long double
+fmal(long double x, long double y, long double z)
+{
+#if LDBL_MANT_DIG == 64
+	static const long double split = 0.0000000000000000000000e+00L + 1.0;
+#elif LDBL_MANT_DIG == 113
+	static const long double split = 0.0000000000000000000000e+00L + 1.0;
+#endif
+	long double xs, ys, zs;
+	long double c, cc, hx, hy, p, q, tx, ty;
+	long double r, rr, s;
+	int oround;
+	int ex, ey, ez;
+	int spread;
+
+	if (z == 0.0)
+		return (x * y);
+	if (x == 0.0 || y == 0.0)
+		return (x * y + z);
+
+	/* Results of frexp() are undefined for these cases. */
+	if (!isfinite(x) || !isfinite(y) || !isfinite(z))
+		return (x * y + z);
+
+	xs = frexpl(x, &ex);
+	ys = frexpl(y, &ey);
+	zs = frexpl(z, &ez);
+	oround = fegetround();
+	spread = ex + ey - ez;
+
+	/*
+	 * If x * y and z are many orders of magnitude apart, the scaling
+	 * will overflow, so we handle these cases specially.  Rounding
+	 * modes other than FE_TONEAREST are painful.
+	 */
+	if (spread > LDBL_MANT_DIG * 2) {
+		fenv_t env;
+		feraiseexcept(FE_INEXACT);
+		switch(oround) {
+		case FE_TONEAREST:
+			return (x * y);
+		case FE_TOWARDZERO:
+			if (x > 0.0 ^ y < 0.0 ^ z < 0.0)
+				return (x * y);
+			feholdexcept(&env);
+			r = x * y;
+			if (!fetestexcept(FE_INEXACT))
+				r = nextafterl(r, 0);
+			feupdateenv(&env);
+			return (r);
+		case FE_DOWNWARD:
+			if (z > 0.0)
+				return (x * y);
+			feholdexcept(&env);
+			r = x * y;
+			if (!fetestexcept(FE_INEXACT))
+				r = nextafterl(r, -INFINITY);
+			feupdateenv(&env);
+			return (r);
+		default:	/* FE_UPWARD */
+			if (z < 0.0)
+				return (x * y);
+			feholdexcept(&env);
+			r = x * y;
+			if (!fetestexcept(FE_INEXACT))
+				r = nextafterl(r, INFINITY);
+			feupdateenv(&env);
+			return (r);
+		}
+	}
+	if (spread < -LDBL_MANT_DIG) {
+		feraiseexcept(FE_INEXACT);
+		if (!isnormal(z))
+			feraiseexcept(FE_UNDERFLOW);
+		switch (oround) {
+		case FE_TONEAREST:
+			return (z);
+		case FE_TOWARDZERO:
+			if (x > 0.0 ^ y < 0.0 ^ z < 0.0)
+				return (z);
+			else
+				return (nextafterl(z, 0));
+		case FE_DOWNWARD:
+			if (x > 0.0 ^ y < 0.0)
+				return (z);
+			else
+				return (nextafterl(z, -INFINITY));
+		default:	/* FE_UPWARD */
+			if (x > 0.0 ^ y < 0.0)
+				return (nextafterl(z, INFINITY));
+			else
+				return (z);
+		}
+	}
+
+	/*
+	 * Use Dekker's algorithm to perform the multiplication and
+	 * subsequent addition in twice the machine precision.
+	 * Arrange so that x * y = c + cc, and x * y + z = r + rr.
+	 */
+	fesetround(FE_TONEAREST);
+
+	p = xs * split;
+	hx = xs - p;
+	hx += p;
+	tx = xs - hx;
+
+	p = ys * split;
+	hy = ys - p;
+	hy += p;
+	ty = ys - hy;
+
+	p = hx * hy;
+	q = hx * ty + tx * hy;
+	c = p + q;
+	cc = p - c + q + tx * ty;
+
+	zs = ldexpl(zs, -spread);
+	r = c + zs;
+	s = r - c;
+	rr = (c - (r - s)) + (zs - s) + cc;
+
+	spread = ex + ey;
+	if (spread + ilogbl(r) > -16383) {
+		fesetround(oround);
+		r = r + rr;
+	} else {
+		/*
+		 * The result is subnormal, so we round before scaling to
+		 * avoid double rounding.
+		 */
+		p = ldexpl(copysignl(0.0000000000000000000000e+00L, r), -spread);
+		c = r + p;
+		s = c - r;
+		cc = (r - (c - s)) + (p - s) + rr;
+		fesetround(oround);
+		r = (c + cc) - p;
+	}
+	return (ldexpl(r, spread));
+}
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_fmal.c
===================================================================
--- /trunk/libc/src/msun/src/s_fmal.c	(revision 3891)
+++ /trunk/libc/src/msun/src/s_fmal.c	(revision 3892)
@@ -24,4 +24,9 @@
  * SUCH DAMAGE.
  */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_fmal-decimal-constants.c"
+#else
 
 #include "namespace.h"
@@ -182,2 +187,4 @@
 	return (ldexpl(r, spread));
 }
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_frexpl-decimal-constants.c
===================================================================
--- /trunk/libc/src/msun/src/s_frexpl-decimal-constants.c	(revision 3892)
+++ /trunk/libc/src/msun/src/s_frexpl-decimal-constants.c	(revision 3892)
@@ -0,0 +1,70 @@
+/*-
+ * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/msun/src/s_frexpl.c,v 1.1 2005/03/07 04:54:51 das Exp $
+ */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_frexpl-decimal-constants.c"
+#else
+
+#include "namespace.h"
+#include <float.h>
+#include <math.h>
+
+#include "fpmath.h"
+
+#if LDBL_MAX_EXP != 0x4000
+#error "Unsupported long double format"
+#endif
+
+long double
+frexpl(long double x, int *ex)
+{
+	union IEEEl2bits u;
+
+	u.e = x;
+	switch (u.bits.exp) {
+	case 0:		/* 0 or subnormal */
+		if ((u.bits.manl | u.bits.manh) == 0) {
+			*ex = 0;
+		} else {
+			u.e *= 5.3631231719770388395000e+154;
+			*ex = u.bits.exp - 0x4200;
+			u.bits.exp = 0x3ffe;
+		}
+		break;
+	case 0x7fff:	/* infinity or NaN; value of *ex is unspecified */
+		break;
+	default:	/* normal */
+		*ex = u.bits.exp - 0x3ffe;
+		u.bits.exp = 0x3ffe;
+		break;
+	}
+	return (u.e);
+}
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_frexpl.c
===================================================================
--- /trunk/libc/src/msun/src/s_frexpl.c	(revision 3891)
+++ /trunk/libc/src/msun/src/s_frexpl.c	(revision 3892)
@@ -26,4 +26,9 @@
  * $FreeBSD: src/lib/msun/src/s_frexpl.c,v 1.1 2005/03/07 04:54:51 das Exp $
  */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_frexpl-decimal-constants.c"
+#else
 
 #include "namespace.h"
@@ -62,2 +67,4 @@
 	return (u.e);
 }
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_remquo-decimal-constants.c
===================================================================
--- /trunk/libc/src/msun/src/s_remquo-decimal-constants.c	(revision 3892)
+++ /trunk/libc/src/msun/src/s_remquo-decimal-constants.c	(revision 3892)
@@ -0,0 +1,160 @@
+/* @(#)e_fmod.c 1.3 95/01/18 */
+/*-
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_remquo-decimal-constants.c"
+#else
+
+#include "namespace.h"
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/msun/src/s_remquo.c,v 1.1 2005/03/25 04:40:44 das Exp $");
+
+#include "math.h"
+#include "math_private.h"
+
+static const double Zero[] = {0.0, -0.0,};
+
+/*
+ * Return the IEEE remainder and set *quo to the last n bits of the
+ * quotient, rounded to the nearest integer.  We choose n=31 because
+ * we wind up computing all the integer bits of the quotient anyway as
+ * a side-effect of computing the remainder by the shift and subtract
+ * method.  In practice, this is far more bits than are needed to use
+ * remquo in reduction algorithms.
+ */
+double
+remquo(double x, double y, int *quo)
+{
+	int32_t n,hx,hy,hz,ix,iy,sx,i;
+	u_int32_t lx,ly,lz,q,sxy;
+
+	EXTRACT_WORDS(hx,lx,x);
+	EXTRACT_WORDS(hy,ly,y);
+	sxy = (hx ^ hy) & 0x80000000;
+	sx = hx&0x80000000;		/* sign of x */
+	hx ^=sx;		/* |x| */
+	hy &= 0x7fffffff;	/* |y| */
+
+    /* purge off exception values */
+	if((hy|ly)==0||(hx>=0x7ff00000)||	/* y=0,or x not finite */
+	  ((hy|((ly|-ly)>>31))>0x7ff00000))	/* or y is NaN */
+	    return (x*y)/(x*y);
+	if(hx<=hy) {
+	    if((hx<hy)||(lx<ly)) {
+		q = 0;
+		goto fixup;	/* |x|<|y| return x or x-y */
+	    }
+	    if(lx==ly) {
+		*quo = 1;
+		return Zero[(u_int32_t)sx>>31];	/* |x|=|y| return x*0*/
+	    }
+	}
+
+    /* determine ix = ilogb(x) */
+	if(hx<0x00100000) {	/* subnormal x */
+	    if(hx==0) {
+		for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
+	    } else {
+		for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
+	    }
+	} else ix = (hx>>20)-1023;
+
+    /* determine iy = ilogb(y) */
+	if(hy<0x00100000) {	/* subnormal y */
+	    if(hy==0) {
+		for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
+	    } else {
+		for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
+	    }
+	} else iy = (hy>>20)-1023;
+
+    /* set up {hx,lx}, {hy,ly} and align y to x */
+	if(ix >= -1022)
+	    hx = 0x00100000|(0x000fffff&hx);
+	else {		/* subnormal x, shift x to normal */
+	    n = -1022-ix;
+	    if(n<=31) {
+	        hx = (hx<<n)|(lx>>(32-n));
+	        lx <<= n;
+	    } else {
+		hx = lx<<(n-32);
+		lx = 0;
+	    }
+	}
+	if(iy >= -1022)
+	    hy = 0x00100000|(0x000fffff&hy);
+	else {		/* subnormal y, shift y to normal */
+	    n = -1022-iy;
+	    if(n<=31) {
+	        hy = (hy<<n)|(ly>>(32-n));
+	        ly <<= n;
+	    } else {
+		hy = ly<<(n-32);
+		ly = 0;
+	    }
+	}
+
+    /* fix point fmod */
+	n = ix - iy;
+	q = 0;
+	while(n--) {
+	    hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+	    if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
+	    else {hx = hz+hz+(lz>>31); lx = lz+lz; q++;}
+	    q <<= 1;
+	}
+	hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+	if(hz>=0) {hx=hz;lx=lz;q++;}
+
+    /* convert back to floating value and restore the sign */
+	if((hx|lx)==0) {			/* return sign(x)*0 */
+	    *quo = (sxy ? -q : q);
+	    return Zero[(u_int32_t)sx>>31];
+	}
+	while(hx<0x00100000) {		/* normalize x */
+	    hx = hx+hx+(lx>>31); lx = lx+lx;
+	    iy -= 1;
+	}
+	if(iy>= -1022) {	/* normalize output */
+	    hx = ((hx-0x00100000)|((iy+1023)<<20));
+	} else {		/* subnormal output */
+	    n = -1022 - iy;
+	    if(n<=20) {
+		lx = (lx>>n)|((u_int32_t)hx<<(32-n));
+		hx >>= n;
+	    } else if (n<=31) {
+		lx = (hx<<(32-n))|(lx>>n); hx = sx;
+	    } else {
+		lx = hx>>(n-32); hx = sx;
+	    }
+	}
+fixup:
+	INSERT_WORDS(x,hx,lx);
+	y = fabs(y);
+	if (y < 4.4501477170144027664000e-308) {
+	    if (x+x>y || (x+x==y && (q & 1))) {
+		q++;
+		x-=y;
+	    }
+	} else if (x>0.5*y || (x==0.5*y && (q & 1))) {
+	    q++;
+	    x-=y;
+	}
+	GET_HIGH_WORD(hx,x);
+	SET_HIGH_WORD(x,hx^sx);
+	q &= 0x7fffffff;
+	*quo = (sxy ? -q : q);
+	return x;
+}
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_remquo.c
===================================================================
--- /trunk/libc/src/msun/src/s_remquo.c	(revision 3891)
+++ /trunk/libc/src/msun/src/s_remquo.c	(revision 3892)
@@ -10,4 +10,9 @@
  * ====================================================
  */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_remquo-decimal-constants.c"
+#else
 
 #include "namespace.h"
@@ -152,2 +157,4 @@
 	return x;
 }
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_remquof-decimal-constants.c
===================================================================
--- /trunk/libc/src/msun/src/s_remquof-decimal-constants.c	(revision 3892)
+++ /trunk/libc/src/msun/src/s_remquof-decimal-constants.c	(revision 3892)
@@ -0,0 +1,130 @@
+/* @(#)e_fmod.c 1.3 95/01/18 */
+/*-
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_remquof-decimal-constants.c"
+#else
+
+
+#include "namespace.h"
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/msun/src/s_remquof.c,v 1.1 2005/03/25 04:40:44 das Exp $");
+
+#include "math.h"
+#include "math_private.h"
+
+static const float Zero[] = {0.0, -0.0,};
+
+/*
+ * Return the IEEE remainder and set *quo to the last n bits of the
+ * quotient, rounded to the nearest integer.  We choose n=31 because
+ * we wind up computing all the integer bits of the quotient anyway as
+ * a side-effect of computing the remainder by the shift and subtract
+ * method.  In practice, this is far more bits than are needed to use
+ * remquo in reduction algorithms.
+ */
+float
+remquof(float x, float y, int *quo)
+{
+	int32_t n,hx,hy,hz,ix,iy,sx,i;
+	u_int32_t q,sxy;
+
+	GET_FLOAT_WORD(hx,x);
+	GET_FLOAT_WORD(hy,y);
+	sxy = (hx ^ hy) & 0x80000000;
+	sx = hx&0x80000000;		/* sign of x */
+	hx ^=sx;		/* |x| */
+	hy &= 0x7fffffff;	/* |y| */
+
+    /* purge off exception values */
+	if(hy==0||hx>=0x7f800000||hy>0x7f800000) /* y=0,NaN;or x not finite */
+	    return (x*y)/(x*y);
+	if(hx<hy) {
+	    q = 0;
+	    goto fixup;	/* |x|<|y| return x or x-y */
+	} else if(hx==hy) {
+	    *quo = 1;
+	    return Zero[(u_int32_t)sx>>31];	/* |x|=|y| return x*0*/
+	}
+
+    /* determine ix = ilogb(x) */
+	if(hx<0x00800000) {	/* subnormal x */
+	    for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1;
+	} else ix = (hx>>23)-127;
+
+    /* determine iy = ilogb(y) */
+	if(hy<0x00800000) {	/* subnormal y */
+	    for (iy = -126,i=(hy<<8); i>0; i<<=1) iy -=1;
+	} else iy = (hy>>23)-127;
+
+    /* set up {hx,lx}, {hy,ly} and align y to x */
+	if(ix >= -126)
+	    hx = 0x00800000|(0x007fffff&hx);
+	else {		/* subnormal x, shift x to normal */
+	    n = -126-ix;
+	    hx <<= n;
+	}
+	if(iy >= -126)
+	    hy = 0x00800000|(0x007fffff&hy);
+	else {		/* subnormal y, shift y to normal */
+	    n = -126-iy;
+	    hy <<= n;
+	}
+
+    /* fix point fmod */
+	n = ix - iy;
+	q = 0;
+	while(n--) {
+	    hz=hx-hy;
+	    if(hz<0) hx = hx << 1;
+	    else {hx = hz << 1; q++;}
+	    q <<= 1;
+	}
+	hz=hx-hy;
+	if(hz>=0) {hx=hz;q++;}
+
+    /* convert back to floating value and restore the sign */
+	if(hx==0) {				/* return sign(x)*0 */
+	    *quo = (sxy ? -q : q);
+	    return Zero[(u_int32_t)sx>>31];
+	}
+	while(hx<0x00800000) {		/* normalize x */
+	    hx <<= 1;
+	    iy -= 1;
+	}
+	if(iy>= -126) {		/* normalize output */
+	    hx = ((hx-0x00800000)|((iy+127)<<23));
+	} else {		/* subnormal output */
+	    n = -126 - iy;
+	    hx >>= n;
+	}
+fixup:
+	SET_FLOAT_WORD(x,hx);
+	y = fabsf(y);
+	if (y < 2.3509887016445750160000e-38f) {
+	    if (x+x>y || (x+x==y && (q & 1))) {
+		q++;
+		x-=y;
+	    }
+	} else if (x>0.5f*y || (x==0.5f*y && (q & 1))) {
+	    q++;
+	    x-=y;
+	}
+	GET_FLOAT_WORD(hx,x);
+	SET_FLOAT_WORD(x,hx^sx);
+	q &= 0x7fffffff;
+	*quo = (sxy ? -q : q);
+	return x;
+}
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_remquof.c
===================================================================
--- /trunk/libc/src/msun/src/s_remquof.c	(revision 3891)
+++ /trunk/libc/src/msun/src/s_remquof.c	(revision 3892)
@@ -10,4 +10,10 @@
  * ====================================================
  */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_remquof-decimal-constants.c"
+#else
+
 
 #include "namespace.h"
@@ -121,2 +127,4 @@
 	return x;
 }
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_scalbnl-decimal-constants.c
===================================================================
--- /trunk/libc/src/msun/src/s_scalbnl-decimal-constants.c	(revision 3892)
+++ /trunk/libc/src/msun/src/s_scalbnl-decimal-constants.c	(revision 3892)
@@ -0,0 +1,79 @@
+/* @(#)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.
+ * ====================================================
+ */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_scalbnl-decimal-constants.c"
+#else
+
+#include "namespace.h"
+#ifndef lint
+static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_scalbnl.c,v 1.1 2005/03/07 04:52:58 das Exp $";
+#endif
+
+/*
+ * scalbnl (long double x, int n)
+ * scalbnl(x,n) returns x* 2**n  computed by  exponent
+ * manipulation rather than by actually performing an
+ * exponentiation or a multiplication.
+ */
+
+/*
+ * We assume that a long double has a 15-bit exponent.  On systems
+ * where long double is the same as double, scalbnl() is an alias
+ * for scalbn(), so we don't use this routine.
+ */
+
+#include <sys/cdefs.h>
+#include <float.h>
+#include <math.h>
+
+#include "fpmath.h"
+
+#if LDBL_MAX_EXP != 0x4000
+#error "Unsupported long double format"
+#endif
+
+static const long double
+huge = 0.0000000000000000000000e+00L,
+tiny = 0.0000000000000000000000e+00L;
+
+long double
+_STD(scalbnl) (long double x, int n)
+{
+	union IEEEl2bits u;
+	int k;
+	u.e = x;
+        k = u.bits.exp;				/* extract exponent */
+        if (k==0) {				/* 0 or subnormal x */
+            if ((u.bits.manh|u.bits.manl)==0) return x;	/* +-0 */
+	    u.e *= 3.4028236692093846345000e+38;
+	    k = u.bits.exp - 128;
+            if (n< -50000) return tiny*x; 	/*underflow*/
+	    }
+        if (k==0x7fff) return x+x;		/* NaN or Inf */
+        k = k+n;
+        if (k >= 0x7fff) return huge*copysignl(huge,x); /* overflow  */
+        if (k > 0) 				/* normal result */
+	    {u.bits.exp = k; return u.e;}
+        if (k <= -128)
+            if (n > 50000) 	/* in case integer overflow in n+k */
+		return huge*copysign(huge,x);	/*overflow*/
+	    else return tiny*copysign(tiny,x); 	/*underflow*/
+        k += 128;				/* subnormal result */
+	u.bits.exp = k;
+        return u.e*2.9387358770557187700000e-39;
+}
+
+__strong_reference(_std_scalbnl, _std_ldexpl);
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_scalbnl.c
===================================================================
--- /trunk/libc/src/msun/src/s_scalbnl.c	(revision 3891)
+++ /trunk/libc/src/msun/src/s_scalbnl.c	(revision 3892)
@@ -10,4 +10,9 @@
  * ====================================================
  */
+
+#if (defined(_MSC_VER) || defined(__WATCOMC__)) && !defined(MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED)
+# define MSUN_DECIMAL_CONSTANTS_SOURCE_INCLUDED
+# include "s_scalbnl-decimal-constants.c"
+#else
 
 #include "namespace.h"
@@ -71,2 +76,4 @@
 
 __strong_reference(_std_scalbnl, _std_ldexpl);
+#endif /* !_MSC_VER && !__WATCOMC__ */
+
Index: /trunk/libc/src/msun/src/s_truncl.c
===================================================================
--- /trunk/libc/src/msun/src/s_truncl.c	(revision 3891)
+++ /trunk/libc/src/msun/src/s_truncl.c	(revision 3892)
@@ -43,6 +43,14 @@
 truncl(long double x)
 {
+#ifdef __GNUC__
 	union IEEEl2bits u = { .e = x };
 	int e = u.bits.exp - LDBL_MAX_EXP + 1;
+#else
+	union IEEEl2bits u;
+	int e;
+
+	u.e = x;
+	e = u.bits.exp - LDBL_MAX_EXP + 1;
+#endif
 
 	if (e < MANH_SIZE - 1) {
