1255294Stheraven/*-
2255294Stheraven * Copyright (c) 2013 David Chisnall
3255294Stheraven * All rights reserved.
4255294Stheraven *
5255294Stheraven * Redistribution and use in source and binary forms, with or without
6255294Stheraven * modification, are permitted provided that the following conditions
7255294Stheraven * are met:
8255294Stheraven * 1. Redistributions of source code must retain the above copyright
9255294Stheraven *    notice, this list of conditions and the following disclaimer.
10255294Stheraven * 2. Redistributions in binary form must reproduce the above copyright
11255294Stheraven *    notice, this list of conditions and the following disclaimer in the
12255294Stheraven *    documentation and/or other materials provided with the distribution.
13255294Stheraven *
14255294Stheraven * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15255294Stheraven * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16255294Stheraven * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17255294Stheraven * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18255294Stheraven * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19255294Stheraven * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20255294Stheraven * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21255294Stheraven * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22255294Stheraven * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23255294Stheraven * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24255294Stheraven * SUCH DAMAGE.
25255294Stheraven *
26255294Stheraven * $FreeBSD: stable/11/lib/msun/src/imprecise.c 336767 2018-07-27 17:39:36Z dim $
27255294Stheraven */
28255294Stheraven
29255294Stheraven#include <float.h>
30255294Stheraven#include <math.h>
31255294Stheraven
32255294Stheraven/*
33255294Stheraven * If long double is not the same size as double, then these will lose
34255294Stheraven * precision and we should emit a warning whenever something links against
35255294Stheraven * them.
36255294Stheraven */
37255294Stheraven#if (LDBL_MANT_DIG > 53)
38255294Stheraven#define WARN_IMPRECISE(x) \
39255294Stheraven	__warn_references(x, # x " has lower than advertised precision");
40255294Stheraven#else
41255294Stheraven#define WARN_IMPRECISE(x)
42255294Stheraven#endif
43255294Stheraven/*
44255294Stheraven * Declare the functions as weak variants so that other libraries providing
45255294Stheraven * real versions can override them.
46255294Stheraven */
47255294Stheraven#define	DECLARE_WEAK(x)\
48255294Stheraven	__weak_reference(imprecise_## x, x);\
49255294Stheraven	WARN_IMPRECISE(x)
50255294Stheraven
51255294Stheraven#define DECLARE_IMPRECISE(f) \
52255294Stheraven	long double imprecise_ ## f ## l(long double v) { return f(v); }\
53255294Stheraven	DECLARE_WEAK(f ## l)
54255294Stheraven
55255294StheravenDECLARE_IMPRECISE(tgamma);
56