• My Pages
  • Comments
  • Add Link
  • Subscribe
  • Subscribe User
  • Edit (GUI)
  • Edit (Text)
  • Rename Page
  • Copy Page
  • Load Page
  • Save Page
  • Delete Page
  • Attachments
  • Check Spelling
  • Diffs
  • Info
  • Revert to this revision
  • XML
  • Render as Docbook
  • Print View
  • Raw Text
  • Delete Cache
  • Like Pages
  • Local Site Map
  • Remove Spam
  • Package Pages
  • Sync Pages
    • Diff for "Math"
    Differences between revisions 5 and 7 (spanning 2 versions)
    Revision 5 as of 2012-12-04 18:33:00
    Size: 5160
    Editor: Inanna
    Comment:
    Revision 7 as of 2013-07-31 04:27:55
    Size: 6220
    Editor: tech
    Comment:
    Deletions are marked like this. Additions are marked like this.
    Line 31: Line 31:


    Line 32: Line 35:
    '''Usage:'''  '''Usage:'''
    Line 37: Line 40:
     .

    '''Result:'''

    echo abs(-123456)

    echo abs(123456)

    '''Result:<<BR>>'''

    123456

    123456
    Line 43: Line 54:
    '''Usage:'''  '''Usage:'''
    Line 48: Line 59:
     .

    '''Result:'''

    .

    '''Result:'''
    Line 54: Line 67:
    '''Usage:'''  '''Usage:'''
    Line 59: Line 72:
     .

    '''Result:'''

    .

    '''Result:'''
    Line 65: Line 80:
    '''Usage:'''  '''Usage:'''
    Line 70: Line 85:
     .

    '''Result:'''

    .

    '''Result:'''
    Line 76: Line 93:
    '''Usage:'''  '''Usage:'''
    Line 81: Line 98:
     .

    '''Result:'''

    .

    '''Result:'''
    Line 87: Line 106:
    '''Usage:''' 

    Returns the ceiling of the specified number or expression.

    '''Example:'''
     
    .

    '''Result:'''
     .
    '''Usage:'''

    Returns the ceiling of the specified number or expression. Basically this means return the number rounded up to next whole number

    '''Example:<<BR>><<BR>>'''echo ceil(4.1)

     .


    '''Result:'''

    5
    Line 98: Line 119:
    '''Usage:'''  '''Usage:'''
    Line 103: Line 124:
     .

    '''Result:'''

    .

    '''Result:'''
    Line 109: Line 132:
    '''Usage:'''  '''Usage:'''
    Line 114: Line 137:
     .

    '''Result:'''

    .

    '''Result:'''
    Line 120: Line 145:
    '''Usage:''' 

    Returns the floor of the number or expression specified in the parameter val.

    '''Example:'''
     .

    '''Result:'''
    '''Usage:'''

    Returns the floor of the number or expression specified in the paraenthesis... Floor is the whole number part, without the decimals. Basically means chop the decimal portion of the number off.

    '''Example:  echo floor(1234.56)'''

     .

    '''Result: 1234'''
    Line 131: Line 158:
    '''Usage:'''  '''Usage:'''
    Line 136: Line 163:
     .

    '''Result:'''

    .

    '''Result:'''
    Line 142: Line 171:
    '''Usage:'''  '''Usage:'''
    Line 147: Line 176:
     .

    '''Result:'''

    echo max( city.troop.scouter, 100k )

    '''Result:'''

    If city.troop.scouter (the current number of scouts in the city) < 100k, then max( city.troop.scouter, 100k ) will return the number of scouts in city. If city.troop.scouter >= 100k then it will return 100000
    Line 153: Line 186:
    '''Usage:'''  '''Usage:'''
    Line 158: Line 191:
     .

    '''Result:'''

    echo min(city.resource.food.amount,99999999)

     .

    '''Result:<<BR>><<BR>>'''this will return whichever is smaller, 99,999,999 or the current amount of food in the city
    Line 164: Line 201:
    '''Usage:'''  '''Usage:'''
    Line 169: Line 206:
     .

    '''Result:'''

    .

    '''Result:'''
    Line 175: Line 214:
    '''Usage:'''  '''Usage:'''
    Line 179: Line 218:
    '''Example:'''
     .

    '''Result:'''
    '''Example:<<BR>><<BR>>'''

    echo round(random*10)

     .

    '''Result:'''

    a random number between 0 and 9
    Line 186: Line 231:
    '''Usage:''' 

    Rounds the value of the parameter val up or down to the nearest integer and returns the value.

    '''Example:'''
     .

    '''Result:'''
     .
    '''Usage:'''

    Rounds the value of the parameter val up or down to the nearest integer and returns the value. Optional argument to specify precision (or number of decimal places).

    '''Example:'''

    echo round(6.66666666666666666666) echo round(6.66666666666666666666,1) echo round(6.66666666666666666666,2) echo round(6.66666666666666666666,3)

    .

    '''Result:'''

    7 6.7 6.67 6.667
    Line 197: Line 246:
    '''Usage:'''  '''Usage:'''
    Line 202: Line 251:
     .

    '''Result:'''

    .

    '''Result:'''
    Line 208: Line 259:
    '''Usage:'''  '''Usage:'''
    Line 213: Line 264:
     .

    '''Result:'''

    .

    '''Result:'''
    Line 219: Line 272:
    '''Usage:'''  '''Usage:'''
    Line 224: Line 277:
     .

    '''Result:'''

    .

    '''Result:'''

    The following functions can be used to perform arithmetic on objects and variables.

    These should be written in the following formats:

    • variable.method(arguments), example - ...

    • object.method(arguments), example - ...

    Click each method name in the table below for more details of it, with examples.

    Methods

    Method

    Type

    Description

    abs

    int

    Computes and returns an absolute value for the number specified by the parameter val.

    acos

    int

    Computes and returns the arc cosine of the number specified in the parameter val, in radians.

    asin

    int

    Computes and returns the arc sine for the number specified in the parameter val, in radians.

    atan

    int

    Computes and returns the value, in radians, of the angle whose tangent is specified in the parameter val.

    atan2

    int

    Computes and returns the angle of the point y/x in radians, when measured counterclockwise from a circle's x axis (where 0,0 represents the center of the circle).

    ceil

    int

    Returns the ceiling of the specified number or expression.

    cos

    int

    Computes and returns the cosine of the specified angle in radians.

    exp

    int

    Returns the value of the base of the natural logarithm (e), to the power of the exponent specified in the parameter x.

    floor

    int

    Returns the floor of the number or expression specified in the parameter val.

    log

    int

    Returns the natural logarithm of the parameter val.

    max

    int

    Evaluates val1 and val2 (or more values) and returns the largest value.

    min

    int

    Evaluates val1 and val2 (or more values) and returns the smallest value.

    pow

    int

    Computes and returns base to the power of pow.

    random

    int

    Returns a pseudo-random number n, where 0 <= n < 1.

    round

    int

    Rounds the value of the parameter val up or down to the nearest integer and returns the value.

    sin

    int

    Computes and returns the sine of the specified angle in radians.

    sqrt

    int

    Computes and returns the square root of the specified number.

    tan

    int

    Computes and returns the tangent of the specified angle.

    abs

    Usage:

    Computes and returns an absolute value for the number specified by the parameter val.

    Example:

    echo abs(-123456)

    echo abs(123456)

    Result:<<BR>>

    123456

    123456

    acos

    Usage:

    Computes and returns the arc cosine of the number specified in the parameter val, in radians.

    Example:

    Result:

    asin

    Usage:

    Computes and returns the arc sine for the number specified in the parameter val, in radians.

    Example:

    Result:

    atan

    Usage:

    Computes and returns the value, in radians, of the angle whose tangent is specified in the parameter val.

    Example:

    Result:

    atan2

    Usage:

    Returns a string comprising the characters represented by the Unicode character codes in the parameters.

    Example:

    Result:

    ceil

    Usage:

    Returns the ceiling of the specified number or expression. Basically this means return the number rounded up to next whole number

    Example:<<BR>><<BR>>echo ceil(4.1)

    Result:

    5

    cos

    Usage:

    Computes and returns the cosine of the specified angle in radians.

    Example:

    Result:

    exp

    Usage:

    Returns the value of the base of the natural logarithm (e), to the power of the exponent specified in the parameter x.

    Example:

    Result:

    floor

    Usage:

    Returns the floor of the number or expression specified in the paraenthesis... Floor is the whole number part, without the decimals. Basically means chop the decimal portion of the number off.

    Example: echo floor(1234.56)

    Result: 1234

    log

    Usage:

    Returns the natural logarithm of the parameter val.

    Example:

    Result:

    max

    Usage:

    Evaluates val1 and val2 (or more values) and returns the largest value.

    Example:

    echo max( city.troop.scouter, 100k )

    Result:

    If city.troop.scouter (the current number of scouts in the city) < 100k, then max( city.troop.scouter, 100k ) will return the number of scouts in city. If city.troop.scouter >= 100k then it will return 100000

    min

    Usage:

    Evaluates val1 and val2 (or more values) and returns the smallest value.

    Example:

    echo min(city.resource.food.amount,99999999)

    Result:<<BR>><<BR>>this will return whichever is smaller, 99,999,999 or the current amount of food in the city

    pow

    Usage:

    Computes and returns base to the power of pow.

    Example:

    Result:

    random

    Usage:

    Returns a pseudo-random number n, where 0 <= n < 1.

    Example:<<BR>><<BR>>

    echo round(random*10)

    Result:

    a random number between 0 and 9

    round

    Usage:

    Rounds the value of the parameter val up or down to the nearest integer and returns the value. Optional argument to specify precision (or number of decimal places).

    Example:

    echo round(6.66666666666666666666) echo round(6.66666666666666666666,1) echo round(6.66666666666666666666,2) echo round(6.66666666666666666666,3)

    Result:

    7 6.7 6.67 6.667

    sin

    Usage:

    Computes and returns the sine of the specified angle in radians.

    Example:

    Result:

    sqrt

    Usage:

    Computes and returns the square root of the specified number.

    Example:

    Result:

    tan

    Usage:

    Computes and returns the tangent of the specified angle.

    Example:

    Result:


    ScriptSyntax

    Math (last edited 2015-02-13 20:59:39 by LKD70)