/
html/
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
     from ProgrammersManual.texinfo on 4 March 1997 -->

<TITLE>LambdaMOO Programmer's Manual - Manipulating Numbers</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_42.html">previous</A>, <A HREF="ProgrammersManual_44.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>.
<P><HR><P>


<H4><A NAME="SEC43" HREF="ProgrammersManual_toc.html#TOC43">Operations on Numbers</A></H4>

<P>
<DL>
<DT><U>Function:</U> int <B>random</B> <I>([int <VAR>mod</VAR>])</I>
<DD><A NAME="IDX12"></A>
<VAR>mod</VAR> must be a positive integer; otherwise, <CODE>E_INVARG</CODE> is raised.  An
integer is chosen randomly from the range <CODE>[1..<VAR>mod</VAR>]</CODE> and returned.
If <VAR>mod</VAR> is not provided, it defaults to the largest MOO integer,
2147483647.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> num <B>min</B> <I>(num <VAR>x</VAR>, ...)</I>
<DD><A NAME="IDX13"></A>
<DT><U>Function:</U> num <B>max</B> <I>(num <VAR>x</VAR>, ...)</I>
<DD><A NAME="IDX14"></A>
These two functions return the smallest or largest of their arguments,
respectively.  All of the arguments must be numbers of the same kind (i.e.,
either integer or floating-point); otherwise <CODE>E_TYPE</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> num <B>abs</B> <I>(num <VAR>x</VAR>)</I>
<DD><A NAME="IDX15"></A>
Returns the absolute value of <VAR>x</VAR>.  If <VAR>x</VAR> is negative, then the result
is <CODE>-<VAR>x</VAR></CODE>; otherwise, the result is <VAR>x</VAR>.  The number <VAR>x</VAR> can
be either integer or floating-point; the result is of the same kind.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> str <B>floatstr(float</B> <I><VAR>x</VAR>, int <VAR>precision</VAR> [, <VAR>scientific</VAR>])</I>
<DD><A NAME="IDX16"></A>
Converts <VAR>x</VAR> into a string with more control than provided by either
<CODE>tostr()</CODE> or <CODE>toliteral()</CODE>.  <VAR>Precision</VAR> is the number of digits
to appear to the right of the decimal point, capped at 4 more than the maximum
available precision, a total of 19 on most machines; this makes it possible to
avoid rounding errors if the resulting string is subsequently read back as a
floating-point value.  If <VAR>scientific</VAR> is false or not provided, the result
is a string in the form <CODE>"MMMMMMM.DDDDDD"</CODE>, preceded by a minus sign if
and only if <VAR>x</VAR> is negative.  If <VAR>scientific</VAR> is provided and true, the
result is a string in the form <CODE>"M.DDDDDDe+EEE"</CODE>, again preceded by a
minus sign if and only if <VAR>x</VAR> is negative.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>sqrt</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX17"></A>
Returns the square root of <VAR>x</VAR>.  Raises <CODE>E_INVARG</CODE> if <VAR>x</VAR> is
negative.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>sin</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX18"></A>
<DT><U>Function:</U> float <B>cos</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX19"></A>
<DT><U>Function:</U> float <B>tan</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX20"></A>
Returns the sine, cosine, or tangent of <VAR>x</VAR>, respectively.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>asin</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX21"></A>
<DT><U>Function:</U> float <B>acos</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX22"></A>
Returns the arc-sine or arc-cosine (inverse sine or cosine) of <VAR>x</VAR>, in the
range <CODE>[-pi/2..pi/2]</CODE> or <CODE>[0..pi]</CODE>, respectively.  Raises
<CODE>E_INVARG</CODE> if <VAR>x</VAR> is outside the range <CODE>[-1.0..1.0]</CODE>.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>atan</B> <I>(float <VAR>y</VAR> [, float <VAR>x</VAR>])</I>
<DD><A NAME="IDX23"></A>
Returns the arc-tangent (inverse tangent) of <VAR>y</VAR> in the range
<CODE>[-pi/2..pi/2]</CODE> if <VAR>x</VAR> is not provided, or of <CODE><VAR>y</VAR>/<VAR>x</VAR></CODE>
in the range <CODE>[-pi..pi]</CODE> if <VAR>x</VAR> is provided.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>sinh</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX24"></A>
<DT><U>Function:</U> float <B>cosh</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX25"></A>
<DT><U>Function:</U> float <B>tanh</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX26"></A>
Returns the hyperbolic sine, cosine, or tangent of <VAR>x</VAR>, respectively.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>exp</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX27"></A>
Returns <VAR>e</VAR> raised to the power of <VAR>x</VAR>.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>log</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX28"></A>
<DT><U>Function:</U> float <B>log10</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX29"></A>
Returns the natural or base 10 logarithm of <VAR>x</VAR>.  Raises <CODE>E_INVARG</CODE> if
<VAR>x</VAR> is not positive.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>ceil</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX30"></A>
Returns the smallest integer not less than <VAR>x</VAR>, as a floating-point number.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>floor</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX31"></A>
Returns the largest integer not greater than <VAR>x</VAR>, as a floating-point
number.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>trunc</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX32"></A>
Returns the integer obtained by truncating <VAR>x</VAR> at the decimal point, as a
floating-point number.  For negative <VAR>x</VAR>, this is equivalent to
<CODE>ceil()</CODE>; otherwise it is equivalent to <CODE>floor()</CODE>.
</DL>

</P>
<P><HR><P>
Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_42.html">previous</A>, <A HREF="ProgrammersManual_44.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>.
</BODY>
</HTML>