
1: @c We need some definitions here. 2: @ifclear mult 3: @ifhtml 4: @set mult · 5: @set infty ∞ 6: @set pie π 7: @end ifhtml 8: @iftex 9: @set mult @cdot 10: @set infty @infty 11: @end iftex 12: @ifclear mult 13: @set mult * 14: @set infty oo 15: @set pie pi 16: @end ifclear 17: @macro mul 18: @value{mult} 19: @end macro 20: @macro infinity 21: @value{infty} 22: @end macro 23: @ifnottex 24: @macro pi 25: @value{pie} 26: @end macro 27: @end ifnottex 28: @end ifclear 29: 30: @node Mathematics, Arithmetic, Syslog, Top 31: @c %MENU% Math functions, useful constants, random numbers 32: @chapter Mathematics 33: 34: This chapter contains information about functions for performing 35: mathematical computations, such as trigonometric functions. Most of 36: these functions have prototypes declared in the header file 37: @file{math.h}. The complex-valued functions are defined in 38: @file{complex.h}. 39: @pindex math.h 40: @pindex complex.h 41: 42: All mathematical functions which take a floating-point argument 43: have three variants, one each for @code{double}, @code{float}, and 44: @code{long double} arguments. The @code{double} versions are mostly 45: defined in @w{ISO C89}. The @code{float} and @code{long double} 46: versions are from the numeric extensions to C included in @w{ISO C99}. 47: 48: Which of the three versions of a function should be used depends on the 49: situation. For most calculations, the @code{float} functions are the 50: fastest. On the other hand, the @code{long double} functions have the 51: highest precision. @code{double} is somewhere in between. It is 52: usually wise to pick the narrowest type that can accommodate your data. 53: Not all machines have a distinct @code{long double} type; it may be the 54: same as @code{double}. 55: 56: @menu 57: * Mathematical Constants:: Precise numeric values for often-used 58: constants. 59: * Trig Functions:: Sine, cosine, tangent, and friends. 60: * Inverse Trig Functions:: Arcsine, arccosine, etc. 61: * Exponents and Logarithms:: Also pow and sqrt. 62: * Hyperbolic Functions:: sinh, cosh, tanh, etc. 63: * Special Functions:: Bessel, gamma, erf. 64: * Errors in Math Functions:: Known Maximum Errors in Math Functions. 65: * Pseudo-Random Numbers:: Functions for generating pseudo-random 66: numbers. 67: * FP Function Optimizations:: Fast code or small code. 68: @end menu 69: 70: @node Mathematical Constants 71: @section Predefined Mathematical Constants 72: @cindex constants 73: @cindex mathematical constants 74: 75: The header @file{math.h} defines several useful mathematical constants. 76: All values are defined as preprocessor macros starting with @code{M_}. 77: The values provided are: 78: 79: @vtable @code 80: @item M_E 81: The base of natural logarithms. 82: @item M_LOG2E 83: The logarithm to base @code{2} of @code{M_E}. 84: @item M_LOG10E 85: The logarithm to base @code{10} of @code{M_E}. 86: @item M_LN2 87: The natural logarithm of @code{2}. 88: @item M_LN10 89: The natural logarithm of @code{10}. 90: @item M_PI 91: Pi, the ratio of a circle's circumference to its diameter. 92: @item M_PI_2 93: Pi divided by two. 94: @item M_PI_4 95: Pi divided by four. 96: @item M_1_PI 97: The reciprocal of pi (1/pi) 98: @item M_2_PI 99: Two times the reciprocal of pi. 100: @item M_2_SQRTPI 101: Two times the reciprocal of the square root of pi. 102: @item M_SQRT2 103: The square root of two. 104: @item M_SQRT1_2 105: The reciprocal of the square root of two (also the square root of 1/2). 106: @end vtable 107: 108: These constants come from the Unix98 standard and were also available in 109: 4.4BSD; therefore they are only defined if @code{_BSD_SOURCE} or 110: @code{_XOPEN_SOURCE=500}, or a more general feature select macro, is 111: defined. The default set of features includes these constants. 112: @xref{Feature Test Macros}. 113: 114: All values are of type @code{double}. As an extension, the GNU C 115: library also defines these constants with type @code{long double}. The 116: @code{long double} macros have a lowercase @samp{l} appended to their 117: names: @code{M_El}, @code{M_PIl}, and so forth. These are only 118: available if @code{_GNU_SOURCE} is defined. 119: 120: @vindex PI 121: @emph{Note:} Some programs use a constant named @code{PI} which has the 122: same value as @code{M_PI}. This constant is not standard; it may have 123: appeared in some old AT&T headers, and is mentioned in Stroustrup's book 124: on C++. It infringes on the user's name space, so the GNU C library 125: does not define it. Fixing programs written to expect it is simple: 126: replace @code{PI} with @code{M_PI} throughout, or put @samp{-DPI=M_PI} 127: on the compiler command line. 128: 129: @node Trig Functions 130: @section Trigonometric Functions 131: @cindex trigonometric functions 132: 133: These are the familiar @code{sin}, @code{cos}, and @code{tan} functions. 134: The arguments to all of these functions are in units of radians; recall 135: that pi radians equals 180 degrees. 136: 137: @cindex pi (trigonometric constant) 138: The math library normally defines @code{M_PI} to a @code{double} 139: approximation of pi. If strict ISO and/or POSIX compliance 140: are requested this constant is not defined, but you can easily define it 141: yourself: 142: 143: @smallexample 144: #define M_PI 3.14159265358979323846264338327 145: @end smallexample 146: 147: @noindent 148: You can also compute the value of pi with the expression @code{acos 149: (-1.0)}. 150: 151: @comment math.h 152: @comment ISO 153: @deftypefun double sin (double @var{x}) 154: @comment math.h 155: @comment ISO 156: @deftypefunx float sinf (float @var{x}) 157: @comment math.h 158: @comment ISO 159: @deftypefunx {long double} sinl (long double @var{x}) 160: These functions return the sine of @var{x}, where @var{x} is given in 161: radians. The return value is in the range @code{-1} to @code{1}. 162: @end deftypefun 163: 164: @comment math.h 165: @comment ISO 166: @deftypefun double cos (double @var{x}) 167: @comment math.h 168: @comment ISO 169: @deftypefunx float cosf (float @var{x}) 170: @comment math.h 171: @comment ISO 172: @deftypefunx {long double} cosl (long double @var{x}) 173: These functions return the cosine of @var{x}, where @var{x} is given in 174: radians. The return value is in the range @code{-1} to @code{1}. 175: @end deftypefun 176: 177: @comment math.h 178: @comment ISO 179: @deftypefun double tan (double @var{x}) 180: @comment math.h 181: @comment ISO 182: @deftypefunx float tanf (float @var{x}) 183: @comment math.h 184: @comment ISO 185: @deftypefunx {long double} tanl (long double @var{x}) 186: These functions return the tangent of @var{x}, where @var{x} is given in 187: radians. 188: 189: Mathematically, the tangent function has singularities at odd multiples 190: of pi/2. If the argument @var{x} is too close to one of these 191: singularities, @code{tan} will signal overflow. 192: @end deftypefun 193: 194: In many applications where @code{sin} and @code{cos} are used, the sine 195: and cosine of the same angle are needed at the same time. It is more 196: efficient to compute them simultaneously, so the library provides a 197: function to do that. 198: 199: @comment math.h 200: @comment GNU 201: @deftypefun void sincos (double @var{x}, double *@var{sinx}, double *@var{cosx}) 202: @comment math.h 203: @comment GNU 204: @deftypefunx void sincosf (float @var{x}, float *@var{sinx}, float *@var{cosx}) 205: @comment math.h 206: @comment GNU 207: @deftypefunx void sincosl (long double @var{x}, long double *@var{sinx}, long double *@var{cosx}) 208: These functions return the sine of @var{x} in @code{*@var{sinx}} and the 209: cosine of @var{x} in @code{*@var{cos}}, where @var{x} is given in 210: radians. Both values, @code{*@var{sinx}} and @code{*@var{cosx}}, are in 211: the range of @code{-1} to @code{1}. 212: 213: This function is a GNU extension. Portable programs should be prepared 214: to cope with its absence. 215: @end deftypefun 216: 217: @cindex complex trigonometric functions 218: 219: @w{ISO C99} defines variants of the trig functions which work on 220: complex numbers. The GNU C library provides these functions, but they 221: are only useful if your compiler supports the new complex types defined 222: by the standard. 223: @c XXX Change this when gcc is fixed. -zw 224: (As of this writing GCC supports complex numbers, but there are bugs in 225: the implementation.) 226: 227: @comment complex.h 228: @comment ISO 229: @deftypefun {complex double} csin (complex double @var{z}) 230: @comment complex.h 231: @comment ISO 232: @deftypefunx {complex float} csinf (complex float @var{z}) 233: @comment complex.h 234: @comment ISO 235: @deftypefunx {complex long double} csinl (complex long double @var{z}) 236: These functions return the complex sine of @var{z}. 237: The mathematical definition of the complex sine is 238: 239: @ifnottex 240: @math{sin (z) = 1/(2*i) * (exp (z*i) - exp (-z*i))}. 241: @end ifnottex 242: @tex 243: $$\sin(z) = {1\over 2i} (e^{zi} - e^{-zi})$$ 244: @end tex 245: @end deftypefun 246: 247: @comment complex.h 248: @comment ISO 249: @deftypefun {complex double} ccos (complex double @var{z}) 250: @comment complex.h 251: @comment ISO 252: @deftypefunx {complex float} ccosf (complex float @var{z}) 253: @comment complex.h 254: @comment ISO 255: @deftypefunx {complex long double} ccosl (complex long double @var{z}) 256: These functions return the complex cosine of @var{z}. 257: The mathematical definition of the complex cosine is 258: 259: @ifnottex 260: @math{cos (z) = 1/2 * (exp (z*i) + exp (-z*i))} 261: @end ifnottex 262: @tex 263: $$\cos(z) = {1\over 2} (e^{zi} + e^{-zi})$$ 264: @end tex 265: @end deftypefun 266: 267: @comment complex.h 268: @comment ISO 269: @deftypefun {complex double} ctan (complex double @var{z}) 270: @comment complex.h 271: @comment ISO 272: @deftypefunx {complex float} ctanf (complex float @var{z}) 273: @comment complex.h 274: @comment ISO 275: @deftypefunx {complex long double} ctanl (complex long double @var{z}) 276: These functions return the complex tangent of @var{z}. 277: The mathematical definition of the complex tangent is 278: 279: @ifnottex 280: @math{tan (z) = -i * (exp (z*i) - exp (-z*i)) / (exp (z*i) + exp (-z*i))} 281: @end ifnottex 282: @tex 283: $$\tan(z) = -i \cdot {e^{zi} - e^{-zi}\over e^{zi} + e^{-zi}}$$ 284: @end tex 285: 286: @noindent 287: The complex tangent has poles at @math{pi/2 + 2n}, where @math{n} is an 288: integer. @code{ctan} may signal overflow if @var{z} is too close to a 289: pole. 290: @end deftypefun 291: 292: 293: @node Inverse Trig Functions 294: @section Inverse Trigonometric Functions 295: @cindex inverse trigonometric functions 296: 297: These are the usual arc sine, arc cosine and arc tangent functions, 298: which are the inverses of the sine, cosine and tangent functions 299: respectively. 300: 301: @comment math.h 302: @comment ISO 303: @deftypefun double asin (double @var{x}) 304: @comment math.h 305: @comment ISO 306: @deftypefunx float asinf (float @var{x}) 307: @comment math.h 308: @comment ISO 309: @deftypefunx {long double} asinl (long double @var{x}) 310: These functions compute the arc sine of @var{x}---that is, the value whose 311: sine is @var{x}. The value is in units of radians. Mathematically, 312: there are infinitely many such values; the one actually returned is the 313: one between @code{-pi/2} and @code{pi/2} (inclusive). 314: 315: The arc sine function is defined mathematically only 316: over the domain @code{-1} to @code{1}. If @var{x} is outside the 317: domain, @code{asin} signals a domain error. 318: @end deftypefun 319: 320: @comment math.h 321: @comment ISO 322: @deftypefun double acos (double @var{x}) 323: @comment math.h 324: @comment ISO 325: @deftypefunx float acosf (float @var{x}) 326: @comment math.h 327: @comment ISO 328: @deftypefunx {long double} acosl (long double @var{x}) 329: These functions compute the arc cosine of @var{x}---that is, the value 330: whose cosine is @var{x}. The value is in units of radians. 331: Mathematically, there are infinitely many such values; the one actually 332: returned is the one between @code{0} and @code{pi} (inclusive). 333: 334: The arc cosine function is defined mathematically only 335: over the domain @code{-1} to @code{1}. If @var{x} is outside the 336: domain, @code{acos} signals a domain error. 337: @end deftypefun 338: 339: @comment math.h 340: @comment ISO 341: @deftypefun double atan (double @var{x}) 342: @comment math.h 343: @comment ISO 344: @deftypefunx float atanf (float @var{x}) 345: @comment math.h 346: @comment ISO 347: @deftypefunx {long double} atanl (long double @var{x}) 348: These functions compute the arc tangent of @var{x}---that is, the value 349: whose tangent is @var{x}. The value is in units of radians. 350: Mathematically, there are infinitely many such values; the one actually 351: returned is the one between @code{-pi/2} and @code{pi/2} (inclusive). 352: @end deftypefun 353: 354: @comment math.h 355: @comment ISO 356: @deftypefun double atan2 (double @var{y}, double @var{x}) 357: @comment math.h 358: @comment ISO 359: @deftypefunx float atan2f (float @var{y}, float @var{x}) 360: @comment math.h 361: @comment ISO 362: @deftypefunx {long double} atan2l (long double @var{y}, long double @var{x}) 363: This function computes the arc tangent of @var{y}/@var{x}, but the signs 364: of both arguments are used to determine the quadrant of the result, and 365: @var{x} is permitted to be zero. The return value is given in radians 366: and is in the range @code{-pi} to @code{pi}, inclusive. 367: 368: If @var{x} and @var{y} are coordinates of a point in the plane, 369: @code{atan2} returns the signed angle between the line from the origin 370: to that point and the x-axis. Thus, @code{atan2} is useful for 371: converting Cartesian coordinates to polar coordinates. (To compute the 372: radial coordinate, use @code{hypot}; see @ref{Exponents and 373: Logarithms}.) 374: 375: @c This is experimentally true. Should it be so? -zw 376: If both @var{x} and @var{y} are zero, @code{atan2} returns zero. 377: @end deftypefun 378: 379: @cindex inverse complex trigonometric functions 380: @w{ISO C99} defines complex versions of the inverse trig functions. 381: 382: @comment complex.h 383: @comment ISO 384: @deftypefun {complex double} casin (complex double @var{z}) 385: @comment complex.h 386: @comment ISO 387: @deftypefunx {complex float} casinf (complex float @var{z}) 388: @comment complex.h 389: @comment ISO 390: @deftypefunx {complex long double} casinl (complex long double @var{z}) 391: These functions compute the complex arc sine of @var{z}---that is, the 392: value whose sine is @var{z}. The value returned is in radians. 393: 394: Unlike the real-valued functions, @code{casin} is defined for all 395: values of @var{z}. 396: @end deftypefun 397: 398: @comment complex.h 399: @comment ISO 400: @deftypefun {complex double} cacos (complex double @var{z}) 401: @comment complex.h 402: @comment ISO 403: @deftypefunx {complex float} cacosf (complex float @var{z}) 404: @comment complex.h 405: @comment ISO 406: @deftypefunx {complex long double} cacosl (complex long double @var{z}) 407: These functions compute the complex arc cosine of @var{z}---that is, the 408: value whose cosine is @var{z}. The value returned is in radians. 409: 410: Unlike the real-valued functions, @code{cacos} is defined for all 411: values of @var{z}. 412: @end deftypefun 413: 414: 415: @comment complex.h 416: @comment ISO 417: @deftypefun {complex double} catan (complex double @var{z}) 418: @comment complex.h 419: @comment ISO 420: @deftypefunx {complex float} catanf (complex float @var{z}) 421: @comment complex.h 422: @comment ISO 423: @deftypefunx {complex long double} catanl (complex long double @var{z}) 424: These functions compute the complex arc tangent of @var{z}---that is, 425: the value whose tangent is @var{z}. The value is in units of radians. 426: @end deftypefun 427: 428: 429: @node Exponents and Logarithms 430: @section Exponentiation and Logarithms 431: @cindex exponentiation functions 432: @cindex power functions 433: @cindex logarithm functions 434: 435: @comment math.h 436: @comment ISO 437: @deftypefun double exp (double @var{x}) 438: @comment math.h 439: @comment ISO 440: @deftypefunx float expf (float @var{x}) 441: @comment math.h 442: @comment ISO 443: @deftypefunx {long double} expl (long double @var{x}) 444: These functions compute @code{e} (the base of natural logarithms) raised 445: to the power @var{x}. 446: 447: If the magnitude of the result is too large to be representable, 448: @code{exp} signals overflow. 449: @end deftypefun 450: 451: @comment math.h 452: @comment ISO 453: @deftypefun double exp2 (double @var{x}) 454: @comment math.h 455: @comment ISO 456: @deftypefunx float exp2f (float @var{x}) 457: @comment math.h 458: @comment ISO 459: @deftypefunx {long double} exp2l (long double @var{x}) 460: These functions compute @code{2} raised to the power @var{x}. 461: Mathematically, @code{exp2 (x)} is the same as @code{exp (x * log (2))}. 462: @end deftypefun 463: 464: @comment math.h 465: @comment GNU 466: @deftypefun double exp10 (double @var{x}) 467: @comment math.h 468: @comment GNU 469: @deftypefunx float exp10f (float @var{x}) 470: @comment math.h 471: @comment GNU 472: @deftypefunx {long double} exp10l (long double @var{x}) 473: @comment math.h 474: @comment GNU 475: @deftypefunx double pow10 (double @var{x}) 476: @comment math.h 477: @comment GNU 478: @deftypefunx float pow10f (float @var{x}) 479: @comment math.h 480: @comment GNU 481: @deftypefunx {long double} pow10l (long double @var{x}) 482: These functions compute @code{10} raised to the power @var{x}. 483: Mathematically, @code{exp10 (x)} is the same as @code{exp (x * log (10))}. 484: 485: These functions are GNU extensions. The name @code{exp10} is 486: preferred, since it is analogous to @code{exp} and @code{exp2}. 487: @end deftypefun 488: 489: 490: @comment math.h 491: @comment ISO 492: @deftypefun double log (double @var{x}) 493: @comment math.h 494: @comment ISO 495: @deftypefunx float logf (float @var{x}) 496: @comment math.h 497: @comment ISO 498: @deftypefunx {long double} logl (long double @var{x}) 499: These functions compute the natural logarithm of @var{x}. @code{exp (log 500: (@var{x}))} equals @var{x}, exactly in mathematics and approximately in 501: C. 502: 503: If @var{x} is negative, @code{log} signals a domain error. If @var{x} 504: is zero, it returns negative infinity; if @var{x} is too close to zero, 505: it may signal overflow. 506: @end deftypefun 507: 508: @comment math.h 509: @comment ISO 510: @deftypefun double log10 (double @var{x}) 511: @comment math.h 512: @comment ISO 513: @deftypefunx float log10f (float @var{x}) 514: @comment math.h 515: @comment ISO 516: @deftypefunx {long double} log10l (long double @var{x}) 517: These functions return the base-10 logarithm of @var{x}. 518: @code{log10 (@var{x})} equals @code{log (@var{x}) / log (10)}. 519: 520: @end deftypefun 521: 522: @comment math.h 523: @comment ISO 524: @deftypefun double log2 (double @var{x}) 525: @comment math.h 526: @comment ISO 527: @deftypefunx float log2f (float @var{x}) 528: @comment math.h 529: @comment ISO 530: @deftypefunx {long double} log2l (long double @var{x}) 531: These functions return the base-2 logarithm of @var{x}. 532: @code{log2 (@var{x})} equals @code{log (@var{x}) / log (2)}. 533: @end deftypefun 534: 535: @comment math.h 536: @comment ISO 537: @deftypefun double logb (double @var{x}) 538: @comment math.h 539: @comment ISO 540: @deftypefunx float logbf (float @var{x}) 541: @comment math.h 542: @comment ISO 543: @deftypefunx {long double} logbl (long double @var{x}) 544: These functions extract the exponent of @var{x} and return it as a 545: floating-point value. If @code{FLT_RADIX} is two, @code{logb} is equal 546: to @code{floor (log2 (x))}, except it's probably faster. 547: 548: If @var{x} is de-normalized, @code{logb} returns the exponent @var{x} 549: would have if it were normalized. If @var{x} is infinity (positive or 550: negative), @code{logb} returns @math{@infinity{}}. If @var{x} is zero, 551: @code{logb} returns @math{@infinity{}}. It does not signal. 552: @end deftypefun 553: 554: @comment math.h 555: @comment ISO 556: @deftypefun int ilogb (double @var{x}) 557: @comment math.h 558: @comment ISO 559: @deftypefunx int ilogbf (float @var{x}) 560: @comment math.h 561: @comment ISO 562: @deftypefunx int ilogbl (long double @var{x}) 563: These functions are equivalent to the corresponding @code{logb} 564: functions except that they return signed integer values. 565: @end deftypefun 566: 567: @noindent 568: Since integers cannot represent infinity and NaN, @code{ilogb} instead 569: returns an integer that can't be the exponent of a normal floating-point 570: number. @file{math.h} defines constants so you can check for this. 571: 572: @comment math.h 573: @comment ISO 574: @deftypevr Macro int FP_ILOGB0 575: @code{ilogb} returns this value if its argument is @code{0}. The 576: numeric value is either @code{INT_MIN} or @code{-INT_MAX}. 577: 578: This macro is defined in @w{ISO C99}. 579: @end deftypevr 580: 581: @comment math.h 582: @comment ISO 583: @deftypevr Macro int FP_ILOGBNAN 584: @code{ilogb} returns this value if its argument is @code{NaN}. The 585: numeric value is either @code{INT_MIN} or @code{INT_MAX}. 586: 587: This macro is defined in @w{ISO C99}. 588: @end deftypevr 589: 590: These values are system specific. They might even be the same. The 591: proper way to test the result of @code{ilogb} is as follows: 592: 593: @smallexample 594: i = ilogb (f); 595: if (i == FP_ILOGB0 || i == FP_ILOGBNAN) 596: @{ 597: if (isnan (f)) 598: @{ 599: /* @r{Handle NaN.} */ 600: @} 601: else if (f == 0.0) 602: @{ 603: /* @r{Handle 0.0.} */ 604: @} 605: else 606: @{ 607: /* @r{Some other value with large exponent,} 608: @r{perhaps +Inf.} */ 609: @} 610: @} 611: @end smallexample 612: 613: @comment math.h 614: @comment ISO 615: @deftypefun double pow (double @var{base}, double @var{power}) 616: @comment math.h 617: @comment ISO 618: @deftypefunx float powf (float @var{base}, float @var{power}) 619: @comment math.h 620: @comment ISO 621: @deftypefunx {long double} powl (long double @var{base}, long double @var{power}) 622: These are general exponentiation functions, returning @var{base} raised 623: to @var{power}. 624: 625: Mathematically, @code{pow} would return a complex number when @var{base} 626: is negative and @var{power} is not an integral value. @code{pow} can't 627: do that, so instead it signals a domain error. @code{pow} may also 628: underflow or overflow the destination type. 629: @end deftypefun 630: 631: @cindex square root function 632: @comment math.h 633: @comment ISO 634: @deftypefun double sqrt (double @var{x}) 635: @comment math.h 636: @comment ISO 637: @deftypefunx float sqrtf (float @var{x}) 638: @comment math.h 639: @comment ISO 640: @deftypefunx {long double} sqrtl (long double @var{x}) 641: These functions return the nonnegative square root of @var{x}. 642: 643: If @var{x} is negative, @code{sqrt} signals a domain error. 644: Mathematically, it should return a complex number. 645: @end deftypefun 646: 647: @cindex cube root function 648: @comment math.h 649: @comment BSD 650: @deftypefun double cbrt (double @var{x}) 651: @comment math.h 652: @comment BSD 653: @deftypefunx float cbrtf (float @var{x}) 654: @comment math.h 655: @comment BSD 656: @deftypefunx {long double} cbrtl (long double @var{x}) 657: These functions return the cube root of @var{x}. They cannot 658: fail; every representable real value has a representable real cube root. 659: @end deftypefun 660: 661: @comment math.h 662: @comment ISO 663: @deftypefun double hypot (double @var{x}, double @var{y}) 664: @comment math.h 665: @comment ISO 666: @deftypefunx float hypotf (float @var{x}, float @var{y}) 667: @comment math.h 668: @comment ISO 669: @deftypefunx {long double} hypotl (long double @var{x}, long double @var{y}) 670: These functions return @code{sqrt (@var{x}*@var{x} + 671: @var{y}*@var{y})}. This is the length of the hypotenuse of a right 672: triangle with sides of length @var{x} and @var{y}, or the distance 673: of the point (@var{x}, @var{y}) from the origin. Using this function 674: instead of the direct formula is wise, since the error is 675: much smaller. See also the function @code{cabs} in @ref{Absolute Value}. 676: @end deftypefun 677: 678: @comment math.h 679: @comment ISO 680: @deftypefun double expm1 (double @var{x}) 681: @comment math.h 682: @comment ISO 683: @deftypefunx float expm1f (float @var{x}) 684: @comment math.h 685: @comment ISO 686: @deftypefunx {long double} expm1l (long double @var{x}) 687: These functions return a value equivalent to @code{exp (@var{x}) - 1}. 688: They are computed in a way that is accurate even if @var{x} is 689: near zero---a case where @code{exp (@var{x}) - 1} would be inaccurate owing 690: to subtraction of two numbers that are nearly equal. 691: @end deftypefun 692: 693: @comment math.h 694: @comment ISO 695: @deftypefun double log1p (double @var{x}) 696: @comment math.h 697: @comment ISO 698: @deftypefunx float log1pf (float @var{x}) 699: @comment math.h 700: @comment ISO 701: @deftypefunx {long double} log1pl (long double @var{x}) 702: These functions returns a value equivalent to @w{@code{log (1 + @var{x})}}. 703: They are computed in a way that is accurate even if @var{x} is 704: near zero. 705: @end deftypefun 706: 707: @cindex complex exponentiation functions 708: @cindex complex logarithm functions 709: 710: @w{ISO C99} defines complex variants of some of the exponentiation and 711: logarithm functions. 712: 713: @comment complex.h 714: @comment ISO 715: @deftypefun {complex double} cexp (complex double @var{z}) 716: @comment complex.h 717: @comment ISO 718: @deftypefunx {complex float} cexpf (complex float @var{z}) 719: @comment complex.h 720: @comment ISO 721: @deftypefunx {complex long double} cexpl (complex long double @var{z}) 722: These functions return @code{e} (the base of natural 723: logarithms) raised to the power of @var{z}. 724: Mathematically, this corresponds to the value 725: 726: @ifnottex 727: @math{exp (z) = exp (creal (z)) * (cos (cimag (z)) + I * sin (cimag (z)))} 728: @end ifnottex 729: @tex 730: $$\exp(z) = e^z = e^{{\rm Re}\,z} (\cos ({\rm Im}\,z) + i \sin ({\rm Im}\,z))$$ 731: @end tex 732: @end deftypefun 733: 734: @comment complex.h 735: @comment ISO 736: @deftypefun {complex double} clog (complex double @var{z}) 737: @comment complex.h 738: @comment ISO 739: @deftypefunx {complex float} clogf (complex float @var{z}) 740: @comment complex.h 741: @comment ISO 742: @deftypefunx {complex long double} clogl (complex long double @var{z}) 743: These functions return the natural logarithm of @var{z}. 744: Mathematically, this corresponds to the value 745: 746: @ifnottex 747: @math{log (z) = log (cabs (z)) + I * carg (z)} 748: @end ifnottex 749: @tex 750: $$\log(z) = \log |z| + i \arg z$$ 751: @end tex 752: 753: @noindent 754: @code{clog} has a pole at 0, and will signal overflow if @var{z} equals 755: or is very close to 0. It is well-defined for all other values of 756: @var{z}. 757: @end deftypefun 758: 759: 760: @comment complex.h 761: @comment GNU 762: @deftypefun {complex double} clog10 (complex double @var{z}) 763: @comment complex.h 764: @comment GNU 765: @deftypefunx {complex float} clog10f (complex float @var{z}) 766: @comment complex.h 767: @comment GNU 768: @deftypefunx {complex long double} clog10l (complex long double @var{z}) 769: These functions return the base 10 logarithm of the complex value 770: @var{z}. Mathematically, this corresponds to the value 771: 772: @ifnottex 773: @math{log (z) = log10 (cabs (z)) + I * carg (z)} 774: @end ifnottex 775: @tex 776: $$\log_{10}(z) = \log_{10}|z| + i \arg z$$ 777: @end tex 778: 779: These functions are GNU extensions. 780: @end deftypefun 781: 782: @comment complex.h 783: @comment ISO 784: @deftypefun {complex double} csqrt (complex double @var{z}) 785: @comment complex.h 786: @comment ISO 787: @deftypefunx {complex float} csqrtf (complex float @var{z}) 788: @comment complex.h 789: @comment ISO 790: @deftypefunx {complex long double} csqrtl (complex long double @var{z}) 791: These functions return the complex square root of the argument @var{z}. Unlike 792: the real-valued functions, they are defined for all values of @var{z}. 793: @end deftypefun 794: 795: @comment complex.h 796: @comment ISO 797: @deftypefun {complex double} cpow (complex double @var{base}, complex double @var{power}) 798: @comment complex.h 799: @comment ISO 800: <