From 9da547ff2644ebcb2ef964ef278072deff6ea84d Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Sat, 9 Nov 2002 10:44:02 +0000 Subject: [PATCH] * include/math.h (sqrt): Remove inline definition. (sqrtf): Replace inline definition with prototype. (sqrtl): Likewise. * mingwex/math/sqrtf.c (sqrtf): Set domain error if argument less than zero. * mingwex/math/sqrtf.c (sqrtl): Likewise. Correct typo in 2002-10-30 ChangeLog entry. --- winsup/mingw/include/math.h | 21 ++------------------- winsup/mingw/mingwex/math/sqrtf.c | 17 ++++++++++++++--- winsup/mingw/mingwex/math/sqrtl.c | 18 +++++++++++++++--- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/winsup/mingw/include/math.h b/winsup/mingw/include/math.h index 488493895..fbfd712c0 100644 --- a/winsup/mingw/include/math.h +++ b/winsup/mingw/include/math.h @@ -144,12 +144,6 @@ double log (double); double log10 (double); double pow (double, double); double sqrt (double); -extern __inline__ double sqrt (double x) -{ - double res; - __asm__ ("fsqrt;" : "=t" (res) : "0" (x)); - return res; -} double ceil (double); double floor (double); double fabs (double); @@ -504,19 +498,8 @@ extern __inline__ float powf (float x, float y) extern long double powl (long double, long double); /* 7.12.7.5 The sqrt functions. Double in C89. */ -extern __inline__ float sqrtf (float x) -{ - float res; - __asm__ ("fsqrt" : "=t" (res) : "0" (x)); - return res; -} - -extern __inline__ long double sqrtl (long double x) -{ - long double res; - __asm__ ("fsqrt" : "=t" (res) : "0" (x)); - return res; -} +extern float sqrtf (float); +extern long double sqrtl (long double); /* 7.12.8 Error and gamma functions: TODO */ diff --git a/winsup/mingw/mingwex/math/sqrtf.c b/winsup/mingw/mingwex/math/sqrtf.c index 55ca39dbe..b1029cad8 100644 --- a/winsup/mingw/mingwex/math/sqrtf.c +++ b/winsup/mingw/mingwex/math/sqrtf.c @@ -1,9 +1,20 @@ #include +#include + +extern float __QNANF; float sqrtf (float x) { - float res; - asm ("fsqrt" : "=t" (res) : "0" (x)); - return res; + if (x < 0.0F ) + { + errno = EDOM; + return __QNANF; + } + else + { + float res; + asm ("fsqrt" : "=t" (res) : "0" (x)); + return res; + } } diff --git a/winsup/mingw/mingwex/math/sqrtl.c b/winsup/mingw/mingwex/math/sqrtl.c index 0bd301390..dba68d878 100644 --- a/winsup/mingw/mingwex/math/sqrtl.c +++ b/winsup/mingw/mingwex/math/sqrtl.c @@ -1,8 +1,20 @@ #include +#include + +extern long double __QNANL; + long double sqrtl (long double x) { - long double res; - asm ("fsqrt" : "=t" (res) : "0" (x)); - return res; + if (x < 0.0L ) + { + errno = EDOM; + return __QNANL; + } + else + { + long double res; + asm ("fsqrt" : "=t" (res) : "0" (x)); + return res; + } } -- 2.43.5