1967141b1SJohn Marino /*-
2967141b1SJohn Marino * Copyright (c) 2013 David Chisnall
3967141b1SJohn Marino * All rights reserved.
4967141b1SJohn Marino *
5967141b1SJohn Marino * Redistribution and use in source and binary forms, with or without
6967141b1SJohn Marino * modification, are permitted provided that the following conditions
7967141b1SJohn Marino * are met:
8967141b1SJohn Marino * 1. Redistributions of source code must retain the above copyright
9967141b1SJohn Marino * notice, this list of conditions and the following disclaimer.
10967141b1SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
11967141b1SJohn Marino * notice, this list of conditions and the following disclaimer in the
12967141b1SJohn Marino * documentation and/or other materials provided with the distribution.
13967141b1SJohn Marino *
14967141b1SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15967141b1SJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16967141b1SJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17967141b1SJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18967141b1SJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19967141b1SJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20967141b1SJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21967141b1SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22967141b1SJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23967141b1SJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24967141b1SJohn Marino * SUCH DAMAGE.
25967141b1SJohn Marino *
26967141b1SJohn Marino * $FreeBSD: head/lib/msun/src/imprecise.c 255294 2013-09-06 07:58:23Z theraven $
27967141b1SJohn Marino */
28967141b1SJohn Marino
29967141b1SJohn Marino #include <float.h>
30967141b1SJohn Marino #include <math.h>
31967141b1SJohn Marino
32967141b1SJohn Marino /*
33967141b1SJohn Marino * If long double is not the same size as double, then these will lose
34967141b1SJohn Marino * precision and we should emit a warning whenever something links against
35967141b1SJohn Marino * them.
36967141b1SJohn Marino */
37967141b1SJohn Marino #if (LDBL_MANT_DIG > 53)
38967141b1SJohn Marino #define WARN_IMPRECISE(x) \
39967141b1SJohn Marino __warn_references(x, # x " has lower than advertised precision");
40967141b1SJohn Marino #else
41967141b1SJohn Marino #define WARN_IMPRECISE(x)
42967141b1SJohn Marino #endif
43967141b1SJohn Marino /*
44967141b1SJohn Marino * Declare the functions as weak variants so that other libraries providing
45967141b1SJohn Marino * real versions can override them.
46967141b1SJohn Marino */
47967141b1SJohn Marino #define DECLARE_WEAK(x)\
48967141b1SJohn Marino __weak_reference(imprecise_## x, x);\
49967141b1SJohn Marino WARN_IMPRECISE(x)
50967141b1SJohn Marino
512fedfd5cSJohn Marino #define DECLARE_FORMER_IMPRECISE(f) \
52*404c8a26SSascha Wildner __sym_compat(f ## l, imprecise_ ## f ## l, DF306.1); \
532fedfd5cSJohn Marino long double imprecise_ ## f ## l(long double v) { return f(v); }
542fedfd5cSJohn Marino
55be0c75e8SJohn Marino #pragma GCC diagnostic push
56be0c75e8SJohn Marino #pragma GCC diagnostic ignored "-Wmissing-prototypes"
57967141b1SJohn Marino
58*404c8a26SSascha Wildner __sym_compat(powl, imprecise_powl, DF306.1);
59be0c75e8SJohn Marino long double
imprecise_powl(long double x,long double y)60be0c75e8SJohn Marino imprecise_powl(long double x, long double y) { return pow(x, y); }
61be0c75e8SJohn Marino
622fedfd5cSJohn Marino DECLARE_FORMER_IMPRECISE(cosh);
632fedfd5cSJohn Marino DECLARE_FORMER_IMPRECISE(erfc);
642fedfd5cSJohn Marino DECLARE_FORMER_IMPRECISE(erf);
652fedfd5cSJohn Marino DECLARE_FORMER_IMPRECISE(sinh);
662fedfd5cSJohn Marino DECLARE_FORMER_IMPRECISE(tanh);
672fedfd5cSJohn Marino DECLARE_FORMER_IMPRECISE(tgamma);
68be0c75e8SJohn Marino DECLARE_FORMER_IMPRECISE(lgamma);
69be0c75e8SJohn Marino
70be0c75e8SJohn Marino #pragma GCC diagnostic pop
71