ph_sumnum PowerHome formula function
Description
This function will take a string of numerics
and perform one of several summations on
them.
Syntax
ph_sumnum ( data, numtype, sumtype
)
Argument |
Description |
data |
String. The string containing the numbers to sum. Numbers
should be separated using commas, spaces, or some other non-numeric
character (the "-" sign is reserved to indicate a negative number). |
numtype |
Integer. The type of numbers contained in the data
parameter. Use 0 for standard whole numbers. Use 1 for numbers that
contain a decimal point. Use 2 for hexadecimal numbers. |
sumtype
|
Integer. The type of summation to
perform. Use 0 to have the individual numbers added together. Use 1 to
return the average of the numbers. Use 2 to return a checksum of
the numbers.
|
Return value
Double. Returns the result of the specified
summation. Returns 0 if the numtype or sumtype are
invalid values.
Usage
Use this function to quickly add a string of
delimited numbers or return their average. The checksum option uses the same
technique specified for Insteon I2CS operations. The checksum operation is
defined as: ph_and(ph_xor(ph_and(d_sum,255),255) + 1,255) where d_sum is the
total of individual numbers
added together.
Examples
The following examples demonstrate typical syntax/usage for this function.
ph_sumnum("A5 19 2E 45 AA BB 34 1A
2D",2,2)
The above example will add the hexadecimal numbers in the data
parameter and then perform the I2CS checksum operation. The result returned will
be
239.