1*03a88e3dSMark Murray /*- 2*03a88e3dSMark Murray * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*03a88e3dSMark Murray * 4*03a88e3dSMark Murray * Copyright (c) 2013 David Chisnall 5*03a88e3dSMark Murray * All rights reserved. 6*03a88e3dSMark Murray * 7*03a88e3dSMark Murray * Redistribution and use in source and binary forms, with or without 8*03a88e3dSMark Murray * modification, are permitted provided that the following conditions 9*03a88e3dSMark Murray * are met: 10*03a88e3dSMark Murray * 1. Redistributions of source code must retain the above copyright 11*03a88e3dSMark Murray * notice, this list of conditions and the following disclaimer. 12*03a88e3dSMark Murray * 2. Redistributions in binary form must reproduce the above copyright 13*03a88e3dSMark Murray * notice, this list of conditions and the following disclaimer in the 14*03a88e3dSMark Murray * documentation and/or other materials provided with the distribution. 15*03a88e3dSMark Murray * 16*03a88e3dSMark Murray * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*03a88e3dSMark Murray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*03a88e3dSMark Murray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*03a88e3dSMark Murray * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*03a88e3dSMark Murray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*03a88e3dSMark Murray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*03a88e3dSMark Murray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*03a88e3dSMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*03a88e3dSMark Murray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*03a88e3dSMark Murray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*03a88e3dSMark Murray * SUCH DAMAGE. 27*03a88e3dSMark Murray * 28*03a88e3dSMark Murray * $FreeBSD$ 29*03a88e3dSMark Murray */ 30*03a88e3dSMark Murray 31*03a88e3dSMark Murray #include <float.h> 32*03a88e3dSMark Murray #include <math.h> 33*03a88e3dSMark Murray 34*03a88e3dSMark Murray /* 35*03a88e3dSMark Murray * If long double is not the same size as double, then these will lose 36*03a88e3dSMark Murray * precision and we should emit a warning whenever something links against 37*03a88e3dSMark Murray * them. 38*03a88e3dSMark Murray */ 39*03a88e3dSMark Murray #if (LDBL_MANT_DIG > 53) 40*03a88e3dSMark Murray #define WARN_IMPRECISE(x) \ 41*03a88e3dSMark Murray __warn_references(x, # x " has lower than advertised precision"); 42*03a88e3dSMark Murray #else 43*03a88e3dSMark Murray #define WARN_IMPRECISE(x) 44*03a88e3dSMark Murray #endif 45*03a88e3dSMark Murray /* 46*03a88e3dSMark Murray * Declare the functions as weak variants so that other libraries providing 47*03a88e3dSMark Murray * real versions can override them. 48*03a88e3dSMark Murray */ 49*03a88e3dSMark Murray #define DECLARE_WEAK(x)\ 50*03a88e3dSMark Murray __weak_reference(imprecise_## x, x);\ 51*03a88e3dSMark Murray WARN_IMPRECISE(x) 52*03a88e3dSMark Murray 53*03a88e3dSMark Murray #define DECLARE_IMPRECISE(f) \ 54*03a88e3dSMark Murray long double imprecise_ ## f ## l(long double v) { return f(v); }\ 55*03a88e3dSMark Murray DECLARE_WEAK(f ## l) 56*03a88e3dSMark Murray 57*03a88e3dSMark Murray DECLARE_IMPRECISE(tgamma); 58