Table of Contents

Math Routines

Miscellaneous mathematical and low-level routines


  • func abs( object a )   Absolute value.
  • func get_bits( atom b32 )    Does the reverse of or_all() in that it gets all the bit values from an atom.
  • func hi_word( atom pData)    returns the high 16 bits of pData
  • func lo_word( atom pData)    returns the low-16 bits of pData
  • func or_all( object pData )    Calculates a binary OR against each element in pData
  • func pack_word( integer low, integer high )   Packs values into word.
  • func shortInt( atom a )   Converts a number into a 16-bit signed integer
  • func signed_word( atom a )    Converts a into a signed 16-bit integer.
  • func TextToNumber( sequence text )   This converts the text into a number.
  • func unpack_sWord( atom a )   Returns signed high and signed low portions of a 32-bit word.
  • func unpack_word( atom a )   Returns high and low portions of a 32-bit word.


    Table of Contents

    [func]
    abs
    ( object a )

    Absolute value.

    Returns: Absolute value of the atom or sequence.

    Category: Math Routines

    Example

           sequence s
           atom a
    

    a = abs(-1) -- = 1 s = abs({-2,-1,{-1,0,1},1,2}) -- = {2,1,{1,0,1},1,2}

    See Also: get_bits, hi_word, lo_word, or_all, pack_word, shortInt, signed_word, TextToNumber, unpack_sWord, unpack_word



    Table of Contents

    [func]
    get_bits
    ( atom b32 )

    Does the reverse of or_all() in that it gets all the bit values from an atom.

    Returns: Sequence: The non-zero bits set in b32.

    Category: Math Routines

    Typically used to extract which bits have been set on in a flag.

    Example:

    -- combine flags
    integer flags
    sequence codes
    codes = get_bits( origflag )
    if find(WS_EX_CLIENTEDGE, codes) then
    setText(statusarea, "Client Edge has been specified")
    end if
    

    See Also: abs, hi_word, lo_word, or_all, pack_word, shortInt, signed_word, TextToNumber, unpack_sWord, unpack_word



    Table of Contents

    [func]
    hi_word
    ( atom pData)

    returns the high 16 bits of pData

    Returns: INTEGER: Bits 31-16 of the parameter as a 16 bit value.

    Category: Math Routines

    Example:

    integer y
    y = hi_word( bigval )
    

    See Also: abs, get_bits, lo_word, or_all, pack_word, shortInt, signed_word, TextToNumber, unpack_sWord, unpack_word



    Table of Contents

    [func]
    lo_word
    ( atom pData)

    returns the low-16 bits of pData

    Returns: INTEGER: Bits 15-0 of the parameter

    Category: Math Routines

    Example:

    integer y
    y = lo_word( bigval )
    

    See Also: abs, get_bits, hi_word, or_all, pack_word, shortInt, signed_word, TextToNumber, unpack_sWord, unpack_word



    Table of Contents

    [func]
    or_all
    ( object pData )

    Calculates a binary OR against each element in pData

    Returns: ATOM: The OR'd value

    Category: Math Routines

    example:

          atom flags
          flags = or_all({WS_CHILD, WS_VISIBLE, WS_BORDER})
    

    See Also: abs, get_bits, hi_word, lo_word, pack_word, shortInt, signed_word, TextToNumber, unpack_sWord, unpack_word



    Table of Contents

    [func]
    pack_word
    ( integer low, integer high )

    Packs values into word.

    Returns: ATOM: 32 bit word with low value in low 16 bits, high value in high 16 bits.

    Category: Math Routines

    Typically used to encode a message parameter into a 32 bit word.

    Example:

    -- pack min and max into parameter
    integer y
    lParam = pack_word( min, max )
    

    See Also: abs, get_bits, hi_word, lo_word, or_all, shortInt, signed_word, TextToNumber, unpack_sWord, unpack_word



    Table of Contents

    [func]
    shortInt
    ( atom a )

    Converts a number into a 16-bit signed integer

    Returns: INTEGER: The value of a as a short int.

    Category: Math Routines

    Typically used to decode Win32 message values

    Example:

    -- Mouse Position
    sequence hilo, x, y
    hilo = upack_word( lParam )
    x = shortInt(hilo[2])
    y = shortInt(hilo[1])
    

    See Also: abs, get_bits, hi_word, lo_word, or_all, pack_word, signed_word, TextToNumber, unpack_sWord, unpack_word



    Table of Contents

    [func]
    signed_word
    ( atom a )

    Converts a into a signed 16-bit integer.

    Returns: INTEGER: Signed 16 bits of a 32 bit word.

    Category: Math Routines

    Typically used to decode Win32 message values when several values are packed into a single number.

    Example:

    -- extract the low portion from lParam
    integer x
    x = signed_word( lParam )
    

    See Also: abs, get_bits, hi_word, lo_word, or_all, pack_word, shortInt, TextToNumber, unpack_sWord, unpack_word



    Table of Contents

    [func]
    TextToNumber
    ( sequence text )

    This converts the text into a number.

    Returns: Atom: The number represented by the text.

    Category: Math Routines

    If the text contains invalid characters, zero is returned.

    Note 1: You can supply Hexadecimal values if the value is preceded by a '#' character, Octal values if the value is preceded by a '@' character, and Binary values if the value is preceded by a '!' character. With hexadecimal values, the case of the digits 'A' - 'F' is not important. Also, any period character embedded in the number is used with the correct base.

    Note 2: Any underscore characters, '_', that are embedded in the text number are ignored. These can be used to help visual clarity for long numbers.

    Note 3: You can supply a leading or trailing, minus or plus sign.

    Note 4: You can supply trailing percentage sign(s). Each one present causes the resulting value to be divided by 100.

    This function can optionally return information about invalid numbers. If text has the form of {sequence, integer} then if the integer is nonzero, a sequence is returned. The first element is the value converted, and the second is the position in the text where conversion stopped. If no errors were found then this is zero.

         sequence rc
         atom   val
         rc = TextToNumber({"12.34a", 1})
         --  rc ---> {12.34, 6} -- Error at position 6
         rc = TextToNumber({"12.34", 1})
         --  rc ---> {12.34, 0} -- No errors.
    

    val = TextToNumber("12.34a") -- val ---> 0

    val = TextToNumber("#f80c") --> 63500 val = TextToNumber("#f80c.7aa") --> 63500.47900390625 val = TextToNumber("@1703") --> 963 val = TextToNumber("!101101") --> 45 val = TextToNumber("12_583_891") --> 12583891 val = TextToNumber("12_583_891%") --> 125838.91 val = TextToNumber("12_583_891%%") --> 1258.3891

    See Also: abs, get_bits, hi_word, lo_word, or_all, pack_word, shortInt, signed_word, unpack_sWord, unpack_word



    Table of Contents

    [func]
    unpack_sWord
    ( atom a )

    Returns signed high and signed low portions of a 32-bit word.

    Returns: SEQUENCE: {High signed 16 bits,Low signed 16 bits}

    Category: Math Routines

    Typically used to decode Win32 message values when several values are packed into a single number.

    Example:

    -- extract the signed words from lParam
    sequence hilo
    hilo = upack_sWord( lParam )
    

    See Also: abs, get_bits, hi_word, lo_word, or_all, pack_word, shortInt, signed_word, TextToNumber, unpack_word



    Table of Contents

    [func]
    unpack_word
    ( atom a )

    Returns high and low portions of a 32-bit word.

    Returns: SEQUENCE: {High 16 bits,Low 16 bits}

    Category: Math Routines

    Typically used to decode Win32 message values when several values are packed into a single number.

    Example:

    -- extract the short words from lParam
    sequence hilo
    hilo = upack_word( lParam )
    

    See Also: abs, get_bits, hi_word, lo_word, or_all, pack_word, shortInt, signed_word, TextToNumber, unpack_sWord