math 27.2 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma force_top_level
#pragma include_only_once

18
/* math.h: ISO 'C' (9899:1999) library header, section 7.12 */
Neil Turton's avatar
Neil Turton committed
19 20
/* Copyright (C) Codemist Ltd. */
/* Copyright (C) Acorn Computers Ltd. 1991 */
21
/* version 0.07 */
Neil Turton's avatar
Neil Turton committed
22 23 24 25

#ifndef __math_h
#define __math_h

26 27 28 29
typedef float float_t;
typedef double double_t;
   /* most efficient types at least as wide as float and double */

Neil Turton's avatar
Neil Turton committed
30 31 32 33 34 35 36 37 38
#ifndef HUGE_VAL
#  define HUGE_VAL __huge_val
#ifdef __cplusplus
#  define HUGE __huge_val
extern "C" const double HUGE_VAL;
#else
extern const double HUGE_VAL;
#endif
#endif
Kevin Bracey's avatar
Kevin Bracey committed
39 40 41 42 43 44 45 46 47 48 49 50
   /* HUGE_VAL equals DBL_MAX, and this is the return value for overflow */
   /* range errors in the C90 functions. Also, domain errors return */
   /* -HUGE_VAL = -DBL_MAX. */
   /* However, new C99 functions are in a state of flux. They may either */
   /* return DBL_MAX or INFINITY for range errors and either a NaN */
   /* or -DBL_MAX for domain errors, depending on how new the shared C */
   /* library is. Newer versions of the C library will use infinities and */
   /* NaNs for all the C99 functions, and will also have a parallel set of */
   /* C99 versions of the original C90 functions, so behaviour will */
   /* eventually be consistent within each mode, with HUGE_VAL set to */
   /* DBL_MAX for C90 mode and INFINITY for C99 mode. */
   /* See also math_errhandling below. */
Neil Turton's avatar
Neil Turton committed
51

52 53 54
#ifndef HUGE_VALL
#define HUGE_VALL ((long double) HUGE_VAL)
#endif
Kevin Bracey's avatar
Kevin Bracey committed
55 56
   /* long double is equivalent to double in Norcroft C, so all */
   /* long double functions just call their double counterpart. */
57

58
#ifndef __cplusplus
59 60 61 62
#ifndef HUGE_VALF
#  define HUGE_VALF INFINITY
#endif

Kevin Bracey's avatar
Kevin Bracey committed
63
#define INFINITY 0f_7F800000
64
   /* a constant expression of type float representing positive infinity */
Kevin Bracey's avatar
Kevin Bracey committed
65
#define NAN      0f_7FC00001
66 67 68 69 70
   /* a constant expression of type float representing a quiet NaN */

#define FP_ZERO      0
#define FP_SUBNORMAL 1
#define FP_NORMAL    2
Kevin Bracey's avatar
Kevin Bracey committed
71
#define FP_INFINITE  3
72
#define FP_NAN       4
73
   /* the mutually exclusive kinds of floating-point values for fpclassify */
74
#endif
75

ROOL's avatar
ROOL committed
76 77 78 79
#ifdef __FP_FAST_FMA
#define FP_FAST_FMA  1
#endif
#ifdef __FP_FAST_FMAF
Kevin Bracey's avatar
Kevin Bracey committed
80
#define FP_FAST_FMAF 1
ROOL's avatar
ROOL committed
81 82 83 84 85 86
#endif
#ifdef __FP_FAST_FMAL
#define FP_FAST_FMAL 1
#endif
   /* indicates that the fmaf/fmaf/fmal functions generally execute about */
   /* as fast, or faster than, a multiply and an add of the operands. */
Kevin Bracey's avatar
Kevin Bracey committed
87 88 89

#define FP_ILOGB0    (-0x7FFFFFFF) /* -INT_MAX */
#define FP_ILOGBNAN  (~0x7FFFFFFF) /* INT_MIN */
90 91
   /* integer constant expressions whose values are returned by ilogb(x) */
   /* if x is zero or NaN, respectively. */
92

93 94 95
#define MATH_ERRNO 1
#define MATH_ERREXCEPT 2

Kevin Bracey's avatar
Kevin Bracey committed
96
#undef math_errhandling
97 98 99 100 101 102
   /* math_errhandling is not currently provided, as an indication that */
   /* this is in flux. At present, "invalid", "divide-by-zero" and */
   /* "overflow" traps are enabled by default, so to raise these would */
   /* cause SIGFPE. C90 does not allow <math.h> functions to do this, so */
   /* the functions present in C90 do not raise these exceptions. */
   /* They instead set errno to EDOM or ERANGE, as required by C90. */
