1*c30c1fceSderaadt /* $OpenBSD: fabs.c,v 1.1 2021/06/19 18:43:28 deraadt Exp $ */
2*c30c1fceSderaadt /*
3*c30c1fceSderaadt * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org>
4*c30c1fceSderaadt *
5*c30c1fceSderaadt * Permission to use, copy, modify, and distribute this software for any
6*c30c1fceSderaadt * purpose with or without fee is hereby granted, provided that the above
7*c30c1fceSderaadt * copyright notice and this permission notice appear in all copies.
8*c30c1fceSderaadt *
9*c30c1fceSderaadt * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*c30c1fceSderaadt * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*c30c1fceSderaadt * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*c30c1fceSderaadt * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*c30c1fceSderaadt * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*c30c1fceSderaadt * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*c30c1fceSderaadt * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*c30c1fceSderaadt */
17*c30c1fceSderaadt
18*c30c1fceSderaadt #include <sys/types.h>
19*c30c1fceSderaadt #include <machine/ieee.h>
20*c30c1fceSderaadt #include <math.h>
21*c30c1fceSderaadt
22*c30c1fceSderaadt /*
23*c30c1fceSderaadt * fabs(d) returns the absolute value of d.
24*c30c1fceSderaadt */
25*c30c1fceSderaadt double
fabs(double d)26*c30c1fceSderaadt fabs(double d)
27*c30c1fceSderaadt {
28*c30c1fceSderaadt struct ieee_double *p = (struct ieee_double *)&d;
29*c30c1fceSderaadt
30*c30c1fceSderaadt p->dbl_sign = 0;
31*c30c1fceSderaadt
32*c30c1fceSderaadt return(d);
33*c30c1fceSderaadt }
34*c30c1fceSderaadt
35*c30c1fceSderaadt __strong_alias(fabsl, fabs);
36