Thunderstone Software Document Search, Retrieval, and Management
Search:
Vortex Manual
 

sum - return sum of variable values

 

SYNOPSIS

<sum $fmt $var [$var ...]>


DESCRIPTION
The sum function numerically sums the $var arguments' values. The result is then cast to the type implied by the $fmt argument, which is a fmt format string for one numeric argument. If $fmt is empty, "%g" is assumed.

The $fmt format can be any numerical format supported by the <fmt> function (here), with some implicit size casts. For example, "%d" would return an int64 (long in version 5 and earlier), truncated if needed; "%1.2f" would return a double value. If an integer $fmt format is used, an integer sum is attempted, otherwise a double-precision floating-point sum is used.

If one or more of the values of any of the $var arguments are non-numeric, the function returns the string concatenation of the $var values instead. In this case, each value (not the result) is first formatted with the $fmt argument. If $fmt is empty, "%s" is assumed.


DIAGNOSTICS
If all $var arguments are numeric, sum numerically sums them, and then formats and casts the result using the $fmt argument. If any $var arguments are non-numeric, each argument is formatted with the $fmt argument, and their string concatenation is returned.


EXAMPLE

<$x = 1 2 3>
<sum "%d" $x 4>
$ret
<sum "%10s" "one" "two" "three">
$ret

The output would be (note spacing):

10
       one       two     three


CAVEATS
The sum function was added Sep. 20 1996. In versions prior to Nov 25 1996, the $fmt argument was ignored when concatenating strings.

The $fmt argument should be appropriate for the values' type (numeric or string).


SEE ALSO
fmt strfmt


Copyright © Thunderstone Software     Last updated: Thu Dec 22 15:13:31 EST 2011
 
Home   ::   Products   ::   Solutions   ::   How to Buy   ::   Support   ::   Contact Us   ::   News   ::   About
Copyright © 2012 Thunderstone Software LLC. All rights reserved.