Kevin Bracey's avatar
Kevin Bracey committed
103 104
   /* The new C99 functions do raise exceptions, and don't set errno. But */
   /* because this will (by default) lead to SIGFPE being raised, the */
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
   /* behaviour does not currently conform to the C99 standard. To avoid */
   /* the traps you can use feholdexcept(). A future C99 version of the */
   /* library will have all traps disabled by default, making these */
   /* functions conforming, and will have new versions of the C90 */
   /* functions which do raise exceptions. Note that some C99 functions */
   /* may still be using errno and DBL_MAX, but this will be changed (even */
   /* for existing clients) by newer Shared C libraries. The original C90 */
   /* functions will not change, to preserve compatibility for older */
   /* clients. See also HUGE_VAL above. */

/* #pragma STDC FP_CONTRACT ON|OFF|DEFAULT */
   /* The FP_CONTRACT pragma can be used to allow (if the state is "on") */
   /* or disallow (if the state is "off") the implementation to contract */
   /* expressions (refer to section 6.5 of the ISO standard). Each pragma */
   /* can occur either outside external declarations or preceding all */
   /* explicit declarations and statements inside a compound statement. */
   /* When outside external declarations, the pragma takes effect from its */
   /* occurrence until another FP_CONTRACT pragma is encountered, or until */
   /* the end of the translation unit. When inside a compound statement, */
   /* the pragma takes effect from its occurrence until another */
   /* FP_CONTRACT pragma is encountered (including within a nested */
   /* compound statement), or until the end of the compound statement; at */
   /* the end of a compound statement the state for the pragma is restored */
   /* to its condition just before the compound statement. If this pragma */
   /* is used in any other context, the behaviour is undefined. The */
   /* default state for this pragma is implementation-defined ("off" in */
   /* Norcroft C.). */
132

Neil Turton's avatar
Neil Turton committed
133 134 135
#ifdef __cplusplus
extern "C" {
#endif
136

137 138 139 140
#ifndef __cplusplus
/* None of this actually works, as the C++ system won't obey the
   force_fpargs_in_regs pragma */

141 142
#pragma no_side_effects
#pragma force_fpargs_in_regs
143 144 145 146
__caller_narrow int __fpclassifyf(float);
int __fpclassifyd(double);
__caller_narrow int __signbitf(float);
int __signbitd(double);
Kevin Bracey's avatar
Kevin Bracey committed
147 148
__caller_narrow float __copysignf(float,float);
double __copysignd(double,double);
149 150 151 152
#pragma no_force_fpargs_in_regs
#pragma side_effects

#ifdef __cplusplus
153 154
#define __classmacro(fn,r) (sizeof(r) == 4 ? __##fn##f((float)(r)) : \
                                             __##fn##d((double)(r)))
155 156 157 158 159 160 161
#else
#define __assertfp(r) ___assert(___typeof(r) == 0x002 ||\
                                ___typeof(r) == 0x202 ||\
                                ___typeof(r) == 0x402, \
                                "Illegal type used with classification macro")

#define __classmacro(fn,r) (__assertfp(r),\
162 163
                            ___typeof(r) == 0x402 ? __##fn##f((float)(r)) : \
                                                    __##fn##d((double)(r)))
164 165 166 167 168 169
#endif

#define fpclassify(r) __classmacro(fpclassify,(r))
   /* Returns: the value of the appropriate number classification macro */
#define isfinite(r)   (fpclassify(r) <= FP_NORMAL)
   /* Returns: a nonzero value if and only if its argument is finite */
Kevin Bracey's avatar
Kevin Bracey committed
170
#define isinf(r)      (fpclassify(r) == FP_INFINITE)
171 172 173 174 175 176 177 178
   /* Returns: a nonzero value if and only if its argument is infinite */
#define isnan(r)      (fpclassify(r) == FP_NAN)
   /* Returns: a nonzero value if and only if its argument is a NaN */
#define isnormal(r)   (fpclassify(r) == FP_NORMAL)
   /* Returns: a nonzero value if and only if its argument is normal */
#define signbit(r)    __classmacro(signbit,(r))
   /* Returns: a nonzero value if and only if its argument is negative */

179 180
#endif

