📄 0911-0913.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Complete Command Reference:Library Functions:EarthWeb Inc.-</TITLE>
</HEAD>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311046 //-->
<!-- TITLE=Linux Complete Command Reference//-->
<!-- AUTHOR=Red Hat//-->
<!-- PUBLISHER=Macmillan Computer Publishing//-->
<!-- IMPRINT=Sams//-->
<!-- CHAPTER=03 //-->
<!-- PAGES=0891-1062 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0909-0910.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0914-0915.html">Next</A></CENTER></P>
<A NAME="PAGENUM-911"><P>Page 911</P></A>
<P><B>CONFORMS TO</b>
</P>
<P>SVID 3, POSIX, BSD 4.3, ISO 9899</P>
<P></B>SEE ALSO</b>
</P>
<!-- CODE SNIP //-->
<PRE>date(1), gettimeofday(2), time(2), tzset(3),
difftime(3), strftime(3), newctime(3)
</PRE>
<!-- END CODE SNIP //-->
<P>BSD, 26 April 1996</P>
<H3><A NAME="ch03_ 37">
difftime
</A></H3>
<!-- CODE SNIP //-->
<PRE>difftime—Calculates time difference</PRE>
<!-- END CODE SNIP //-->
<P><B>SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE>
#include <time.h>
double difftime(time_t time1, time_t time0);
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>The difftime() function returns the number of seconds elapsed between time
time1 and time time0. The two times are specified in calendar time, which represents the time elapsed since 00:00:00 on January 1, 1970, Coordinated
Universal Time (UTC).
</P>
<P><B>CONFORMS TO</B>
</P>
<P>SVID 3, BSD 4.3, ISO 9899</P>
<P><B>
SEE ALSO
</B></P>
<!-- CODE SNIP //-->
<PRE>date(1), gettimeofday(2), time(2), ctime(3),
gmtime(3), localtime(3)
</PRE>
<!-- END CODE SNIP //-->GNU, 2 July 1993
<H3><A NAME="ch03_ 38">
div
</A></H3>
<P>div—Computes the quotient and remainder of integer division
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE WIDTH="1">#include <stdlib.h>
div_t div(int numer, int denom);
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>The div() function computes the value
numer/denom and returns the quotient and remainder in a structure named
div_t that contains two integer members named quot and
rem.
</P>
<P><B>
RETURN VALUE
</B></P>
<P>The div_t structure.</P>
<P><B>
CONFORMS TO
</B></P>
<P>SVID 3, BSD 4.3, ISO 9899</P>
<P></B>SEE ALSO
</B></P>
<P>ldiv(3)</P>
<P>6 June 1993</P>
<A NAME="PAGENUM-912"><P>Page 912</P></A>
<H3><A NAME="ch03_ 39">
drand48, erand48, lrand48, nrand48, mrand48,
jrand48, srand48, seed48, lcong48
</A></H3>
<!-- CODE SNIP //-->
<PRE>drand48, erand48, lrand48, nrand48, mrand48,
jrand48, srand48, seed48, lcong48—Generate uniformly distributed
pseudo-random numbers
</PRE>
<!-- END CODE SNIP //-->
<P><B>
SYNOPSIS
</B></P>
<!-- CODE //-->
<PRE WIDTH="1">
#include <stdlib.h>
double drand48(void);
double erand48(unsigned short int xsubi[3]);
long int lrand48(void);
long int nrand48(unsigned short int xsubi[3]);
long int mrand48(void);
long int jrand48(unsigned short int xsubi[3]);
void srand48(long int seedval);
unsigned short int * seed48(unsigned short int seed16v [3]);
void lcong48(unsigned short int param[7]);
</PRE>
<!-- END CODE //-->
<b><P>
DESCRIPTION
</P></b>
<P>These functions generate pseudo-random numbers using the linear congruential algorithm and 48-bit integer arithmetic.
</P>
<P>The drand48() and erand48() functions return non-negative double-precision floating-point values uniformly
distributed between [0.0, 1.0].
</P>
<P>The lrand48() and nrand48() functions return non-negative long integers uniformly distributed between 0 and 2^31.
</P>
<P>The mrand48() and jrand48() functions return signed long integers uniformly distributed between
_2^31 and 2^31.
</P>
<P>The srand48(),seed48(), and lcong48() functions are initialization functions, one of which should be called before
using drand48(), lrand48(), or mrand49(). The functions
erand48(), nrand48(), and jrand48() do not require an
initialization function to be called first.
</P>
<P>All the functions work by generating a sequence of 48-bit integers,
Xi, according to the linear congruential formula
</P>
<P>Xi+1=(aXi+c) mod m, where i >=0
<P>
<P>The parameter m=2^48; hence 48-bit integer arithmetic is performed. Unless
lcong48() is called, a and c are given by
</P>
<!-- CODE SNIP //-->
<PRE WIDTH="1">a = 0x5DEECE66D
c = 0xB
</PRE>
<!-- END CODE SNIP //-->
<P>The value returned by any of the functions
drand48(), erand48(), lrand48(), nrand48(),
mrand48(), or jrand48() is computed by first generating the next 48-bit
Xi in the sequence. Then the appropriate number of bits, according to the type of
data item to be returned, is copied from the high-order bits of
Xi and transformed into the returned value.
</P>
<P>The functions drand48(), lrand48(), and
mrand48() store the last 48-bit Xi generated in an internal buffer. The
functions erand48(), nrand48(), and jrand48() require the calling program to provide storage for the successive
Xi values in the array argument xsubi. The functions are initialized by placing the initial value of
Xi into the array before calling the function for the first time.
</P>
<P>The initializer function srand48() sets the high-order 32 bits of
Xi to the argument seedval. The low-order 16 bits are set
to the arbitrary value 0x330E.
</P>
<P>The initializer function seed48() sets the value of
Xi to the 48-bit value specified in the array argument seed16v.
The previous value of Xi is copied into an internal buffer and a pointer to this buffer is returned by
seed48().
</P>
<P>The initialization function lcong48() allows the user to specify initial values for
Xi, a and c. Array argument elements param[0-2] specify
Xi, param[3-5] specify a, and param[6] specifies c. After
lcong48() has been called, a subsequent call to either
srand48() or seed48() will restore the standard values of
a and c.
</P>
<A NAME="PAGENUM-913"><P>Page 913</P></A>
<P><B>
CONFORMS TO
</P></b>
<P>SVID 3</P>
<P><B>
NOTES
</P></b>
<P>These functions are declared obsolete by SVID 3, which states that
rand(3) should be used instead.
</P>
<P><B>
SEE ALSO
</P></b>
<!-- CODE SNIP //-->
<PRE>rand(3), random(3)</PRE>
<!-- END CODE SNIP //-->
<P>2 July 1993</P>
<H3><A NAME="ch03_ 40">
drem
</A></H3>
<P>drem—Floating-point remainder function</P>
<b><P>
SYNOPSIS
</P></b>
<!-- CODE SNIP //-->
<PRE WIDTH="1">#include <math.h>
double drem(double x, double y);
</PRE>
<!-- END CODE SNIP //-->
<b><P>
DESCRIPTION
</P></b>
<P>The drem() function computes the remainder of dividing
x by y. The return value is x_n*y, where n is the quotient of
x divided by y, rounded to the nearest integer. If the quotient is
<SUP>1</SUP>¦<SUB>2</SUB>, it is rounded to the even number.
</P>
<b><P>
RETURN VALUE
</P></b>
<P>The drem() function returns the remainder unless
y is 0, in which case the function fails and errno is set.
</P>
<b><P>
ERRORS
</P></b>
<!-- CODE SNIP //-->
<PRE>
EDOM The denominator y is 0.
</PRE>
<!-- END CODE SNIP //-->
<b><P>
CONFORMS TO
</P></b>
<P>BSD 4.3</P>
<b><P>
SEE ALSO
</P></b>
<P>fmod(3)</P>
<P>6 June 1993</P>
<H3><A NAME="ch03_ 41">
ecvt, fcvt
</A></H3>
<P>ecvt, fcvt—Convert a floating-point number to a string
</P>
<b><P>
SYNOPSIS
</P></b>
<!-- CODE SNIP //-->
<PRE WIDTH="1">
#include <stdlib.h>
char *ecvt(double number, size_t ndigits,int*decpt,int*sign);
char *fcvt(double number, size_t ndigits,int*decpt,int*sign);
</PRE>
<!-- END CODE SNIP //-->
<b><P>
DESCRIPTION
</P></b>
<P>The ecvt() function converts number to a NULL-terminated string of
ndigits digits and returns a pointer to the string.
The string itself does not contain a decimal point; however, the position of the decimal point relative to the start of the string
is</P>
<P><CENTER>
<a href="0909-0910.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0914-0915.html">Next</A></CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -