/
math.mh
452 lines (395 loc) · 14.9 KB
/
math.mh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/***************************************************************************
* FILE: math.h/cmath (Math functions)
*
:include crwat.sp
*
* Description: This header is part of the C/C++ standard library. It
* describes the math functions provided by those standards.
***************************************************************************/
:segment CNAME
#ifndef _CMATH_INCLUDED
#define _CMATH_INCLUDED
:include readonly.sp
:include cpponly.sp
:elsesegment
#ifndef _MATH_H_INCLUDED
#define _MATH_H_INCLUDED
:include readonly.sp
:: The following somewhat long segment only appears in math.h
#ifdef __cplusplus
#define _INCLUDED_FROM_MATH_H
#include <cmath>
#undef _INCLUDED_FROM_MATH_H
// functions in math.h
using std::acos;
using std::asin;
using std::atan;
using std::atan2;
using std::ceil;
using std::cos;
using std::cosh;
using std::exp;
using std::fabs;
using std::floor;
using std::fmod;
using std::frexp;
using std::ldexp;
using std::log;
using std::log10;
using std::modf;
using std::pow;
using std::sin;
using std::sinh;
using std::sqrt;
using std::tan;
using std::tanh;
:: C99 functions in math.h that are currently considered extensions.
:include extc99.sp
using std::acosh;
using std::asinh;
using std::atanh;
using std::cbrt;
using std::copysign;
using std::erf;
using std::erfc;
using std::exp2;
using std::expm1;
using std::fdim;
using std::fmax;
using std::fma;
using std::fmin;
using std::hypot;
using std::ilogb;
using std::lgamma;
using std::lgamma_r;
using std::log1p;
using std::log2;
using std::logb;
using std::nearbyint;
using std::nextafter;
using std::remainder;
using std::remquo;
using std::rint;
using std::round;
using std::scalbn;
using std::tgamma;
using std::trunc;
using std::nan;
using std::nanf;
using std::nanl;
:include extepi.sp
#else /* __cplusplus not defined */
:: End of segment that is only in math.h
:endsegment
:include owrtlink.sp
:: Only need extern "C" in cmath
:segment CNAME
:include cpluspro.sp
:endsegment
:include pshpackl.sp
_WCRTLINK extern const double *__get_HugeValue_ptr( void );
#if defined(__FUNCTION_DATA_ACCESS)
#define _HugeValue (*__get_HugeValue_ptr())
#elif defined(__SW_BR) || defined(_RTDLL)
#define _HugeValue _HugeValue_br
#endif
_WCRTDATA extern const double _WCDATA _HugeValue;
#define HUGE_VAL _HugeValue
:: Always enable C99 stuff
::#if __STDC_VERSION__ >= 199901L
/* Internal library helper routines */
_WMRTLINK extern int _FSClass( float __x );
_WMRTLINK extern int _FDClass( double __x );
_WMRTLINK extern int _FLClass( long double __x );
_WMRTLINK extern int _FSSign( float __x );
_WMRTLINK extern int _FDSign( double __x );
_WMRTLINK extern int _FLSign( long double __x );
/* Floating-point classification macros */
:: NB: The following values *must* match ld_classification in xfloat.h!
#define FP_ZERO 0
#define FP_SUBNORMAL 1
#define FP_NORMAL 2
#define FP_NAN 3
#define FP_INFINITE 4
#define fpclassify(x) \
((sizeof(x) == sizeof(float)) ? _FSClass(x) : \
(sizeof(x) == sizeof(double)) ? _FDClass(x) : \
_FLClass(x))
#define isfinite(x) (fpclassify(x) <= FP_NORMAL)
#define isinf(x) (fpclassify(x) == FP_INFINITE)
#define isnan(x) (fpclassify(x) == FP_NAN)
#define isnormal(x) (fpclassify(x) == FP_NORMAL)
#define signbit(x) \
((sizeof(x) == sizeof(float)) ? _FSSign(x) : \
(sizeof(x) == sizeof(double)) ? _FDSign(x) : \
_FLSign(x))
:: The following externs are also defined in float.h
/* Floating-point Infinity and NaN constants */
_WMRTDATA extern const float __f_infinity;
_WMRTDATA extern const float __f_posqnan;
#define INFINITY __f_infinity
#define NAN __f_posqnan
/* The sign of the gamma function as returned by
* lgamma
*/
extern int signgam;
:segment CNAME
namespace std {
:endsegment
_WMRTLINK extern double ceil( double __x );
_WMRTLINK extern double floor( double __x );
#if defined(_M_IX86) && 0
#pragma aux ceil parm nomemory modify nomemory;
#pragma aux floor parm nomemory modify nomemory;
#endif
_WMRTLINK extern double frexp( double __value, int *__exp );
_WMRTLINK extern double ldexp( double __x, int __exp );
_WMRTLINK extern double modf( double __value, double *__iptr );
_WMIRTLINK extern double acos( double __x );
_WMIRTLINK extern double asin( double __x );
_WMIRTLINK extern double atan( double __x );
_WMIRTLINK extern double atan2( double __y, double __x );
_WMIRTLINK extern double cos( double __x );
_WMIRTLINK extern double cosh( double __x );
_WMIRTLINK extern double exp( double __x );
_WMIRTLINK extern double fabs( double __x );
_WMIRTLINK extern double fmod( double __x, double __y );
_WMIRTLINK extern double log( double __x );
_WMIRTLINK extern double log10( double __x );
_WMIRTLINK extern double pow( double __x, double __y );
_WMIRTLINK extern double sin( double __x );
_WMIRTLINK extern double sinh( double __x );
_WMIRTLINK extern double sqrt( double __x );
_WMIRTLINK extern double tan( double __x );
_WMIRTLINK extern double tanh( double __x );
:: C99 functions in math.h that are currently considered extensions.
:include extc99.sp
_WMRTLINK extern double acosh( double __x );
_WMRTLINK extern double asinh( double __x );
_WMRTLINK extern double atanh( double __x );
_WMRTLINK extern double cbrt( double __x );
_WMRTLINK extern double copysign( double __x, double __y );
_WMRTLINK extern double erf( double __x );
_WMRTLINK extern double erfc( double __x );
_WMRTLINK extern double exp2( double __x );
_WMRTLINK extern double expm1( double __x );
_WMRTLINK extern double fdim( double __x, double __y );
_WMRTLINK extern double fmax( double __x, double __y );
_WMRTLINK extern double fma( double __a, double __b, double __c );
_WMRTLINK extern double fmin( double __x, double __y );
_WMRTLINK extern double hypot( double __x, double __y );
_WMRTLINK extern int ilogb( double __x );
_WMRTLINK extern double lgamma( double __x );
_WMRTLINK extern double lgamma_r( double __x, int *__signgamma );
_WMRTLINK extern double log1p( double __x );
_WMRTLINK extern double log2( double __x );
_WMRTLINK extern double logb( double __x );
_WMRTLINK extern long lrint( double __x );
_WMRTLINK extern long long llrint( double __x );
_WMRTLINK extern double nearbyint( double __x );
_WMRTLINK extern double nextafter( double __x, double __y );
_WMRTLINK extern double remainder( double __x, double __y );
_WMRTLINK extern double remquo( double __x, double __y, int *__q );
_WMRTLINK extern double rint( double __x );
_WMRTLINK extern double round( double __x );
_WMRTLINK extern double scalbn( double __x, int __n );
_WMRTLINK extern double tgamma( double __x );
_WMRTLINK extern double trunc( double __x );
_WMRTLINK extern float nanf(const char *ignored);
_WMRTLINK extern double nan(const char *ignored);
#ifdef _LONG_DOUBLE_
_WMRTLINK extern long double nanl(const char *ignored);
#else
_WMRTLINK extern double nanl(const char *ignored);
#endif
:segment DOS | QNX
#if defined(_M_I86)
#define FP_ILOGBNAN (-32767-1)
#define FP_ILOGB0 32767
#else
:endsegment
#define FP_ILOGBNAN (-2147483647-1)
#define FP_ILOGB0 2147483647
:segment DOS | QNX
#endif
:endsegment
/* Math error handling mode ala C99 */
extern int __math_errhandling_flag;
#define MATH_ERRNO 1
#define MATH_ERREXCEPT 2
/* As an extension, support Watcom errors as well */
#define MATH_ERRWATCOM 4
#define math_errhandling __math_errhandling_flag
:include extepi.sp
:segment CNAME
} // namespace std
:endsegment
:include ext.sp
::
:: Begin of extension section
::
/* non-ANSI */
struct _complex {
double x;
double y;
};
:segment !CNAME
struct complex {
double x;
double y;
};
:endsegment
_WMRTLINK extern double cabs( struct _complex );
_WMRTLINK extern double j0( double __x );
_WMRTLINK extern double j1( double __x );
_WMRTLINK extern double jn( int __n, double __x );
_WMRTLINK extern double y0( double __x );
_WMRTLINK extern double y1( double __x );
_WMRTLINK extern double yn( int __n, double __x );
/* The following struct is used to record errors detected in the math library.
* matherr is called with a pointer to this struct for possible error recovery.
*/
struct _exception {
int type; /* type of error, see below */
const char *name; /* name of math function */
double arg1; /* value of first argument to function */
double arg2; /* second argument (if indicated) */
double retval; /* default return value */
};
:segment !CNAME
struct exception {
int type; /* type of error, see below */
const char *name; /* name of math function */
double arg1; /* value of first argument to function */
double arg2; /* second argument (if indicated) */
double retval; /* default return value */
};
:endsegment
#define DOMAIN 1 /* argument domain error */
#define SING 2 /* argument singularity */
#define OVERFLOW 3 /* overflow range error */
#define UNDERFLOW 4 /* underflow range error */
#define TLOSS 5 /* total loss of significance */
#define PLOSS 6 /* partial loss of significance */
_WMRTLINK extern int matherr( struct _exception * );
_WMRTLINK extern double _matherr( struct _exception * );
_WMRTLINK extern void _set_matherr( int (*rtn)( struct _exception * ) );
_WCRTLINK extern int _dieeetomsbin( double *__x, double *__y );
_WCRTLINK extern int _dmsbintoieee( double *__x, double *__y );
_WCRTLINK extern int _fieeetomsbin( float *__x, float *__y );
_WCRTLINK extern int _fmsbintoieee( float *__x, float *__y );
::
:: End of extension section
::
:include extepi.sp
#if !defined(__NO_MATH_OPS) && defined(_M_IX86)
/*
Defining the __NO_MATH_OPS macro will stop the compiler from
recognizing the following functions as intrinsic operators.
*/
:segment CNAME
namespace std {
#pragma intrinsic(log,cos,sin,tan,sqrt,fabs,pow,atan2,fmod)
#pragma intrinsic(acos,asin,atan,cosh,exp,log10,sinh,tanh)
}
:elsesegment
#pragma intrinsic(log,cos,sin,tan,sqrt,fabs,pow,atan2,fmod)
#pragma intrinsic(acos,asin,atan,cosh,exp,log10,sinh,tanh)
:endsegment
#endif
:include poppack.sp
:segment CNAME
:include cplusepi.sp
:elsesegment
#endif /* __cplusplus not defined */
:endsegment
#endif
:segment CNAME
:: For C++ provide the appropriate overloaded signatures. These signatures
:: must not be extern "C" (which is why they are down here).
#ifndef _INCLUDED_FROM_MATH_H
#ifndef _CMATH_AUX_INCLUDED
#define _CMATH_AUX_INCLUDED
namespace std {
// double
inline double abs( double __x ) { return( fabs( __x ) ); }
inline double pow( double __x, int __y )
{ return( pow( __x, (double)__y ) ); }
// float
inline float abs ( float __x ) { return( abs ( (double)__x ) ); }
inline float acos ( float __x ) { return( acos ( (double)__x ) ); }
inline float asin ( float __x ) { return( asin ( (double)__x ) ); }
inline float atan ( float __x ) { return( atan ( (double)__x ) ); }
inline float atan2( float __x, float __y )
{ return( atan2( (double)__x, (double)__y ) ); }
inline float ceil ( float __x ) { return( ceil ( (double)__x ) ); }
inline float cos ( float __x ) { return( cos ( (double)__x ) ); }
inline float cosh ( float __x ) { return( cosh ( (double)__x ) ); }
inline float exp ( float __x ) { return( exp ( (double)__x ) ); }
inline float fabs ( float __x ) { return( fabs ( (double)__x ) ); }
inline float floor( float __x ) { return( floor( (double)__x ) ); }
inline float fmod ( float __x, float __y )
{ return( fmod( (double)__x, (double)__y ) ); }
inline float frexp( float __value, int *__exp )
{ return( frexp( (double)__value, __exp ) ); }
inline float ldexp( float __x, int __exp )
{ return( ldexp( (double)__x, __exp ) ); }
inline float log ( float __x ) { return( log ( (double)__x ) ); }
inline float log10( float __x ) { return( log10( (double)__x ) ); }
inline float modf ( float __value, float *__iptr )
{
float __result; double __i;
__result = modf( (double)__value, &__i );
*__iptr = __i;
return( __result );
}
inline float pow ( float __x, float __y )
{ return( pow ( (double)__x, (double)__y ) ); }
inline float pow ( float __x, int __y )
{ return( pow ( (double)__x, __y ) ); }
inline float sin ( float __x ) { return( sin ( (double)__x ) ); }
inline float sinh ( float __x ) { return( sinh ( (double)__x ) ); }
inline float sqrt ( float __x ) { return( sqrt ( (double)__x ) ); }
inline float tan ( float __x ) { return( tan ( (double)__x ) ); }
inline float tanh ( float __x ) { return( tanh ( (double)__x ) ); }
// long double
inline long double abs ( long double __x ) { return( abs ( (double)__x ) ); }
inline long double acos ( long double __x ) { return( acos ( (double)__x ) ); }
inline long double asin ( long double __x ) { return( asin ( (double)__x ) ); }
inline long double atan ( long double __x ) { return( atan ( (double)__x ) ); }
inline long double atan2( long double __x, long double __y )
{ return( atan2( (double)__x, (double)__y ) ); }
inline long double ceil ( long double __x ) { return( ceil ( (double)__x ) ); }
inline long double cos ( long double __x ) { return( cos ( (double)__x ) ); }
inline long double cosh ( long double __x ) { return( cosh ( (double)__x ) ); }
inline long double exp ( long double __x ) { return( exp ( (double)__x ) ); }
inline long double fabs ( long double __x ) { return( fabs ( (double)__x ) ); }
inline long double floor( long double __x ) { return( floor( (double)__x ) ); }
inline long double fmod ( long double __x, long double __y )
{ return( fmod( (double)__x, (double)__y ) ); }
inline long double frexp( long double __value, int *__exp )
{ return( frexp( (double)__value, __exp ) ); }
inline long double ldexp( long double __x, int __exp )
{ return( ldexp( (double)__x, __exp ) ); }
inline long double log ( long double __x ) { return( log ( (double)__x ) ); }
inline long double log10( long double __x ) { return( log10( (double)__x ) ); }
inline long double modf ( long double __value, long double *__iptr )
{
long double __result; double __i;
__result = modf( (double)__value, &__i );
*__iptr = __i;
return( __result );
}
inline long double pow ( long double __x, long double __y )
{ return( pow ( (double)__x, (double)__y ) ); }
inline long double pow ( long double __x, int __y )
{ return( pow ( (double)__x, __y ) ); }
inline long double sin ( long double __x ) { return( sin ( (double)__x ) ); }
inline long double sinh ( long double __x ) { return( sinh ( (double)__x ) ); }
inline long double sqrt ( long double __x ) { return( sqrt ( (double)__x ) ); }
inline long double tan ( long double __x ) { return( tan ( (double)__x ) ); }
inline long double tanh ( long double __x ) { return( tanh ( (double)__x ) ); }
} // namespace std
#endif
#endif
:endsegment