103a88e3dSMark Murray /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 303a88e3dSMark Murray * 403a88e3dSMark Murray * Copyright (c) 2013 David Chisnall 503a88e3dSMark Murray * All rights reserved. 603a88e3dSMark Murray * 703a88e3dSMark Murray * Redistribution and use in source and binary forms, with or without 803a88e3dSMark Murray * modification, are permitted provided that the following conditions 903a88e3dSMark Murray * are met: 1003a88e3dSMark Murray * 1. Redistributions of source code must retain the above copyright 1103a88e3dSMark Murray * notice, this list of conditions and the following disclaimer. 1203a88e3dSMark Murray * 2. Redistributions in binary form must reproduce the above copyright 1303a88e3dSMark Murray * notice, this list of conditions and the following disclaimer in the 1403a88e3dSMark Murray * documentation and/or other materials provided with the distribution. 1503a88e3dSMark Murray * 1603a88e3dSMark Murray * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1703a88e3dSMark Murray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1803a88e3dSMark Murray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1903a88e3dSMark Murray * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2003a88e3dSMark Murray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2103a88e3dSMark Murray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2203a88e3dSMark Murray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2303a88e3dSMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2403a88e3dSMark Murray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2503a88e3dSMark Murray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2603a88e3dSMark Murray * SUCH DAMAGE. 2703a88e3dSMark Murray * 2803a88e3dSMark Murray * $FreeBSD$ 2903a88e3dSMark Murray */ 3003a88e3dSMark Murray 3103a88e3dSMark Murray #include <float.h> 3203a88e3dSMark Murray #include <math.h> 3303a88e3dSMark Murray 3403a88e3dSMark Murray /* 3503a88e3dSMark Murray * If long double is not the same size as double, then these will lose 3603a88e3dSMark Murray * precision and we should emit a warning whenever something links against 3703a88e3dSMark Murray * them. 3803a88e3dSMark Murray */ 3903a88e3dSMark Murray #if (LDBL_MANT_DIG > 53) 4003a88e3dSMark Murray #define WARN_IMPRECISE(x) \ 4103a88e3dSMark Murray __warn_references(x, # x " has lower than advertised precision"); 4203a88e3dSMark Murray #else 4303a88e3dSMark Murray #define WARN_IMPRECISE(x) 4403a88e3dSMark Murray #endif 4503a88e3dSMark Murray /* 4603a88e3dSMark Murray * Declare the functions as weak variants so that other libraries providing 4703a88e3dSMark Murray * real versions can override them. 4803a88e3dSMark Murray */ 4903a88e3dSMark Murray #define DECLARE_WEAK(x)\ 5003a88e3dSMark Murray __weak_reference(imprecise_## x, x);\ 5103a88e3dSMark Murray WARN_IMPRECISE(x) 5203a88e3dSMark Murray 5303a88e3dSMark Murray #define DECLARE_IMPRECISE(f) \ 5403a88e3dSMark Murray long double imprecise_ ## f ## l(long double v) { return f(v); }\ 5503a88e3dSMark Murray DECLARE_WEAK(f ## l) 5603a88e3dSMark Murray 5703a88e3dSMark Murray DECLARE_IMPRECISE(tgamma); 58