THE META-HTML LANGUAGE REFERENCE MANUAL

Flow Control [TOC] Relational Operators

Section Intro: Arithmetic Operators

Arithmetic Operators

Synopsis:

    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 <get-var-once ...>.

    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 DEBUGGING-OUTPUT when given too few arguments.

    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

<acos XSimple

    Return the arc cosine of X.

<acosh XSimple

    Return the inverse hyperbolic cosine of X.

<add ARG1 ARG2 &rest more-args>Simple

    Returns the summation of all of the arguments passed.

    Examples:

    <add 1 2>        ==> 3
    <add -1 2 2 1>   ==> 4

<asin XSimple

    Return the arc sin of X.

<asinh XSimple

    Return the inverse hyperbolic sine of X.

<atan X &optional [Y]Simple

    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.

<atanh XSimple

    Return the inverse hyperbolic tangent of X.

<avg &rest nums[]>Simple

    Returns the average of all of the arguments passed. Examples:

     <avg 3 4 5>    ==> 4
     <avg 4 9 3.2>  ==> 5.40
     

<cbrt XSimple

    Return the cube root of X.

<ceiling XSimple

    Round X upwards to the nearest integer.

<comma-separated-digits NUMSimple

    Produce NUM in standard human readable format, inserting commas where appropriate.

    Example:

     <comma-separated-digits 98342367.09>
     
    produces:
    98,342,367.09
     

<cos XSimple

    Return the cosine of X.

<cosh XSimple

    Return the hyperbolic cosine of X, i.e., (exp ( X) + exp ( -X)) / 2.

<div ARG1 ARG2 &rest more-args>Simple

    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

<eq ARG1 ARG2Simple

    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, eq performs an implicit call to <get-var-once ...> in order to get the value to operate on.

    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

<exp XSimple

    Return the value of e (the base of natural logarithms), raised to the power of X.

<factorial XSimple

    Computes the factorial of X. Example:

     <factorial 12>
     
    produces:
    479001600.00
     

<floatSimple

    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
     

<floor XSimple

    Round X downwards to the nearest integer.

<ge ARG1 ARG2 &rest more-args...>Simple

    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, gt performs an implicit call to <get-var-once ...> in order to get the value to operate on.

    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

<gt ARG1 ARG2 &rest more-args...>Simple

    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, gt performs an implicit call to <get-var-once ...> in order to get the value to operate on.

    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

<integer NUMSimple

    Returns the integer representation of NUM.

    <integer 3.45> is less than <integer 3.54>
    produces:
    3 is less than 4

<integer? STRING &key [BASE[=10]]Simple

    Returns "true" if STRING is the string representation of an integer value in base BASE (default 10). This function is 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 x=123>
    <integer? -90>          ==> true
    <integer? <get-var-once x>>  ==> true
    <integer? 2.3>          ==>
    <integer? FEFE base=16> ==> true
    <integer? 874 base=8>   ==>

<le ARG1 ARG2 &rest more-args>Simple

    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, lt performs an implicit call to <get-var-once ...> in order to get the value to operate on.

    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

<log XSimple

    Return the natural logarithm of X.

<log10 XSimple

    Return the base-10 logarithm of X.

<logb XSimple

    Return the base-2 logarithm of X.

<lt ARG1 ARG2 &rest more-args>Simple

    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, lt performs an implicit call to <get-var-once ...> in order to get the value to operate on.

    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

<max ARG1 ARG2 &rest more-args>Simple

    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

<med &rest nums[]>Simple

    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
     

<min ARG1 ARG2 &rest more-args>Simple

    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

<mod ARG1 ARG2 &rest more-args>Simple

    Returns the remainder of all of the arguments passed.

    Examples:

    <mod 100 10>    ==> 0
    <mod 101 10>    ==> 1
    <mod 89 9 3>    ==> 2

<mul ARG1 ARG2 &rest more-args>Simple

    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

<neq ARG1 ARG2Simple

    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, eq performs an implicit call to <get-var-once ...> in order to get the value to operate on.

    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

<number? ARG &key [BASE]Simple

    Returns "true" if ARG is the string representation of an integer in base BASE (default 10), or the string representation of a floating point number in base 10.

    For integer checks, the special value of zero (0) for BASE allows the common radixes of decimal, octal, and hexadecimal to be understood. That is to say:

     <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
     

<pi &optional [DIGITS]Simple

    Returns DIGITS digits of the numerical quantity PI, up to a limit of 1,000 decimal places. DIGITS defaults to 4.

<raise X YSimple

    Returns X raised to the Y power.

<random ARGSimple

    Returns a pseudo-random number between 0 and ARG -1. The distribution is pretty good; calling <random 2> returns 0 50% of the time, and 1 the other 50%.

    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 randomize.

<randomize &optional [SEED]Simple

    Sets the pseudo-random number generator seed to SEED. The next call to random uses this seed value to find the next pseudo-random number. There is no return value.

    Examples:

      <randomize 10>
      <random 100> ==> 28
      <random 100> ==> 15
      <randomize 10>
      <random 100> ==> 28

<real? STRINGSimple

    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 XSimple

    Round X to the nearest integer.

<set-output-radix NEW-RADIXSimple

    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

<sin XSimple

    Return the sin of X.

<sinh XSimple

    Return the hyperbolic sine of X, i.e. (exp( X) - exp( -X) / 2.

<sqrt XSimple

    Return the sqaure root of X.

<sub ARG1 ARG2 &rest more-args>Simple

    Returns the difference of all of the arguments passed.

    Examples:

    <sub 2 1>        ==> 1
    <sub 6 2 1>      ==> 3
    <sub -1 -2>      ==> 1

<tan XSimple

    Return the tangent of X.

<tanh XSimple

    Return the hyperbolic tangent of X, i.e. sinh( X) / cosh( X).

Edit Section
Function Index
Variable Index


The META-HTML Reference Manual V2.0 Copyright © 1995, 1998, Brian J. Fox
Found a bug? Send mail to bug-manual@metahtml.org