📄 math.texi
字号:
@comment ANSI@deftypefun double pow (double @var{base}, double @var{power})This is a general exponentiation function, returning @var{base} raisedto @var{power}.@need 250The following @code{errno} error conditions are defined for this function:@table @code@item EDOMThe argument @var{base} is negative and @var{power} is not an integralvalue. Mathematically, the result would be a complex number in this case.@item ERANGEAn underflow or overflow condition was detected in the result.@end table@end deftypefun@cindex square root function@comment math.h@comment ANSI@deftypefun double sqrt (double @var{x})This function returns the nonnegative square root of @var{x}.The @code{sqrt} function fails, and sets @code{errno} to @code{EDOM}, if@var{x} is negative. Mathematically, the square root would be a complexnumber.@end deftypefun@cindex cube root function@comment math.h@comment BSD@deftypefun double cbrt (double @var{x})This function returns the cube root of @var{x}. This function cannotfail; every representable real value has a representable real cube root.@end deftypefun@comment math.h@comment BSD@deftypefun double hypot (double @var{x}, double @var{y})The @code{hypot} function returns @code{sqrt (@var{x}*@var{x} +@var{y}*@var{y})}. (This is the length of the hypotenuse of a righttriangle with sides of length @var{x} and @var{y}, or the distanceof the point (@var{x}, @var{y}) from the origin.) See also the function@code{cabs} in @ref{Absolute Value}.@end deftypefun@comment math.h@comment BSD@deftypefun double expm1 (double @var{x})This function returns a value equivalent to @code{exp (@var{x}) - 1}.It is computed in a way that is accurate even if the value of @var{x} isnear zero---a case where @code{exp (@var{x}) - 1} would be inaccurate dueto subtraction of two numbers that are nearly equal.@end deftypefun@comment math.h@comment BSD@deftypefun double log1p (double @var{x})This function returns a value equivalent to @w{@code{log (1 + @var{x})}}.It is computed in a way that is accurate even if the value of @var{x} isnear zero.@end deftypefun@node Hyperbolic Functions@section Hyperbolic Functions@cindex hyperbolic functionsThe functions in this section are related to the exponential functions;see @ref{Exponents and Logarithms}.@comment math.h@comment ANSI@deftypefun double sinh (double @var{x})The @code{sinh} function returns the hyperbolic sine of @var{x}, definedmathematically as @w{@code{exp (@var{x}) - exp (-@var{x}) / 2}}. Thefunction fails, and sets @code{errno} to @code{ERANGE}, if the value of@var{x} is too large; that is, if overflow occurs.@end deftypefun@comment math.h@comment ANSI@deftypefun double cosh (double @var{x})The @code{cosh} function returns the hyperbolic cosine of @var{x},defined mathematically as @w{@code{exp (@var{x}) + exp (-@var{x}) / 2}}.The function fails, and sets @code{errno} to @code{ERANGE}, if the valueof @var{x} is too large; that is, if overflow occurs.@end deftypefun@comment math.h@comment ANSI@deftypefun double tanh (double @var{x})This function returns the hyperbolic tangent of @var{x}, whose mathematical definition is @w{@code{sinh (@var{x}) / cosh (@var{x})}}.@end deftypefun@cindex inverse hyperbolic functions@comment math.h@comment BSD@deftypefun double asinh (double @var{x})This function returns the inverse hyperbolic sine of @var{x}---thevalue whose hyperbolic sine is @var{x}.@end deftypefun@comment math.h@comment BSD@deftypefun double acosh (double @var{x})This function returns the inverse hyperbolic cosine of @var{x}---thevalue whose hyperbolic cosine is @var{x}. If @var{x} is less than@code{1}, @code{acosh} returns @code{HUGE_VAL}.@end deftypefun@comment math.h@comment BSD@deftypefun double atanh (double @var{x})This function returns the inverse hyperbolic tangent of @var{x}---thevalue whose hyperbolic tangent is @var{x}. If the absolute value of@var{x} is greater than or equal to @code{1}, @code{atanh} returns@code{HUGE_VAL}.@end deftypefun@node Pseudo-Random Numbers@section Pseudo-Random Numbers@cindex random numbers@cindex pseudo-random numbers@cindex seed (for random numbers)This section describes the GNU facilities for generating a series ofpseudo-random numbers. The numbers generated are not truly random;typically, they form a sequence that repeats periodically, with aperiod so large that you can ignore it for ordinary purposes. Therandom number generator works by remembering at all times a @dfn{seed}value which it uses to compute the next random number and also tocompute a new seed.Although the generated numbers look unpredictable within one run of aprogram, the sequence of numbers is @emph{exactly the same} from one runto the next. This is because the initial seed is always the same. Thisis convenient when you are debugging a program, but it is unhelpful ifyou want the program to behave unpredictably. If you want truly randomnumbers, not just pseudo-random, specify a seed based on the currenttime.You can get repeatable sequences of numbers on a particular machine typeby specifying the same initial seed value for the random numbergenerator. There is no standard meaning for a particular seed value;the same seed, used in different C libraries or on different CPU types,will give you different random numbers.The GNU library supports the standard ANSI C random number functionsplus another set derived from BSD. We recommend you use the standardones, @code{rand} and @code{srand}.@menu* ANSI Random:: @code{rand} and friends.* BSD Random:: @code{random} and friends.@end menu@node ANSI Random@subsection ANSI C Random Number FunctionsThis section describes the random number functions that are part ofthe ANSI C standard.To use these facilities, you should include the header file@file{stdlib.h} in your program.@pindex stdlib.h@comment stdlib.h@comment ANSI@deftypevr Macro int RAND_MAXThe value of this macro is an integer constant expression thatrepresents the maximum possible value returned by the @code{rand}function. In the GNU library, it is @code{037777777}, which is thelargest signed integer representable in 32 bits. In other libraries, itmay be as low as @code{32767}.@end deftypevr@comment stdlib.h@comment ANSI@deftypefun int rand ()The @code{rand} function returns the next pseudo-random number in theseries. The value is in the range from @code{0} to @code{RAND_MAX}.@end deftypefun@comment stdlib.h@comment ANSI@deftypefun void srand (unsigned int @var{seed})This function establishes @var{seed} as the seed for a new series ofpseudo-random numbers. If you call @code{rand} before a seed has beenestablished with @code{srand}, it uses the value @code{1} as a defaultseed.To produce truly random numbers (not just pseudo-random), do @code{srand(time (0))}.@end deftypefun@node BSD Random@subsection BSD Random Number FunctionsThis section describes a set of random number generation functions thatare derived from BSD. There is no advantage to using these functionswith the GNU C library; we support them for BSD compatibility only.The prototypes for these functions are in @file{stdlib.h}.@pindex stdlib.h@comment stdlib.h@comment BSD@deftypefun {long int} random ()This function returns the next pseudo-random number in the sequence.The range of values returned is from @code{0} to @code{RAND_MAX}.@end deftypefun@comment stdlib.h@comment BSD@deftypefun void srandom (unsigned int @var{seed})The @code{srandom} function sets the seed for the current random numberstate based on the integer @var{seed}. If you supply a @var{seed} valueof @code{1}, this will cause @code{random} to reproduce the default setof random numbers.To produce truly random numbers (not just pseudo-random), do@code{srandom (time (0))}.@end deftypefun@comment stdlib.h@comment BSD@deftypefun {void *} initstate (unsigned int @var{seed}, void *@var{state}, size_t @var{size})The @code{initstate} function is used to initialize the random numbergenerator state. The argument @var{state} is an array of @var{size}bytes, used to hold the state information. The size must be at least 8bytes, and optimal sizes are 8, 16, 32, 64, 128, and 256. The biggerthe @var{state} array, the better.The return value is the previous value of the state information array.You can use this value later as an argument to @code{setstate} torestore that state.@end deftypefun@comment stdlib.h@comment BSD@deftypefun {void *} setstate (void *@var{state})The @code{setstate} function restores the random number stateinformation @var{state}. The argument must have been the result ofa previous call to @var{initstate} or @var{setstate}. The return value is the previous value of the state information array.You can use thise value later as an argument to @code{setstate} torestore that state.@end deftypefun
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -