1131320Sdas/*-
2131320Sdas * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
3131320Sdas * All rights reserved.
4131320Sdas *
5131320Sdas * Redistribution and use in source and binary forms, with or without
6131320Sdas * modification, are permitted provided that the following conditions
7131320Sdas * are met:
8131320Sdas * 1. Redistributions of source code must retain the above copyright
9131320Sdas *    notice, this list of conditions and the following disclaimer.
10131320Sdas * 2. Redistributions in binary form must reproduce the above copyright
11131320Sdas *    notice, this list of conditions and the following disclaimer in the
12131320Sdas *    documentation and/or other materials provided with the distribution.
13131320Sdas *
14131320Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15131320Sdas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16131320Sdas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17131320Sdas * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18131320Sdas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19131320Sdas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20131320Sdas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21131320Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22131320Sdas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23131320Sdas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24131320Sdas * SUCH DAMAGE.
25131320Sdas */
26131320Sdas
27131320Sdas#include <sys/cdefs.h>
28131320Sdas__FBSDID("$FreeBSD$");
29131320Sdas
30131320Sdas#include <math.h>
31131320Sdas
32131320Sdas#define	DECL(type, fn)			\
33131320Sdastype					\
34131320Sdasfn(type x, type y)			\
35131320Sdas{					\
36131320Sdas					\
37131320Sdas	if (isnan(x))			\
38131320Sdas		return (x);		\
39131320Sdas	if (isnan(y))			\
40131320Sdas		return (y);		\
41131320Sdas	return (x > y ? x - y : 0.0);	\
42131320Sdas}
43131320Sdas
44131320SdasDECL(double, fdim)
45131320SdasDECL(float, fdimf)
46131320SdasDECL(long double, fdiml)
47