1 /* $NetBSD: mathimpl.h,v 1.10 2011/11/02 02:34:56 christos Exp $ */
3 * Copyright (c) 1988, 1993
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * @(#)mathimpl.h 8.1 (Berkeley) 6/4/93
32 #ifndef _NOIEEE_SRC_MATHIMPL_H_
33 #define _NOIEEE_SRC_MATHIMPL_H_
35 #include <sys/cdefs.h>
39 #if defined(__vax__) || defined(tahoe)
41 /* Deal with different ways to concatenate in cpp */
42 #define cat3(a,b,c) a ## b ## c
44 /* Deal with vax/tahoe byte order issues */
46 # define cat3t(a,b,c) cat3(a,b,c)
48 # define cat3t(a,b,c) cat3(a,c,b)
51 # define vccast(name) (cat3(__,name,x).d)
54 * Define a constant to high precision on a Vax or Tahoe.
56 * Args are the name to define, the decimal floating point value,
57 * four 16-bit chunks of the float value in hex
58 * (because the vax and tahoe differ in float format!), the power
59 * of 2 of the hex-float exponent, and the hex-float mantissa.
60 * Most of these arguments are not used at compile time; they are
61 * used in a post-check to make sure the constants were compiled
64 * People who want to use the constant will have to do their own
65 * #define foo vccast(foo)
66 * since CPP cannot do this for them from inside another macro (sigh).
67 * We define "vccast" if this needs doing.
70 # define vc(name, value, x1,x2,x3,x4, bexp, xval) \
71 const union { uint32_t l[2]; double d; } cat3(__,name,x) = { \
72 .l = { [0] = cat3t(0x,x1,x2), [1] = cat3t(0x,x3,x4) } };
73 #elif defined(_LIBM_STATIC)
74 # define vc(name, value, x1,x2,x3,x4, bexp, xval) \
75 static const union { uint32_t l[2]; double d; } cat3(__,name,x) = { \
76 .l = { [0] = cat3t(0x,x1,x2), [1] = cat3t(0x,x3,x4) } };
78 # define vc(name, value, x1,x2,x3,x4, bexp, xval) \
79 extern const union { uint32_t l[2]; double d; } cat3(__,name,x);
81 # define ic(name, value, bexp, xval)
83 #else /* __vax__ or tahoe */
85 /* Hooray, we have an IEEE machine */
87 # define vc(name, value, x1,x2,x3,x4, bexp, xval)
90 # define ic(name, value, bexp, xval) \
91 const double __CONCAT(__,name) = value;
93 # define ic(name, value, bexp, xval) \
94 static const double __CONCAT(__,name) = value;
96 # define ic(name, value, bexp, xval) \
97 extern const double __CONCAT(__,name);
100 #endif /* defined(__vax__)||defined(tahoe) */
103 #include <machine/float.h>
104 #define _TINY DBL_EPSILON
105 #define _TINYER DBL_EPSILON
106 #define _HUGE DBL_MAX
109 #define _TINYER 1e-308
115 * Functions internal to the math package, yet not static.
117 extern double __exp__E(double, double);
118 extern double __log__L(double);
119 extern int infnan(int);
121 struct Double
{double a
, b
;};
122 double __exp__D(double, double);
123 struct Double
__log__D(double);
125 #endif /* _NOIEEE_SRC_MATHIMPL_H_ */