181 182 183
double acos(double /*x*/);
float acosf(float /*x*/);
long double acosl(long double /*x*/);
Neil Turton's avatar
Neil Turton committed
184 185 186
   /* computes the principal value of the arc cosine of x */
   /* a domain error occurs for arguments not in the range -1 to 1 */
   /* Returns: the arc cosine in the range 0 to Pi. */
187 188 189
double asin(double /*x*/);
float asinf(float /*x*/);
long double asinl(long double /*x*/);
Neil Turton's avatar
Neil Turton committed
190 191 192
   /* computes the principal value of the arc sine of x */
   /* a domain error occurs for arguments not in the range -1 to 1 */
   /* Returns: the arc sine in the range -Pi/2 to Pi/2. */
193 194 195
double atan(double /*x*/);
float atanf(float /*x*/);
long double atanl(long double /*x*/);
Neil Turton's avatar
Neil Turton committed
196 197
   /* computes the principal value of the arc tangent of x */
   /* Returns: the arc tangent in the range -Pi/2 to Pi/2. */
198 199 200
double atan2(double /*y*/, double /*x*/);
float atan2f(float /*y*/, float /*x*/);
long double atan2l(long double /*y*/, long double /*x*/);
Neil Turton's avatar
Neil Turton committed
201
   /* computes the principal value of the arc tangent of y/x, using the */
202 203
   /* signs of both arguments to determine the quadrant of the return */
   /* value */
Neil Turton's avatar
Neil Turton committed
204
   /* Returns: the arc tangent of y/x, in the range -Pi to Pi. */
205 206 207
double cos(double /*x*/);
float cosf(float /*x*/);
long double cosl(long double /*x*/);
Neil Turton's avatar
Neil Turton committed
208 209 210
   /* computes the cosine of x (measured in radians). A large magnitude */
   /* argument may yield a result with little or no significance */
   /* Returns: the cosine value. */
211 212 213
double sin(double /*x*/);
float sinf(float /*x*/);
long double sinl(long double /*x*/);
Neil Turton's avatar
Neil Turton committed
214 215 216
   /* computes the sine of x (measured in radians). A large magnitude */
   /* argument may yield a result with little or no significance */
   /* Returns: the sine value. */
217 218 219
double tan(double /*x*/);
float tanf(float /*x*/);
long double tanl(long double /*x*/);
Neil Turton's avatar
Neil Turton committed
220 221 222 223
   /* computes the tangent of x (measured in radians). A large magnitude */
   /* argument may yield a result with little or no significance */
   /* Returns: the tangent value. */

224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
double acosh(double /*x*/);
float acoshf(float /*x*/);
long double acoshl(long double /*x*/);
   /* computes the (non-negative) arc hyperbolic cosine of x. */
   /* A domain error occurs for arguments less than 1. */
   /* Returns: arcosh x in the interval [0,+inf] */
double asinh(double /*x*/);
float asinhf(float /*x*/);
long double asinhl(long double /*x*/);
   /* computes the arc hyperbolic sine of x. */
   /* Returns: arsinh x */
double atanh(double /*x*/);
float atanhf(float /*x*/);
long double atanhl(long double /*x*/);
   /* computes the arc hyperbolic tangent of x. A domain error occurs */
   /* for arguments not in the interval [-1,+1]. A range error occurs */
   /* if the argument equals -1 or +1. */
   /* Returns: artanh x */
double cosh(double /*x*/);
float coshf(float /*x*/);
long double coshl(long double /*x*/);
Neil Turton's avatar
Neil Turton committed
245 246 247
   /* computes the hyperbolic cosine of x. A range error occurs if the */
   /* magnitude of x is too large. */
   /* Returns: the hyperbolic cosine value. */
248 249 250
double sinh(double /*x*/);
float sinhf(float /*x*/);
long double sinhl(long double /*x*/);
Neil Turton's avatar
Neil Turton committed
251 252 253
   /* computes the hyperbolic sine of x. A range error occurs if the */
   /* magnitude of x is too large. */
   /* Returns: the hyperbolic sine value. */
254 255 256
double tanh(double /*x*/);
float tanhf(float /*x*/);
long double tanhl(long double /*x*/);
Neil Turton's avatar
Neil Turton committed
257 258 259
   /* computes the hyperbolic tangent of x. */
   /* Returns: the hyperbolic tangent value. */

260 261 262 263 264 265 266 267 268 269
double exp(double /*x*/);
float expf(float /*x*/);
long double expl(long double /*x*/);
   /* computes the base-e exponential of x. A range error occurs if the */
   /* magnitude of x is too large. */
   /* Returns: e^x */
