1*b5aa3b33Sguenther /* $OpenBSD: fabs.c,v 1.12 2014/04/18 15:09:52 guenther Exp $ */
2aeb694e3Smartynas /*
3aeb694e3Smartynas * Copyright (c) 2006 Miodrag Vallat.
4aeb694e3Smartynas *
5aeb694e3Smartynas * Permission to use, copy, modify, and distribute this software for any
6aeb694e3Smartynas * purpose with or without fee is hereby granted, provided that the above
7aeb694e3Smartynas * copyright notice, this permission notice, and the disclaimer below
8aeb694e3Smartynas * appear in all copies.
9aeb694e3Smartynas *
10aeb694e3Smartynas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11aeb694e3Smartynas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12aeb694e3Smartynas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13aeb694e3Smartynas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14aeb694e3Smartynas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15aeb694e3Smartynas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16aeb694e3Smartynas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17aeb694e3Smartynas */
18aeb694e3Smartynas
19aeb694e3Smartynas #if !defined(__SH4__) || defined(__SH4_NOFPU__)
20aeb694e3Smartynas #include <sys/types.h>
21aeb694e3Smartynas #include <machine/ieee.h>
22aeb694e3Smartynas #endif /* !defined(__SH4__) || defined(__SH4_NOFPU__) */
23aeb694e3Smartynas
24aeb694e3Smartynas #include <math.h>
25aeb694e3Smartynas
26aeb694e3Smartynas double
fabs(double d)27aeb694e3Smartynas fabs(double d)
28aeb694e3Smartynas {
29aeb694e3Smartynas #if defined(__SH4__) && !defined(__SH4_NOFPU__)
30*b5aa3b33Sguenther __asm__ volatile("fabs %0" : "+f" (d));
31aeb694e3Smartynas #else
32aeb694e3Smartynas struct ieee_double *p = (struct ieee_double *)&d;
33aeb694e3Smartynas
34aeb694e3Smartynas p->dbl_sign = 0;
35aeb694e3Smartynas #endif
36aeb694e3Smartynas return (d);
37aeb694e3Smartynas }
38aeb694e3Smartynas
392fbf033eSmartynas __strong_alias(fabsl, fabs);
40