Home | History | Annotate | Download | only in include
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 /*
     23  * Copyright (c) 1988 by Sun Microsystems, Inc.
     24  */
     25 
     26 /*      Copyright (c) 1984 AT&T */
     27 /*        All Rights Reserved   */
     28 
     29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
     30 
     31 
     32 /*
     33  * Math library definitions for all the public functions implemented in libm.a.
     34  */
     35 
     36 #ifndef	__math_h
     37 #define	__math_h
     38 
     39 /*
     40  * Posix (actually ansi C) section
     41  */
     42 #define	HUGE_VAL	(__infinity())	/* Produces IEEE Infinity. */
     43 
     44 
     45 extern double	__infinity();
     46 extern double	acos(/* double x */);
     47 extern double	asin(/* double x */);
     48 extern double	atan(/* double x */);
     49 extern double	atan2(/* double y, double x */);
     50 extern double	ceil(/* double x */);
     51 extern double	cos(/* double x */);
     52 extern double	cosh(/* double x */);
     53 extern double	exp(/* double x */);
     54 extern double	fabs(/* double x */);
     55 extern double	floor(/* double x */);
     56 extern double	fmod(/* double x, double y */);
     57 extern double	frexp(/* double value, int *exp */);
     58 extern double	ldexp(/* double value, int exp */);
     59 extern double	log(/* double x */);
     60 extern double	log10(/* double x */);
     61 extern double	modf(/* double value, double *iptr */);
     62 extern double	pow(/* double x, double y */);
     63 extern double	sin(/* double x */);
     64 extern double	sinh(/* double x */);
     65 extern double	sqrt(/* double x */);
     66 extern double	tan(/* double x */);
     67 extern double	tanh(/* double x */);
     68 
     69 #ifndef	_POSIX_SOURCE			/* the rest of the file is !POSIX */
     70 #include <floatingpoint.h>		/* Contains definitions for types and
     71 					 * functions implemented in libc.a.
     72 					 */
     73 extern double	acosh();
     74 extern double	asinh();
     75 extern double	atanh();
     76 extern double	cbrt();
     77 extern double	copysign();
     78 extern double	erf();
     79 extern double	erfc();
     80 extern double	expm1();
     81 extern int	finite();
     82 extern double	hypot();
     83 extern double	j0();
     84 extern double	j1();
     85 extern double	jn();
     86 extern double	lgamma();
     87 extern double	log1p();
     88 extern double	rint();
     89 extern double	y0();
     90 extern double	y1();
     91 extern double	yn();
     92 
     93 /*
     94  * Sun definitions.
     95  */
     96 
     97 /*
     98  * Implemented precisions for trigonometric argument reduction.
     99  */
    100 enum fp_pi_type {
    101 	fp_pi_infinite	= 0,	/* Infinite-precision approximation to pi. */
    102 	fp_pi_66	= 1,	/* 66-bit approximation to pi. */
    103 	fp_pi_53	= 2	/* 53-bit approximation to pi. */
    104 };
    105 
    106 /*
    107  * Pi precision to use for trigonometric argument reduction.
    108  */
    109 extern enum	fp_pi_type fp_pi;
    110 
    111 /*
    112  * Functions callable from C, intended to support IEEE arithmetic.
    113  */
    114 extern enum	fp_class_type fp_class();
    115 extern int	ieee_flags();
    116 extern int	ieee_handler();
    117 extern void	ieee_retrospective();
    118 extern int	ilogb();
    119 extern double	infinity();
    120 extern int	irint();
    121 extern int	isinf();
    122 extern int	isnan();
    123 extern int	isnormal();
    124 extern int	issubnormal();
    125 extern int	iszero();
    126 extern double	logb();
    127 extern double	max_normal();
    128 extern double	max_subnormal();
    129 extern double	min_normal();
    130 extern double	min_subnormal();
    131 extern double	nextafter();
    132 extern void	nonstandard_arithmetic();
    133 extern double	quiet_nan();
    134 extern double	remainder();
    135 extern double	scalb();
    136 extern double	scalbn();
    137 extern double	signaling_nan();
    138 extern int	signbit();
    139 extern double	significand();
    140 extern void	standard_arithmetic();
    141 
    142 /*
    143  * Other functions for C programmers.
    144  */
    145 extern double	acospi();
    146 extern double	aint();
    147 extern double	anint();
    148 extern double	annuity();
    149 extern double	asinpi();
    150 extern double	atan2pi();
    151 extern double	atanpi();
    152 extern double	compound();
    153 extern double	cospi();
    154 extern double	exp10();
    155 extern double	exp2();
    156 extern double	log2();
    157 extern int	nint();
    158 extern void	sincos();
    159 extern void	sincospi();
    160 extern double	sinpi();
    161 extern double	tanpi();
    162 extern int	matherr();
    163 
    164 
    165 /*
    166  *	Single-precision functions callable from Fortran, Pascal, Modula-2, etc,
    167  *	take float* arguments instead of double and
    168  *	return FLOATFUNCTIONTYPE results instead of double.
    169  *	RETURNFLOAT is used to return a float function value without conversion
    170  *	to double.
    171  *	ASSIGNFLOAT is used to get the float value out of a FLOATFUNCTIONTYPE
    172  *	result.
    173  *	We don't want you to have to think about -fsingle2.
    174  *
    175  *	Some internal library functions pass float parameters as 32-bit values,
    176  *	disguised as FLOATPARAMETER.  FLOATPARAMETERVALUE(x) extracts the
    177  *	float value from the FLOATPARAMETER.
    178  */
    179 
    180 /*	mc68000 returns float results in d0, same as int	*/
    181 
    182 #ifdef	mc68000
    183 #define	FLOATFUNCTIONTYPE	int
    184 #define	RETURNFLOAT(x) 		return (*(int *)(&(x)))
    185 #define	ASSIGNFLOAT(x,y)	*(int *)(&x) = y
    186 #endif
    187 
    188 /*	sparc returns float results in %f0, same as top half of double	*/
    189 
    190 #ifdef	sparc
    191 #define	FLOATFUNCTIONTYPE	double
    192 #define	RETURNFLOAT(x) 		{ union {double _d; float _f } _kluge; _kluge._f = (x); return _kluge._d; }
    193 #define	ASSIGNFLOAT(x,y)	{ union {double _d; float _f } _kluge; _kluge._d = (y); x = _kluge._f; }
    194 #endif
    195 
    196 /*	i386 returns float results on stack as extendeds, same as double */
    197 
    198 #ifdef	i386
    199 #define	FLOATFUNCTIONTYPE	float
    200 #define	RETURNFLOAT(x) 		return (x)
    201 #define	ASSIGNFLOAT(x,y)	x = y
    202 #endif
    203 
    204 /* So far everybody passes float parameters as 32 bits on stack, same as int. */
    205 
    206 #define	FLOATPARAMETER		int
    207 #define	FLOATPARAMETERVALUE(x)	(*(float *)(&(x)))
    208 
    209 extern int		 ir_finite_();
    210 extern enum fp_class_type ir_fp_class_();
    211 extern int		 ir_ilogb_();
    212 extern int		 ir_irint_();
    213 extern int		 ir_isinf_();
    214 extern int		 ir_isnan_();
    215 extern int		 ir_isnormal_();
    216 extern int		 ir_issubnormal_();
    217 extern int		 ir_iszero_();
    218 extern int		 ir_nint_();
    219 extern int		 ir_signbit_();
    220 extern void		 r_sincos_();
    221 extern void		 r_sincospi_();
    222 extern FLOATFUNCTIONTYPE r_acos_();
    223 extern FLOATFUNCTIONTYPE r_acosh_();
    224 extern FLOATFUNCTIONTYPE r_acospi_();
    225 extern FLOATFUNCTIONTYPE r_aint_();
    226 extern FLOATFUNCTIONTYPE r_anint_();
    227 extern FLOATFUNCTIONTYPE r_annuity_();
    228 extern FLOATFUNCTIONTYPE r_asin_();
    229 extern FLOATFUNCTIONTYPE r_asinh_();
    230 extern FLOATFUNCTIONTYPE r_asinpi_();
    231 extern FLOATFUNCTIONTYPE r_atan2_();
    232 extern FLOATFUNCTIONTYPE r_atan2pi_();
    233 extern FLOATFUNCTIONTYPE r_atan_();
    234 extern FLOATFUNCTIONTYPE r_atanh_();
    235 extern FLOATFUNCTIONTYPE r_atanpi_();
    236 extern FLOATFUNCTIONTYPE r_cbrt_();
    237 extern FLOATFUNCTIONTYPE r_ceil_();
    238 extern FLOATFUNCTIONTYPE r_compound_();
    239 extern FLOATFUNCTIONTYPE r_copysign_();
    240 extern FLOATFUNCTIONTYPE r_cos_();
    241 extern FLOATFUNCTIONTYPE r_cosh_();
    242 extern FLOATFUNCTIONTYPE r_cospi_();
    243 extern FLOATFUNCTIONTYPE r_erf_();
    244 extern FLOATFUNCTIONTYPE r_erfc_();
    245 extern FLOATFUNCTIONTYPE r_exp10_();
    246 extern FLOATFUNCTIONTYPE r_exp2_();
    247 extern FLOATFUNCTIONTYPE r_exp_();
    248 extern FLOATFUNCTIONTYPE r_expm1_();
    249 extern FLOATFUNCTIONTYPE r_fabs_();
    250 extern FLOATFUNCTIONTYPE r_floor_();
    251 extern FLOATFUNCTIONTYPE r_fmod_();
    252 extern FLOATFUNCTIONTYPE r_hypot_();
    253 extern FLOATFUNCTIONTYPE r_infinity_();
    254 extern FLOATFUNCTIONTYPE r_j0_();
    255 extern FLOATFUNCTIONTYPE r_j1_();
    256 extern FLOATFUNCTIONTYPE r_jn_();
    257 extern FLOATFUNCTIONTYPE r_lgamma_();
    258 extern FLOATFUNCTIONTYPE r_log10_();
    259 extern FLOATFUNCTIONTYPE r_log1p_();
    260 extern FLOATFUNCTIONTYPE r_log2_();
    261 extern FLOATFUNCTIONTYPE r_log_();
    262 extern FLOATFUNCTIONTYPE r_logb_();
    263 extern FLOATFUNCTIONTYPE r_max_normal_();
    264 extern FLOATFUNCTIONTYPE r_max_subnormal_();
    265 extern FLOATFUNCTIONTYPE r_min_normal_();
    266 extern FLOATFUNCTIONTYPE r_min_subnormal_();
    267 extern FLOATFUNCTIONTYPE r_nextafter_();
    268 extern FLOATFUNCTIONTYPE r_pow_();
    269 extern FLOATFUNCTIONTYPE r_quiet_nan_();
    270 extern FLOATFUNCTIONTYPE r_remainder_();
    271 extern FLOATFUNCTIONTYPE r_rint_();
    272 extern FLOATFUNCTIONTYPE r_scalb_();
    273 extern FLOATFUNCTIONTYPE r_scalbn_();
    274 extern FLOATFUNCTIONTYPE r_signaling_nan_();
    275 extern FLOATFUNCTIONTYPE r_significand_();
    276 extern FLOATFUNCTIONTYPE r_sin_();
    277 extern FLOATFUNCTIONTYPE r_sinh_();
    278 extern FLOATFUNCTIONTYPE r_sinpi_();
    279 extern FLOATFUNCTIONTYPE r_sqrt_();
    280 extern FLOATFUNCTIONTYPE r_tan_();
    281 extern FLOATFUNCTIONTYPE r_tanh_();
    282 extern FLOATFUNCTIONTYPE r_tanpi_();
    283 extern FLOATFUNCTIONTYPE r_y0_();
    284 extern FLOATFUNCTIONTYPE r_y1_();
    285 extern FLOATFUNCTIONTYPE r_yn_();
    286 
    287 /* 	Constants, variables, and functions from System V */
    288 
    289 #define	_ABS(x) ((x) < 0 ? -(x) : (x))
    290 
    291 #define	HUGE		(infinity())	/* For historical compatibility. */
    292 
    293 #define	DOMAIN		1
    294 #define	SING		2
    295 #define	OVERFLOW	3
    296 #define	UNDERFLOW	4
    297 #define	TLOSS		5
    298 #define	PLOSS		6
    299 
    300 struct exception {
    301 	int type;
    302 	char *name;
    303 	double arg1;
    304 	double arg2;
    305 	double retval;
    306 };
    307 
    308 /*
    309  * First three have to be defined exactly as in values.h including spacing!
    310  */
    311 #define	M_LN2	0.69314718055994530942
    312 #define	M_PI	3.14159265358979323846
    313 #define	M_SQRT2	1.41421356237309504880
    314 
    315 #define	M_E		2.7182818284590452354
    316 #define	M_LOG2E		1.4426950408889634074
    317 #define	M_LOG10E	0.43429448190325182765
    318 #define	M_LN10		2.30258509299404568402
    319 #define	M_PI_2		1.57079632679489661923
    320 #define	M_PI_4		0.78539816339744830962
    321 #define	M_1_PI		0.31830988618379067154
    322 #define	M_2_PI		0.63661977236758134308
    323 #define	M_2_SQRTPI	1.12837916709551257390
    324 #define	M_SQRT1_2	0.70710678118654752440
    325 #define	_REDUCE(TYPE, X, XN, C1, C2)	{ \
    326 	double x1 = (double)(TYPE)X, x2 = X - x1; \
    327 	X = x1 - (XN) * (C1); X += x2; X -= (XN) * (C2); }
    328 #define	_POLY1(x, c)    ((c)[0] * (x) + (c)[1])
    329 #define	_POLY2(x, c)    (_POLY1((x), (c)) * (x) + (c)[2])
    330 #define	_POLY3(x, c)    (_POLY2((x), (c)) * (x) + (c)[3])
    331 #define	_POLY4(x, c)    (_POLY3((x), (c)) * (x) + (c)[4])
    332 #define	_POLY5(x, c)    (_POLY4((x), (c)) * (x) + (c)[5])
    333 #define	_POLY6(x, c)    (_POLY5((x), (c)) * (x) + (c)[6])
    334 #define	_POLY7(x, c)    (_POLY6((x), (c)) * (x) + (c)[7])
    335 #define	_POLY8(x, c)    (_POLY7((x), (c)) * (x) + (c)[8])
    336 #define	_POLY9(x, c)    (_POLY8((x), (c)) * (x) + (c)[9])
    337 
    338 extern int	signgam;
    339 /*
    340  *	Deprecated functions for compatibility with past.
    341  *	Changes planned for future.
    342  */
    343 
    344 extern double cabs();	/* Use double hypot(x,y)
    345 			 * Traditional cabs usage is confused -
    346 			 * is its argument two doubles or one struct?
    347 			 */
    348 extern double drem();	/* Use double remainder(x,y)
    349 			 * drem will disappear in a future release.
    350 			 */
    351 extern double gamma();	/* Use double lgamma(x)
    352 			 * to compute log of gamma function.
    353 			 * Name gamma is reserved for true gamma function
    354 			 * to appear in a future release.
    355 			 */
    356 #endif	/* !_POSIX_SOURCE */
    357 #endif	/* !__math_h */
    358