summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartynas Venckus <martynas@cvs.openbsd.org>2008-09-11 19:18:13 +0000
committerMartynas Venckus <martynas@cvs.openbsd.org>2008-09-11 19:18:13 +0000
commitb8e0d3559dbceca79679a207768039a158696912 (patch)
tree1d38c2eb538c33f1267a43051fb2e41be17716ef
parent98998cdcc8756568297d7c3144acd9e209657ded (diff)
- make much more readable: don't reimplement isnan, signbit each
time we need them ok millert@
-rw-r--r--lib/libm/src/s_fmax.c24
-rw-r--r--lib/libm/src/s_fmaxf.c20
-rw-r--r--lib/libm/src/s_fmin.c24
-rw-r--r--lib/libm/src/s_fminf.c20
4 files changed, 32 insertions, 56 deletions
diff --git a/lib/libm/src/s_fmax.c b/lib/libm/src/s_fmax.c
index 76f91272f2c..7ea5b8dc4db 100644
--- a/lib/libm/src/s_fmax.c
+++ b/lib/libm/src/s_fmax.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: s_fmax.c,v 1.1 2008/09/07 20:36:09 martynas Exp $ */
+/* $OpenBSD: s_fmax.c,v 1.2 2008/09/11 19:18:12 martynas Exp $ */
/*-
* Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
@@ -25,31 +25,23 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
-#include <machine/ieee.h>
#include <math.h>
double
fmax(double x, double y)
{
- struct ieee_double *px = (struct ieee_double *)&x;
- struct ieee_double *py = (struct ieee_double *)&y;
-
/* Check for NaNs to avoid raising spurious exceptions. */
- if (px->dbl_exp == DBL_EXP_INFNAN &&
- (px->dbl_frach | px->dbl_fracl) != 0)
+ if (isnan(x))
return (y);
- if (py->dbl_exp == DBL_EXP_INFNAN &&
- (py->dbl_frach | py->dbl_fracl) != 0)
+ if (isnan(y))
return (x);
/* Handle comparisons of signed zeroes. */
- if (px->dbl_sign != py->dbl_sign &&
- px->dbl_sign == 1)
- return (y);
- if (px->dbl_sign != py->dbl_sign &&
- px->dbl_sign == 0)
- return (x);
+ if (signbit(x) != signbit(y))
+ if (signbit(x))
+ return (y);
+ else
+ return (x);
return (x > y ? x : y);
}
diff --git a/lib/libm/src/s_fmaxf.c b/lib/libm/src/s_fmaxf.c
index 472372950d8..7cd2c39edb5 100644
--- a/lib/libm/src/s_fmaxf.c
+++ b/lib/libm/src/s_fmaxf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: s_fmaxf.c,v 1.1 2008/09/07 20:36:09 martynas Exp $ */
+/* $OpenBSD: s_fmaxf.c,v 1.2 2008/09/11 19:18:12 martynas Exp $ */
/*-
* Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
@@ -25,27 +25,23 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
-#include <machine/ieee.h>
#include <math.h>
float
fmaxf(float x, float y)
{
- struct ieee_single *px = (struct ieee_single *)&x;
- struct ieee_single *py = (struct ieee_single *)&y;
-
/* Check for NaNs to avoid raising spurious exceptions. */
- if (px->sng_exp == SNG_EXP_INFNAN && px->sng_frac != 0)
+ if (isnan(x))
return (y);
- if (py->sng_exp == SNG_EXP_INFNAN && py->sng_frac != 0)
+ if (isnan(y))
return (x);
/* Handle comparisons of signed zeroes. */
- if (px->sng_sign != py->sng_sign && px->sng_sign == 1)
- return (y);
- if (px->sng_sign != py->sng_sign && px->sng_sign == 0)
- return (x);
+ if (signbit(x) != signbit(y))
+ if (signbit(x))
+ return (y);
+ else
+ return (x);
return (x > y ? x : y);
}
diff --git a/lib/libm/src/s_fmin.c b/lib/libm/src/s_fmin.c
index 47c5d9a67a9..7309a6ffd98 100644
--- a/lib/libm/src/s_fmin.c
+++ b/lib/libm/src/s_fmin.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: s_fmin.c,v 1.1 2008/09/07 20:36:09 martynas Exp $ */
+/* $OpenBSD: s_fmin.c,v 1.2 2008/09/11 19:18:12 martynas Exp $ */
/*-
* Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
@@ -25,31 +25,23 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
-#include <machine/ieee.h>
#include <math.h>
double
fmin(double x, double y)
{
- struct ieee_double *px = (struct ieee_double *)&x;
- struct ieee_double *py = (struct ieee_double *)&y;
-
/* Check for NaNs to avoid raising spurious exceptions. */
- if (px->dbl_exp == DBL_EXP_INFNAN &&
- (px->dbl_frach | px->dbl_fracl) != 0)
+ if (isnan(x))
return (y);
- if (py->dbl_exp == DBL_EXP_INFNAN &&
- (py->dbl_frach | py->dbl_fracl) != 0)
+ if (isnan(y))
return (x);
/* Handle comparisons of signed zeroes. */
- if (px->dbl_sign != py->dbl_sign &&
- py->dbl_sign == 1)
- return (y);
- if (px->dbl_sign != py->dbl_sign &&
- py->dbl_sign == 0)
- return (x);
+ if (signbit(x) != signbit(y))
+ if (signbit(y))
+ return (y);
+ else
+ return (x);
return (x < y ? x : y);
}
diff --git a/lib/libm/src/s_fminf.c b/lib/libm/src/s_fminf.c
index 37de5c63e83..4567fbcd627 100644
--- a/lib/libm/src/s_fminf.c
+++ b/lib/libm/src/s_fminf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: s_fminf.c,v 1.1 2008/09/07 20:36:09 martynas Exp $ */
+/* $OpenBSD: s_fminf.c,v 1.2 2008/09/11 19:18:12 martynas Exp $ */
/*-
* Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
@@ -25,27 +25,23 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
-#include <machine/ieee.h>
#include <math.h>
float
fminf(float x, float y)
{
- struct ieee_single *px = (struct ieee_single *)&x;
- struct ieee_single *py = (struct ieee_single *)&y;
-
/* Check for NaNs to avoid raising spurious exceptions. */
- if (px->sng_exp == SNG_EXP_INFNAN && px->sng_frac != 0)
+ if (isnan(x))
return (y);
- if (py->sng_exp == SNG_EXP_INFNAN && py->sng_frac != 0)
+ if (isnan(y))
return (x);
/* Handle comparisons of signed zeroes. */
- if (px->sng_sign != py->sng_sign && py->sng_sign == 1)
- return (y);
- if (px->sng_sign != py->sng_sign && py->sng_sign == 0)
- return (x);
+ if (signbit(x) != signbit(y))
+ if (signbit(y))
+ return (y);
+ else
+ return (x);
return (x < y ? x : y);
}