double exp2(double /*x*/);
float exp2f(float /*x*/);
long double exp2l(long double /*x*/);
   /* computes the base-2 exponential of x. A range error occurs if the */
Neil Turton's avatar
Neil Turton committed
270
   /* magnitude of x is too large. */
271 272 273 274 275 276 277 278 279 280
   /* Returns: 2^x */
double expm1(double /*x*/);
float expm1f(float /*x*/);
long double expm1l(long double /*x*/);
   /* computes the base-e exponential of x, minus 1. A range error occurs if */
   /* the magnitude of x is too large. */
   /* Returns: e^x - 1 */
double frexp(double /*value*/, int * /*exp*/);
float frexpf(float /*value*/, int * /*exp*/);
long double frexpl(long double /*value*/, int * /*exp*/);
Neil Turton's avatar
Neil Turton committed
281 282 283 284
   /* breaks a floating-point number into a normalised fraction and an */
   /* integral power of 2. It stores the integer in the int object pointed */
   /* to by exp. */
   /* Returns: the value x, such that x is a double with magnitude in the */
Kevin Bracey's avatar
Kevin Bracey committed
285
   /* interval [0.5,1.0) or zero, and value equals x times 2 raised to the */
Neil Turton's avatar
Neil Turton committed
286
   /* power *exp. If value is zero, both parts of the result are zero. */
287 288 289 290 291
int ilogb(double /*x*/);
int ilogbf(float /*x*/);
int ilogbl(long double /*x*/);
   /* extracts the exponent of x as a signed int value. If x is zero it */
   /* computes the value FP_ILOGB0; if x is infinite it computes the value */
292 293 294
   /* INT_MAX; if x is a NaN it computes the value FP_ILOGBNAN; otherwise */
   /* it is equivalent to calling the corresponding logb function and */
   /* casting the returned value to type int. */
295 296 297 298
   /* Returns: the exponent of x as a signed int value. */
double ldexp(double /*x*/, int /*exp*/);
float ldexpf(float /*x*/, int /*exp*/);
long double ldexpl(long double /*x*/, int /*exp*/);
Neil Turton's avatar
Neil Turton committed
299 300 301
   /* multiplies a floating-point number by an integral power of 2. */
   /* A range error may occur. */
   /* Returns: the value of x times 2 raised to the power of exp. */
302 303 304
double log(double /*x*/);
float logf(float /*x*/);
long double logl(long double /*x*/);
305 306 307
   /* computes the base-e (natural) logarithm of x. A domain error occurs */
   /* if the argument is negative. A range error occurs if the argument is */
   /* zero. */
Neil Turton's avatar
Neil Turton committed
308
   /* Returns: the natural logarithm. */
309 310 311
double log10(double /*x*/);
float log10f(float /*x*/);
long double log10l(long double /*x*/);
312 313 314
   /* computes the base-ten (common) logarithm of x. A domain error occurs */
   /* if the argument is negative. A range error occurs if the argument is */
   /* zero. */
Neil Turton's avatar
Neil Turton committed
315
   /* Returns: the base-ten logarithm. */
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
double log1p(double /*x*/);
float log1pf(float /*x*/);
long double log1pl(long double /*x*/);
   /* computes the base-e (natural) logarithm of 1 plus the argument. A */
   /* domain error occurs if the argument is less than -1. A range error */
   /* occurs if the argument equals -1. */
   /* Returns: the natural logarithm of (1+x). */
double log2(double /*x*/);
float log2f(float /*x*/);
long double log2l(long double /*x*/);
   /* computes the base-two logarithm of x. A domain error occurs if the */
   /* argument is negative. A range error occurs if the argument is zero. */
   /* Returns: the base-two logarithm. */
double logb(double /*x*/);
float logbf(float /*x*/);
long double logbl(long double /*x*/);
   /* extracts the exponent of x, as a signed integer value in floating- */
   /* point format. If x is subnormal it is treated as though it were */
   /* normalised; thus, for positive finite x, */
   /*      1  <=  x * FLT_RADIX ^ -logb(x)  <  FLT_RADIX     */
Kevin Bracey's avatar
Kevin Bracey committed
336
   /* A range error occurs if the argument is zero. */
337 338 339
   /* Returns: the signed exponent of x */
