1*84d9c625SLionel Sambuc /* $NetBSD: mathimpl.h,v 1.10 2011/11/02 02:34:56 christos Exp $ */ 22fe8fb19SBen Gras /* 32fe8fb19SBen Gras * Copyright (c) 1988, 1993 42fe8fb19SBen Gras * The Regents of the University of California. All rights reserved. 52fe8fb19SBen Gras * 62fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 72fe8fb19SBen Gras * modification, are permitted provided that the following conditions 82fe8fb19SBen Gras * are met: 92fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 102fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 112fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 122fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 132fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 142fe8fb19SBen Gras * 3. Neither the name of the University nor the names of its contributors 152fe8fb19SBen Gras * may be used to endorse or promote products derived from this software 162fe8fb19SBen Gras * without specific prior written permission. 172fe8fb19SBen Gras * 182fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 192fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 202fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 212fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 222fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 232fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 242fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 252fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 262fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 272fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 282fe8fb19SBen Gras * SUCH DAMAGE. 292fe8fb19SBen Gras * 302fe8fb19SBen Gras * @(#)mathimpl.h 8.1 (Berkeley) 6/4/93 312fe8fb19SBen Gras */ 322fe8fb19SBen Gras #ifndef _NOIEEE_SRC_MATHIMPL_H_ 332fe8fb19SBen Gras #define _NOIEEE_SRC_MATHIMPL_H_ 342fe8fb19SBen Gras 352fe8fb19SBen Gras #include <sys/cdefs.h> 362fe8fb19SBen Gras #include <math.h> 372fe8fb19SBen Gras #include <stdint.h> 382fe8fb19SBen Gras 392fe8fb19SBen Gras #if defined(__vax__) || defined(tahoe) 402fe8fb19SBen Gras 412fe8fb19SBen Gras /* Deal with different ways to concatenate in cpp */ 422fe8fb19SBen Gras #define cat3(a,b,c) a ## b ## c 432fe8fb19SBen Gras 442fe8fb19SBen Gras /* Deal with vax/tahoe byte order issues */ 452fe8fb19SBen Gras # ifdef __vax__ 462fe8fb19SBen Gras # define cat3t(a,b,c) cat3(a,b,c) 472fe8fb19SBen Gras # else 482fe8fb19SBen Gras # define cat3t(a,b,c) cat3(a,c,b) 492fe8fb19SBen Gras # endif 502fe8fb19SBen Gras 512fe8fb19SBen Gras # define vccast(name) (cat3(__,name,x).d) 522fe8fb19SBen Gras 532fe8fb19SBen Gras /* 542fe8fb19SBen Gras * Define a constant to high precision on a Vax or Tahoe. 552fe8fb19SBen Gras * 562fe8fb19SBen Gras * Args are the name to define, the decimal floating point value, 572fe8fb19SBen Gras * four 16-bit chunks of the float value in hex 582fe8fb19SBen Gras * (because the vax and tahoe differ in float format!), the power 592fe8fb19SBen Gras * of 2 of the hex-float exponent, and the hex-float mantissa. 602fe8fb19SBen Gras * Most of these arguments are not used at compile time; they are 612fe8fb19SBen Gras * used in a post-check to make sure the constants were compiled 622fe8fb19SBen Gras * correctly. 632fe8fb19SBen Gras * 642fe8fb19SBen Gras * People who want to use the constant will have to do their own 652fe8fb19SBen Gras * #define foo vccast(foo) 662fe8fb19SBen Gras * since CPP cannot do this for them from inside another macro (sigh). 672fe8fb19SBen Gras * We define "vccast" if this needs doing. 682fe8fb19SBen Gras */ 692fe8fb19SBen Gras #ifdef _LIBM_DECLARE 702fe8fb19SBen Gras # define vc(name, value, x1,x2,x3,x4, bexp, xval) \ 712fe8fb19SBen Gras const union { uint32_t l[2]; double d; } cat3(__,name,x) = { \ 722fe8fb19SBen Gras .l = { [0] = cat3t(0x,x1,x2), [1] = cat3t(0x,x3,x4) } }; 732fe8fb19SBen Gras #elif defined(_LIBM_STATIC) 742fe8fb19SBen Gras # define vc(name, value, x1,x2,x3,x4, bexp, xval) \ 752fe8fb19SBen Gras static const union { uint32_t l[2]; double d; } cat3(__,name,x) = { \ 762fe8fb19SBen Gras .l = { [0] = cat3t(0x,x1,x2), [1] = cat3t(0x,x3,x4) } }; 772fe8fb19SBen Gras #else 782fe8fb19SBen Gras # define vc(name, value, x1,x2,x3,x4, bexp, xval) \ 792fe8fb19SBen Gras extern const union { uint32_t l[2]; double d; } cat3(__,name,x); 802fe8fb19SBen Gras #endif 812fe8fb19SBen Gras # define ic(name, value, bexp, xval) 822fe8fb19SBen Gras 832fe8fb19SBen Gras #else /* __vax__ or tahoe */ 842fe8fb19SBen Gras 852fe8fb19SBen Gras /* Hooray, we have an IEEE machine */ 862fe8fb19SBen Gras # undef vccast 872fe8fb19SBen Gras # define vc(name, value, x1,x2,x3,x4, bexp, xval) 882fe8fb19SBen Gras 892fe8fb19SBen Gras #ifdef _LIBM_DECLARE 902fe8fb19SBen Gras # define ic(name, value, bexp, xval) \ 912fe8fb19SBen Gras const double __CONCAT(__,name) = value; 922fe8fb19SBen Gras #elif _LIBM_STATIC 932fe8fb19SBen Gras # define ic(name, value, bexp, xval) \ 942fe8fb19SBen Gras static const double __CONCAT(__,name) = value; 952fe8fb19SBen Gras #else 962fe8fb19SBen Gras # define ic(name, value, bexp, xval) \ 972fe8fb19SBen Gras extern const double __CONCAT(__,name); 982fe8fb19SBen Gras #endif 992fe8fb19SBen Gras 1002fe8fb19SBen Gras #endif /* defined(__vax__)||defined(tahoe) */ 1012fe8fb19SBen Gras 102*84d9c625SLionel Sambuc #ifdef __vax__ 103*84d9c625SLionel Sambuc #include <machine/float.h> 104*84d9c625SLionel Sambuc #define _TINY DBL_EPSILON 105*84d9c625SLionel Sambuc #define _TINYER DBL_EPSILON 106*84d9c625SLionel Sambuc #define _HUGE DBL_MAX 107*84d9c625SLionel Sambuc #else 108*84d9c625SLionel Sambuc #define _TINY 1e-300 109*84d9c625SLionel Sambuc #define _TINYER 1e-308 110*84d9c625SLionel Sambuc #define _HUGE 1e+300 111*84d9c625SLionel Sambuc #endif 112*84d9c625SLionel Sambuc 1132fe8fb19SBen Gras 1142fe8fb19SBen Gras /* 1152fe8fb19SBen Gras * Functions internal to the math package, yet not static. 1162fe8fb19SBen Gras */ 1172fe8fb19SBen Gras extern double __exp__E(double, double); 1182fe8fb19SBen Gras extern double __log__L(double); 1192fe8fb19SBen Gras extern int infnan(int); 1202fe8fb19SBen Gras 1212fe8fb19SBen Gras struct Double {double a, b;}; 1222fe8fb19SBen Gras double __exp__D(double, double); 1232fe8fb19SBen Gras struct Double __log__D(double); 1242fe8fb19SBen Gras 1252fe8fb19SBen Gras #endif /* _NOIEEE_SRC_MATHIMPL_H_ */ 126