diff options
| author | 2008-07-23 18:11:13 +0000 | |
|---|---|---|
| committer | 2008-07-23 18:11:13 +0000 | |
| commit | 67ed3a45ca7d949909c464480b330eaae034c6ac (patch) | |
| tree | e0eb8a810f10c9dbc2e6f7b02c4e64001d0eb161 /lib/libc/arch/sh/gen/fabs.c | |
| parent | sync (diff) | |
| download | wireguard-openbsd-67ed3a45ca7d949909c464480b330eaae034c6ac.tar.xz wireguard-openbsd-67ed3a45ca7d949909c464480b330eaae034c6ac.zip | |
clear sign bit, instead of comparing to zero and setting x=-x.
fixes special cases, such as neg. zero, and makes C99 conformant
ok miod@, millert@
since there's nothing else in arm's fabs.c, replace 4-clause license
w/ the one at /usr/share/misc/license.template
Diffstat (limited to 'lib/libc/arch/sh/gen/fabs.c')
| -rw-r--r-- | lib/libc/arch/sh/gen/fabs.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/libc/arch/sh/gen/fabs.c b/lib/libc/arch/sh/gen/fabs.c index 116e8b4139a..cadfc0e03ed 100644 --- a/lib/libc/arch/sh/gen/fabs.c +++ b/lib/libc/arch/sh/gen/fabs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fabs.c,v 1.3 2007/03/02 06:11:54 miod Exp $ */ +/* $OpenBSD: fabs.c,v 1.4 2008/07/23 18:11:14 martynas Exp $ */ /* * Copyright (c) 2006 Miodrag Vallat. * @@ -16,16 +16,22 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#if !defined(__SH4__) || defined(__SH4_NOFPU__) +#include <sys/types.h> +#include <machine/ieee.h> +#endif /* !defined(__SH4__) || defined(__SH4_NOFPU__) */ + #include <math.h> double -fabs(double x) +fabs(double d) { #if defined(__SH4__) && !defined(__SH4_NOFPU__) - __asm__ __volatile__("fabs %0" : "=f"(x)); + __asm__ __volatile__("fabs %0" : "=f"(d)); #else - if (x < 0) - x = -x; + struct ieee_double *p = (struct ieee_double *)&d; + + p->dbl_sign = 0; #endif - return (x); + return (d); } |