double modf(double /*value*/, double * /*iptr*/);
float modff(float /*value*/, float * /*iptr*/);
Kevin Bracey's avatar
Kevin Bracey committed
340
long double modfl(long double /*value*/, long double * /*iptr*/);
Neil Turton's avatar
Neil Turton committed
341 342 343 344
   /* breaks the argument value into integral and fraction parts, each of */
   /* which has the same sign as the argument. It stores the integral part */
   /* as a double in the object pointed to by iptr. */
   /* Returns: the signed fractional part of value. */
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
double scalbn(double /*x*/, int /*n*/);
float scalbnf(float /*x*/, int /*n*/);
long double scalbnl(long double /*x*/, int /*n*/);
double scalbln(double /*x*/, long int /*n*/);
float scalblnf(float /*x*/, long int /*n*/);
long double scalblnl(long double /*x*/, long int /*n*/);
   /* computes x * FLT_RADIX^n efficiently. A range error may occur. */
   /* Returns: x * FLT_RADIX^n */

double cbrt(double /*x*/);
float cbrtf(float /*x*/);
long double cbrtl(long double /*x*/);
   /* computes the real cube root of x. */
   /* Returns: x^(1/3) */
#pragma no_side_effects
double fabs(double /*x*/);
float fabsf(float /*x*/);
long double fabsl(long double /*x*/);
   /* computes the absolute value of the floating-point number x. */
   /* Returns: the absolute value of x. */
#pragma side_effects
double hypot(double /*x*/, double /*y*/);
float hypotf(float /*x*/, float /*y*/);
long double hypotl(long double /*x*/, long double /*y*/);
369 370
   /* computes the square root of the sum of the squares of x and y, */
   /* without undue overflow or underflow. A range error may occur. */
371
   /* Returns: sqrt(x^2 + y^2) */
372 373 374
double pow(double /*x*/, double /*y*/);
float powf(float /*x*/, float /*y*/);
long double powl(long double /*x*/, long double /*y*/);
Neil Turton's avatar
Neil Turton committed
375 376
   /* computes x raised to the power of y. A domain error occurs if x is */
   /* zero and y is less than or equal to zero, or if x is negative and y */
Kevin Bracey's avatar
Kevin Bracey committed
377
   /* is not an integer. A range error may occur. */
Neil Turton's avatar
Neil Turton committed
378
   /* Returns: the value of x raised to the power of y. */
379 380 381
double sqrt(double /*x*/);
float sqrtf(float /*x*/);
long double sqrtl(long double /*x*/);
Neil Turton's avatar
Neil Turton committed
382
   /* computes the non-negative square root of x. A domain error occurs */
Kevin Bracey's avatar
Kevin Bracey committed
383
   /* if the argument is less than zero. */
Neil Turton's avatar
Neil Turton committed
384 385
   /* Returns: the value of the square root. */

386 387 388 389 390 391 392 393 394
double erf(double /*x*/);
float erff(float /*x*/);
long double erfl(long double /*x*/);
   /* computes the error function of x. */
   /* Returns: erf x = 2/sqrt(pi) * integral[0,x] (e^(-t^2)) dt */
double erfc(double /*x*/);
float erfcf(float /*x*/);
long double erfcl(long double /*x*/);
   /* computes the complementary error function of x. A range error occurs */
Kevin Bracey's avatar
Kevin Bracey committed
395
   /* if x is too large. */
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
   /* Returns: erfc x = 1 - erf x                                  */
   /*                 = 2/sqrt(pi) * integral[x,inf] (e^(-t^2)) dt */
double lgamma(double /*x*/);
float lgammaf(float /*x*/);
long double lgammal(long double /*x*/);
   /* computes the natural logarithm of the absolute value of gamma of x. */
   /* A range error occurs if x is too large. A range error occurs if x is */
   /* a negative integer or zero. */
   /* Returns: log |Gamma(x)| */
double tgamma(double /*x*/);
float tgammaf(float /*x*/);
long double tgammal(long double /*x*/);
   /* computes the gamma function of x. A domain error occurs if x is a */
   /* negative integer or if the result cannot be represented when x is */
   /* zero. A range error may occur if the magnitude of x is too large or */
   /* too small. */
   /* Returns: Gamma(x) */

double ceil(double /*x*/);
float ceilf(float /*x*/);
long double ceill(long double /*x*/);
417
   /* computes the smallest integer not less than x. */
418 419
   /* Returns: the smallest integer not less than x, expressed as a */
   /* floating-point number. */
420 421 422
double floor(double /*x*/);
float floorf(float /*x*/);
long double floorl(long double /*x*/);
Neil Turton's avatar
Neil Turton committed
423
   /* computes the largest integer not greater than x. */
