📄 library_17.html
字号:
<A NAME="IDX1266"></A>
<U>Function:</U> double <B>pow</B> <I>(double <VAR>base</VAR>, double <VAR>power</VAR>)</I><P>
This is a general exponentiation function, returning <VAR>base</VAR> raised
to <VAR>power</VAR>.
<P>
The following <CODE>errno</CODE> error conditions are defined for this function:
<P>
<DL COMPACT>
<DT><CODE>EDOM</CODE>
<DD>The argument <VAR>base</VAR> is negative and <VAR>power</VAR> is not an integral
value. Mathematically, the result would be a complex number in this case.
<P>
<DT><CODE>ERANGE</CODE>
<DD>An underflow or overflow condition was detected in the result.
</DL>
<P>
<A NAME="IDX1267"></A>
<P>
<A NAME="IDX1268"></A>
<U>Function:</U> double <B>sqrt</B> <I>(double <VAR>x</VAR>)</I><P>
This function returns the nonnegative square root of <VAR>x</VAR>.
<P>
The <CODE>sqrt</CODE> function fails, and sets <CODE>errno</CODE> to <CODE>EDOM</CODE>, if
<VAR>x</VAR> is negative. Mathematically, the square root would be a complex
number.
<P>
<A NAME="IDX1269"></A>
<P>
<A NAME="IDX1270"></A>
<U>Function:</U> double <B>cbrt</B> <I>(double <VAR>x</VAR>)</I><P>
This function returns the cube root of <VAR>x</VAR>. This function cannot
fail; every representable real value has a represetable real cube root.
<P>
<A NAME="IDX1271"></A>
<U>Function:</U> double <B>hypot</B> <I>(double <VAR>x</VAR>, double <VAR>y</VAR>)</I><P>
The <CODE>hypot</CODE> function returns <CODE>sqrt (<VAR>x</VAR>*<VAR>x</VAR> +
<VAR>y</VAR>*<VAR>y</VAR>)</CODE>. (This is the length of the hypotenuse of a right
triangle with sides of length <VAR>x</VAR> and <VAR>y</VAR>, or the distance
of the point (<VAR>x</VAR>, <VAR>y</VAR>) from the origin.) See also the function
<CODE>cabs</CODE> in section <A HREF="library_18.html#SEC302" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_18.html#SEC302">Absolute Value</A>.
<P>
<A NAME="IDX1272"></A>
<U>Function:</U> double <B>expm1</B> <I>(double <VAR>x</VAR>)</I><P>
This function returns a value equivalent to <CODE>exp (<VAR>x</VAR>) - 1</CODE>.
It is computed in a way that is accurate even if the value of <VAR>x</VAR> is
near zero--a case where <CODE>exp (<VAR>x</VAR>) - 1</CODE> would be inaccurate due
to subtraction of two numbers that are nearly equal.
<P>
<A NAME="IDX1273"></A>
<U>Function:</U> double <B>log1p</B> <I>(double <VAR>x</VAR>)</I><P>
This function returns a value equivalent to <CODE>log (1 + <VAR>x</VAR>)</CODE>.
It is computed in a way that is accurate even if the value of <VAR>x</VAR> is
near zero.
<P>
<A NAME="IDX1274"></A>
<H2><A NAME="SEC295" HREF="library_toc.html#SEC295" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC295">Hyperbolic Functions</A></H2>
<P>
The functions in this section are related to the exponential functions;
see section <A HREF="library_17.html#SEC294" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_17.html#SEC294">Exponentiation and Logarithms</A>.
<P>
<A NAME="IDX1275"></A>
<U>Function:</U> double <B>sinh</B> <I>(double <VAR>x</VAR>)</I><P>
The <CODE>sinh</CODE> function returns the hyperbolic sine of <VAR>x</VAR>, defined
mathematically as <CODE>exp (<VAR>x</VAR>) - exp (-<VAR>x</VAR>) / 2</CODE>. The
function fails, and sets <CODE>errno</CODE> to <CODE>ERANGE</CODE>, if the value of
<VAR>x</VAR> is too large; that is, if overflow occurs.
<P>
<A NAME="IDX1276"></A>
<U>Function:</U> double <B>cosh</B> <I>(double <VAR>x</VAR>)</I><P>
The <CODE>cosh</CODE> function returns the hyperbolic cosine of <VAR>x</VAR>,
defined mathematically as <CODE>exp (<VAR>x</VAR>) + exp (-<VAR>x</VAR>) / 2</CODE>.
The function fails, and sets <CODE>errno</CODE> to <CODE>ERANGE</CODE>, if the value
of <VAR>x</VAR> is too large; that is, if overflow occurs.
<P>
<A NAME="IDX1277"></A>
<U>Function:</U> double <B>tanh</B> <I>(double <VAR>x</VAR>)</I><P>
This function returns the hyperbolic tangent of <VAR>x</VAR>, whose
mathematical definition is <CODE>sinh (<VAR>x</VAR>) / cosh (<VAR>x</VAR>)</CODE>.
<P>
<A NAME="IDX1278"></A>
<P>
<A NAME="IDX1279"></A>
<U>Function:</U> double <B>asinh</B> <I>(double <VAR>x</VAR>)</I><P>
This function returns the inverse hyperbolic sine of <VAR>x</VAR>---the
value whose hyperbolic sine is <VAR>x</VAR>.
<P>
<A NAME="IDX1280"></A>
<U>Function:</U> double <B>acosh</B> <I>(double <VAR>x</VAR>)</I><P>
This function returns the inverse hyperbolic cosine of <VAR>x</VAR>---the
value whose hyperbolic cosine is <VAR>x</VAR>. If <VAR>x</VAR> is less than
<CODE>1</CODE>, <CODE>acosh</CODE> returns <CODE>HUGE_VAL</CODE>.
<P>
<A NAME="IDX1281"></A>
<U>Function:</U> double <B>atanh</B> <I>(double <VAR>x</VAR>)</I><P>
This function returns the inverse hyperbolic tangent of <VAR>x</VAR>---the
value whose hyperbolic tangent is <VAR>x</VAR>. If the absolute value of
<VAR>x</VAR> is greater than or equal to <CODE>1</CODE>, <CODE>atanh</CODE> returns
<CODE>HUGE_VAL</CODE>.
<P>
<A NAME="IDX1282"></A>
<A NAME="IDX1283"></A>
<A NAME="IDX1284"></A>
<H2><A NAME="SEC296" HREF="library_toc.html#SEC296" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC296">Pseudo-Random Numbers</A></H2>
<P>
This section describes the GNU facilities for generating a series of
pseudo-random numbers. The numbers generated are not truly random;
typically, they form a sequence that repeats periodically, with a
period so large that you can ignore it for ordinary purposes. The
random number generator works by remembering at all times a <DFN>seed</DFN>
value which it uses to compute the next random number and also to
compute a new seed.
<P>
Although the generated numbers look unpredictable within one run of a
program, the sequence of numbers is <EM>exactly the same</EM> from one run
to the next. This is because the initial seed is always the same. This
is convenient when you are debugging a program, but it is unhelpful if
you want the program to behave unpredictably. If you want truly random
numbers, not just pseudo-random, specify a seed based on the current
time.
<P>
You can get repeatable sequences of numbers on a particular machine type
by specifying the same initial seed value for the random number
generator. 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.
<P>
The GNU library supports the standard ANSI C random number functions
plus another set derived from BSD. We recommend you use the standard
ones, <CODE>rand</CODE> and <CODE>srand</CODE>.
<P>
<H3><A NAME="SEC297" HREF="library_toc.html#SEC297" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC297">ANSI C Random Number Functions</A></H3>
<P>
This section describes the random number functions that are part of
the ANSI C standard.
<P>
To use these facilities, you should include the header file
<TT>`stdlib.h'</TT> in your program.
<A NAME="IDX1285"></A>
<P>
<A NAME="IDX1286"></A>
<U>Macro:</U> int <B>RAND_MAX</B><P>
The value of this macro is an integer constant expression that
represents the maximum possible value returned by the <CODE>rand</CODE>
function. In the GNU library, it is <CODE>037777777</CODE>, which is the
largest signed integer representable in 32 bits. In other libraries, it
may be as low as <CODE>32767</CODE>.
<P>
<A NAME="IDX1287"></A>
<U>Function:</U> int <B>rand</B> <I>()</I><P>
The <CODE>rand</CODE> function returns the next pseudo-random number in the
series. The value is in the range from <CODE>0</CODE> to <CODE>RAND_MAX</CODE>.
<P>
<A NAME="IDX1288"></A>
<U>Function:</U> void <B>srand</B> <I>(unsigned int <VAR>seed</VAR>)</I><P>
This function establishes <VAR>seed</VAR> as the seed for a new series of
pseudo-random numbers. If you call <CODE>rand</CODE> before a seed has been
established with <CODE>srand</CODE>, it uses the value <CODE>1</CODE> as a default
seed.
<P>
To produce truly random numbers (not just pseudo-random), do <CODE>srand
(time (0))</CODE>.
<P>
<H3><A NAME="SEC298" HREF="library_toc.html#SEC298" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC298">BSD Random Number Functions</A></H3>
<P>
This section describes a set of random number generation functions that
are derived from BSD. There is no advantage to using these functions
with the GNU C library; we support them for BSD compatibility only.
<P>
The prototypes for these functions are in <TT>`stdlib.h'</TT>.
<A NAME="IDX1289"></A>
<P>
<A NAME="IDX1290"></A>
<U>Function:</U> long int <B>random</B> <I>()</I><P>
This function returns the next pseudo-random number in the sequence.
The range of values returned is from <CODE>0</CODE> to <CODE>RAND_MAX</CODE>.
<P>
<A NAME="IDX1291"></A>
<U>Function:</U> void <B>srandom</B> <I>(unsigned int <VAR>seed</VAR>)</I><P>
The <CODE>srandom</CODE> function sets the seed for the current random number
state based on the integer <VAR>seed</VAR>. If you supply a <VAR>seed</VAR> value
of <CODE>1</CODE>, this will cause <CODE>random</CODE> to reproduce the default set
of random numbers.
<P>
To produce truly random numbers (not just pseudo-random), do
<CODE>srandom (time (0))</CODE>.
<P>
<A NAME="IDX1292"></A>
<U>Function:</U> void * <B>initstate</B> <I>(unsigned int <VAR>seed</VAR>, void *<VAR>state</VAR>, size_t <VAR>size</VAR>)</I><P>
The <CODE>initstate</CODE> function is used to initialize the random number
generator state. The argument <VAR>state</VAR> is an array of <VAR>size</VAR>
bytes, used to hold the state information. The size must be at least 8
bytes, and optimal sizes are 8, 16, 32, 64, 128, and 256. The bigger
the <VAR>state</VAR> array, the better.
<P>
The return value is the previous value of the state information array.
You can use this value later as an argument to <CODE>setstate</CODE> to
restore that state.
<P>
<A NAME="IDX1293"></A>
<U>Function:</U> void * <B>setstate</B> <I>(void *<VAR>state</VAR>)</I><P>
The <CODE>setstate</CODE> function restores the random number state
information <VAR>state</VAR>. The argument must have been the result of
a previous call to <VAR>initstate</VAR> or <VAR>setstate</VAR>.
<P>
The return value is the previous value of the state information array.
You can use thise value later as an argument to <CODE>setstate</CODE> to
restore that state.
<P>
<P>Go to the <A HREF="library_16.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html">previous</A>, <A HREF="library_18.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_18.html">next</A> section.<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -