|
|
Section Intro: Arithmetic Operators
Arithmetic OperatorsSynopsis:Meta-HTML contains a small set of commands for operating on numerical quantities.
All of the arithmetic operators described in this section can accept a
number, or simply the name of a variable, which is then looked up as
if it had been written with That is to say:
<set-var total = <add <get-var-once subtotals[0]>
<get-var-once subtotals[current]>>>
can be written as:
<set-var total = <add subtotals[0] subtotals[current]>>
Commands: Variables: More Information:
The binary arithmetic operators always expect two arguments, and will
produce a warning message in You can perform floating point arithmetic if one or both of the arguments is already a floating point number:
<div 10 3> ==> 3 <div 10.0 3> ==> 3.33
Return the arc cosine of X.
Return the inverse hyperbolic cosine of X.
Returns the summation of all of the arguments passed. Examples: <add 1 2> ==> 3 <add -1 2 2 1> ==> 4
Return the arc sin of X.
Return the inverse hyperbolic sine of X.
Return the arc tangent of X. If Y is supplied, then this returns the arg tangent of Y/X, using the signs of both arguments to determine the quadrant of the result.
Return the inverse hyperbolic tangent of X.
Returns the average of all of the arguments passed. Examples: <avg 3 4 5> ==> 4 <avg 4 9 3.2> ==> 5.40
Return the cube root of X.
Round X upwards to the nearest integer.
Produce NUM in standard human readable format, inserting commas where appropriate. Example: <comma-separated-digits 98342367.09>produces: 98,342,367.09
Return the cosine of X.
Return the hyperbolic cosine of X, i.e., (exp ( X) + exp ( -X)) / 2.
Returns the quotient of all of the arguments passed. Examples: <div 100 5> ==> 20 <div 5 100> ==> 0 <div 5.0 100.0> ==> 0.05 <div 100 5 2> ==> 10
Returns "true" if the numeric value of ARG1 is exactly equal to
the numeric value of ARG2. Just as with the arithmetic
functions (Arithmetic Operators), the arguments
may be the names of variables containing numeric values, and not just
the values themselves. In that case, Examples: <eq 3 4> ==> <eq 3 3> ==> true <eq 3.0 3> ==> true <set-var x=3.01> <eq <get-var-once x> 3.01> ==> true
Return the value of e (the base of natural logarithms), raised to the power of X.
Computes the factorial of X. Example: <factorial 12>produces: 479001600.00
Returns the floating point representation of X. X may be an integer, a floating point number, or a variable containing an integer or floating point number. <set-var foo=7> <float foo> <float 3> <float 3.0>produces: 7.00 3.00 3.00
Round X downwards to the nearest integer.
Returns "true" if the numeric value of ARG1 is greater than or equal to numeric value of ARG2 (which is greater than or equal to MORE-ARGS.
Just as with the arithmetic functions (Arithmetic Operators),
the arguments may be the names of variables containing numeric values,
and not just the values themselves. In that case, Examples: <ge 4 3> ==> true <set-var x=3.4 y=3.5> <ge x y> ==> <ge y x> ==> true <ge <get-var-once y> x> ==> true <ge 3 2 3.0> ==> true <ge 3 2 3> ==> <ge 3 3 2> ==> true
Returns "true" if the numeric value of ARG1 is greater than
the numeric value of ARG2 (which is greater than MORE-ARGS. Just as with the arithmetic functions (Arithmetic Operators), the arguments may be the names of
variables containing numeric values, and not just the values
themselves. In that case, Examples: <gt 4 3> ==> true <set-var x=3.4 y=3.5> <gt x y> ==> <gt y x> ==> true <gt <get-var-once y> x> ==> true <p> <defun between? item high low> <gt high item low> </defun> <p> <between? 7 8 6> ==> true
Returns the integer representation of NUM. <integer 3.45> is less than <integer 3.54>produces: 3 is less than 4
Returns "true" if STRING is the string representation of an integer
value in base BASE (default You call this function with the actual value -- you may not pass the name of a variable instead. Some examples: <set-var x=123> <integer? -90> ==> true <integer? <get-var-once x>> ==> true <integer? 2.3> ==> <integer? FEFE base=16> ==> true <integer? 874 base=8> ==>
Returns "true" if the numeric value of ARG1 is less than or equal to the numeric value of ARG2 (which is less than or equal to MORE-ARGS.
Just as with the arithmetic functions (Arithmetic Operators),
ARG1 and ARG2 may be the names of variables containing
numeric values, and not just the values themselves. In that case,
Examples: <le 3 4> ==> true <le 4 3> ==> <set-var x=3.4 y=3.5> <le x y> ==> true <le x 3.4 y> ==> true <le x y 3.4> ==> <le 4 5 6> ==> true
Return the natural logarithm of X.
Return the base-10 logarithm of X.
Return the base-2 logarithm of X.
Returns "true" if the numeric value of ARG1 is less than
the numeric value of ARG2 (which is less than MORE-ARGS.
Just as with the arithmetic functions (Arithmetic Operators),
ARG1 and ARG2 may be the names of variables containing
numeric values, and not just the values themselves. In that case,
Examples: <lt 3 4> ==> true <lt 4 3> ==> <set-var x=3.4 y=3.5> <lt x y> ==> true <lt y x> ==> <lt x <get-var-once y>> ==> true <lt 4 5 6> ==> true
Returns the largets of all of the arguments passed. Examples: <max 2 2> ==> 2 <max 2.3 8 7> ==> 8.00 <max 4 10 -4> ==> 10
Returns the median of all of the arguments passed. The median is defined as the number for which half of the rest of the numbers is greater, and half of the rest of the numbers is less. Example: <med 3 4 5> ==> 4 <med 2 3 7 8 10> ==> 5.40
Returns the smallest of all of the arguments passed. Examples: <min 2 2> ==> 2 <min 2.3 8 3> ==> 2.30 <min 3 -4 10> ==> -4
Returns the remainder of all of the arguments passed. Examples: <mod 100 10> ==> 0 <mod 101 10> ==> 1 <mod 89 9 3> ==> 2
Returns the product of all of the arguments passed. Examples: <mul 2 2> ==> 4 <mul 2.3 8 3> ==> 55.20 <mul -4 10> ==> -40
Returns "true" if the numeric value of ARG1 is NOT equal to
the numeric value of ARG2. Just as with the arithmetic
functions (Arithmetic Operators), the arguments
may be the names of variables containing numeric values, and not just
the values themselves. In that case, Examples: <neq 3 4> ==> true <neq 3 3> ==> <neq 3.0 3> ==> <set-var x=3.01> <neq <get-var-once x> 3.00> ==> true
Returns "true" if ARG is the string representation of an integer
in base BASE (default
For integer checks, the special value of zero ( <number? <get-var x> base=0>is equivalent to: <or <integer? <get-var x> base=8>
<integer? <get-var x> base=10>
<integer? <get-var x> base=16>
<real? <get-var x>>>
Some examples: <number? 10> ==> true <number? .9> ==> true <number 0xEF base=16> ==> true
Returns DIGITS digits of the numerical quantity PI, up to a limit of 1,000 decimal places. DIGITS defaults to 4.
Returns X raised to the Y power.
Returns a pseudo-random number between 0 and ARG -1. The
distribution is pretty good; calling Examples: <random 100> ==> 87 <random 100> ==> 44 <p> <b>I'm thinking of a number between 1 and 10:</b> <set-var guess = <add 1 <random 10>>>
Also see
Sets the pseudo-random number generator seed to SEED. The next
call to Examples: <randomize 10> <random 100> ==> 28 <random 100> ==> 15 <randomize 10> <random 100> ==> 28
Returns "true" if STRING is the string representation of a real number.Useful for checking the validity of user input to a form. You call this function with the actual value -- you may not pass the name of a variable instead. Some examples: <set-var pi=3.141569> <real? <get-var-once pi>> ==> true <real? 45> ==> <real? 2.3> ==> true <real? "This"> ==> <real? -.087e4> ==> true
Round X to the nearest integer.
Set the output radix for numbers produced by arithmetic operations to NEW-RADIX, which is specified in decimal. Returns the value of the previous output radix. Note that there is no corresponding function for setting the input radix. If the value of NEW-RADIX is a number between 2 and 32 decimal, inclusive, then the output radix is set to that value. NEW-RADIX can also be the name of a function of one argument, which should be called to produce the appropriate output. If the argument to <set-output-radix> does not fall between 2 and 32 inclusive, and is not the name of a defined function, then the output radix remains unchanged, and <set-output-radix> produces no output. Examples: <set-output-radix 16> ==> 10 <add 0x3e 1> ==> 0x3f <set-output-radix 10> ==> 16 <set-output-radix number-to-english> ==> 10 <add 23.4 32.32> ==> Fifty-Five point Seven Two
Return the sin of X.
Return the hyperbolic sine of X, i.e. (exp( X) - exp( -X) / 2.
Return the sqaure root of X.
Returns the difference of all of the arguments passed. Examples: <sub 2 1> ==> 1 <sub 6 2 1> ==> 3 <sub -1 -2> ==> 1
Return the tangent of X.
Return the hyperbolic tangent of X, i.e. sinh( X) / cosh( X).
Edit Section
![]() The META-HTML Reference Manual V2.0 Copyright © 1995, 1998, Brian J. Fox Found a bug? Send mail to bug-manual@metahtml.org |