424 425
   /* Returns: the largest integer not greater than x, expressed as a */
   /* floating-point number. */
Kevin Bracey's avatar
Kevin Bracey committed
426
#pragma no_side_effects
427 428 429
double nearbyint(double /*x*/);
float nearbyintf(float /*x*/);
long double nearbyintl(long double /*x*/);
430 431 432
   /* rounds its argument to an integer value, using the current rounding */
   /* direction. Does not raise the inexact exception. */
   /* Returns: the rounded integer value. */
Kevin Bracey's avatar
Kevin Bracey committed
433
#pragma side_effects
434 435 436
double rint(double /*x*/);
float rintf(float /*x*/);
long double rintl(long double /*x*/);
437 438 439
   /* rounds its argument to an integer value, using the current rounding */
   /* direction. Raises "inexact" if the result differs from the argument. */
   /* Returns: the rounded integer value. */
440 441 442
long int lrint(double /*x*/);
long int lrintf(float /*x*/);
long int lrintl(long double /*x*/);
443 444
#ifdef __STDC_VERSION__
#if __STDC_VERSION__ >= 199901
Kevin Bracey's avatar
Kevin Bracey committed
445 446 447
long long int llrint(double /*x*/);
long long int llrintf(float /*x*/);
long long int llrintl(long double /*x*/);
448 449
#endif
#endif
450 451 452
   /* rounds its argument to an integer value, using the current rounding */
   /* direction. Raises "inexact" if the result differs from the argument. */
   /* Returns: the rounded integer value. */
453 454 455 456
#pragma no_side_effects
double round(double /*x*/);
float roundf(float /*x*/);
long double roundl(long double /*x*/);
457 458 459
   /* rounds its argument to the nearest integer value, rounding halfway */
   /* cases away from zero. */
   /* Returns: the rounded integer value. */
460 461 462 463
#pragma side_effects
long int lround(double /*x*/);
long int lroundf(float /*x*/);
long int lroundl(long double /*x*/);
464 465
#ifdef __STDC_VERSION__
#if __STDC_VERSION__ >= 199901
Kevin Bracey's avatar
Kevin Bracey committed
466 467 468
long long int llround(double /*x*/);
long long int llroundf(float /*x*/);
long long int llroundl(long double /*x*/);
469 470
#endif
#endif
471 472 473
   /* rounds its argument to the nearest integer value, rounding halfway */
   /* cases away from zero. */
   /* Returns: the rounded integer value. */
474 475 476
double trunc(double /*x*/);
float truncf(float /*x*/);
long double truncl(long double /*x*/);
477 478
   /* rounds its argument to the integer value, nearest to but no larger */
   /* in magnitude than the argument. */
479
   /* Returns: the truncated integer value. */
480 481 482
double fmod(double /*x*/, double /*y*/);
float fmodf(float /*x*/, float /*y*/);
long double fmodl(long double /*x*/, long double /*y*/);
Neil Turton's avatar
Neil Turton committed
483
   /* computes the floating-point remainder of x/y. */
Kevin Bracey's avatar
Kevin Bracey committed
484
   /* Returns: the value x - n * y, for some integer n such that, if y is */
Neil Turton's avatar
Neil Turton committed
485 486
   /*          nonzero, the result has the same sign as x and magnitude */
   /*          less than the magnitude of y. If y is zero, a domain error */
Kevin Bracey's avatar
Kevin Bracey committed
487
   /*          occurs. */
488 489 490
double remainder(double /*x*/, double /*y*/);
float remainderf(float /*x*/, float /*y*/);
long double remainderl(long double /*x*/, long double /*y*/);
491 492
   /* computes the remainder x REM y required by IEEE 754 */
   /* Returns: x REM y */
Kevin Bracey's avatar
Kevin Bracey committed
493 494 495 496
double remquo(double /*x*/, double /*y*/, int * /*quo*/);
float remquof(float /*x*/, float /*y*/, int * /*quo*/);
long double remquol(long double /*x*/, long double /*y*/, int * /*quo*/);
   /* compute the same remainder as the remainder functions. In the object */
497 498 499 500
   /* pointed to by quo they store a value whose sign is the sign of x/y */
   /* and whose magnitude is congruent modulo 2^n to the magnitude of the */
   /* integral quotient of x/y, where n is an implementation-defined */
   /* integer greater than or equal to 3 (n=31 under RISC OS) */
Kevin Bracey's avatar
Kevin Bracey committed
501
   /* Returns: x REM y */
Neil Turton's avatar
Neil Turton committed
502

503 504
#pragma no_side_effects
double copysign(double /*x*/, double /*y*/);
Kevin Bracey's avatar
Kevin Bracey committed
505
float copysignf(float /*x*/, float /*y*/);
506
long double copysignl(long double /*x*/, long double /*y*/);
507 508 509
   /* produce a value with the magnitude of x and the sign of y. They */
   /* produce a NaN (with the sign of y) if x is a NaN. */
   /* Returns: a value with the magnitude of x and the sign of y. */
510 511 512
double nan(const char * /*tagp*/);
float nanf(const char * /*tagp*/);
long double nanl(const char * /*tagp*/);
513
   /* Returns: a quiet NaN, with content indicated through tagp. */
514 515 516 517
#pragma side_effects
double nextafter(double /*x*/, double /*y*/);
float nextafterf(float /*x*/, float /*y*/);
long double nextafterl(long double /*x*/, long double /*y*/);
518 519
   /* Returns: the next representable value in the specified format after */
   /*          x in the direction of y */
520 521 522
double nexttoward(double /*x*/, long double /*y*/);
float nexttowardf(float /*x*/, long double /*y*/);
long double nexttowardl(long double /*x*/, long double /*y*/);
523 524
   /* equivalent to the nextafter functions except that the second */
   /* parameter has type long double. */
525 526 527
double fdim(double /*x*/, double /*y*/);
float fdimf(float /*x*/, float /*y*/);
long double fdiml(long double /*x*/, long double /*y*/);
528 529 530 531 532
   /* determine the positive difference between their arguments: */
   /* { x-y if x > y  */
   /* { +0  if x <= y */
   /* A range error may occur. */
   /* Returns: the positive difference value. */
533 534 535 536
#pragma no_side_effects
double fmax(double /*x*/, double /*y*/);
float fmaxf(float /*x*/, float /*y*/);
long double fmaxl(long double /*x*/, long double /*y*/);
537
   /* Returns: the maximum numeric value of their arguments. */
538 539 540
double fmin(double /*x*/, double /*y*/);
float fminf(float /*x*/, float /*y*/);
long double fminl(long double /*x*/, long double /*y*/);
541
   /* Returns: the minimum numeric value of their arguments. */
542 543 544 545 546 547
#pragma side_effects

double fma(double /*x*/, double /*y*/, double /*z*/);
float fmaf(float /*x*/, float /*y*/, float /*z*/);
long double fmal(long double /*x*/, long double /*y*/, long double /*z*/);
   /* computes (x*y)+z, rounded as one ternary operation: it computes */
548 549 550
   /* the value (as if) to infinite precision and rounds once to the */
   /* result format, according to the rounding mode characterised by the */
   /* value of FLT_ROUNDS. */
551
   /* Returns: (x*y)+z, rounded as one ternary operation. */
552

553
#ifndef __cplusplus
554 555 556 557 558 559 560 561 562 563
#define isgreater(x,y)      ((x) __greater (y))
#define isgreaterequal(x,y) ((x) __greaterequal (y))
#define isless(x,y)         ((x) __less (y))
#define islessequal(x,y)    ((x) __lessequal (y))
#define islessgreater(x,y)  ((x) __lessgreater (y))
#define isunordered(x,y)    ((x) __unordered (y))
   /* quiet (non floating-point exception raising) versions of the */
   /* relational operators, and other comparison macros that facilitate */
   /* writing efficient code that accounts for NaNs without suffering the */
   /* "invalid" floating-point exception. */
564
#endif
Neil Turton's avatar
Neil Turton committed
565

Kevin Bracey's avatar
Kevin Bracey committed
566
/* Some functions can be safely inlined - appropriate macros defined here. */
567 568 569 570 571
/* float ones can't be inlined in C++ because of the odd calling */
/* convention. Some can't be inlined because they won't set errno - in */
/* future they will be inlined in C99 mode, once the real functions are */
/* consistent. Define __MATH_FORCE_INLINING if you don't care about errno */
/* vs exceptions. */
Kevin Bracey's avatar
Kevin Bracey committed
572 573
double __d_acos(double);
double __d_asin(double);
574 575 576
double __d_atan(double);
double __d_cos(double);
double __d_sin(double);
Kevin Bracey's avatar
Kevin Bracey committed
577 578 579 580
double __d_tan(double);
double __d_log(double);
double __d_lg10(double);
double __d_exp(double);
581
double __d_abs(double);
Kevin Bracey's avatar
Kevin Bracey committed
582
double __d_sqrt(double);
583 584 585 586 587
double __d_floor(double);
double __d_ceil(double);
double __d_trunc(double);
double __d_rint(double);
long int __d_lrint(double);
Kevin Bracey's avatar
Kevin Bracey committed
588
double __d_rem(double,double);
ROOL's avatar
ROOL committed
589
double __d_fma(double,double,double);
Kevin Bracey's avatar
Kevin Bracey committed
590 591 592 593
#ifdef __MATH_FORCE_INLINING
#  if __STDC_VERSION__ >= 199901
#define acos(x) __d_acos(x)
#define asin(x) __d_asin(x)
594 595
#define cos(x) __d_cos(x)
#define sin(x) __d_sin(x)
Kevin Bracey's avatar
Kevin Bracey committed
596 597 598 599 600 601 602 603
#define tan(x) __d_tan(x)
#define sqrt(x) __d_sqrt(x)
#define log(x) __d_log(x)
#define log10(x) __d_lg10(x)
#define exp(x) __d_exp(x)
#  endif
#endif
#define atan(x) __d_atan(x)
604 605 606 607 608
#ifdef __cplusplus
#  define fabs(x) __d_abs(x)
#else
#  define fabs(x) ((void) sizeof (fabs)(x), __abs (double) (x))
#endif
609 610 611 612 613
#define floor(x) __d_floor(x)
#define ceil(x) __d_ceil(x)
#define trunc(x) __d_trunc(x)
#define rint(x) __d_rint(x)
#define lrint(x) __d_lrint(x)
Kevin Bracey's avatar
Kevin Bracey committed
614
#define remainder(x,y) __d_rem(x,y)
ROOL's avatar
ROOL committed
615
#define fma(x,y,z) __d_fma(x,y,z)
616
#ifndef __cplusplus
Kevin Bracey's avatar
Kevin Bracey committed
617 618
__caller_narrow float __r_acos(float);
__caller_narrow float __r_asin(float);
619 620 621
__caller_narrow float __r_atan(float);
__caller_narrow float __r_sin(float);
__caller_narrow float __r_cos(float);
Kevin Bracey's avatar
Kevin Bracey committed
622 623 624 625
__caller_narrow float __r_tan(float);
__caller_narrow float __r_log(float);
__caller_narrow float __r_lg10(float);
__caller_narrow float __r_exp(float);
626
__caller_narrow float __r_abs(float);
Kevin Bracey's avatar
Kevin Bracey committed
627
__caller_narrow float __r_sqrt(float);
628 629 630 631 632
__caller_narrow float __r_floor(float);
__caller_narrow float __r_ceil(float);
__caller_narrow float __r_trunc(float);
__caller_narrow float __r_rint(float);
__caller_narrow long int __r_lrint(float);
Kevin Bracey's avatar
Kevin Bracey committed
633 634 635 636 637 638
__caller_narrow float __r_rem(float,float);
__caller_narrow float __r_fma(float,float,float);
#define copysign(x,y) __copysignd(x,y)
#define copysignf(x,y) __copysignf(x,y)
#define acosf(x) __r_acos(x)
#define asinf(x) __r_asin(x)
639 640 641
#define atanf(x) __r_atan(x)
#define sinf(x) __r_sin(x)
#define cosf(x) __r_cos(x)
Kevin Bracey's avatar
Kevin Bracey committed
642 643 644 645 646
#define tanf(x) __r_tan(x)
#define sqrtf(x) __r_sqrt(x)
#define logf(x) __r_log(x)
#define log10f(x) __r_lg10(x)
#define expf(x) __r_exp(x)
647
#define fabsf(x) ((void) sizeof (fabsf)(x), __abs (float) (x))
648 649 650 651 652
#define floorf(x) __r_floor(x)
#define ceilf(x) __r_ceil(x)
#define truncf(x) __r_trunc(x)
#define rintf(x) __r_rint(x)
#define lrintf(x) __r_lrint(x)
Kevin Bracey's avatar
Kevin Bracey committed
653 654
#define remainderf(x,y) __r_rem(x,y)
#define fmaf(x,y,z) __r_fma(x,y,z)
655 656
#endif

Neil Turton's avatar
Neil Turton committed
657 658 659 660 661 662 663
#ifdef __cplusplus
}
#endif

#endif

/* end of math.h */