sum - return sum of variable values

SYNOPSIS

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


DESCRIPTION
The sum function sums its $var arguments' values - either arithmetically or via string concatenation. The $fmt argument is a <fmt>-style format string that controls how the values are summed, as well as how each value is processed before summing. If $fmt is a string format code (e.g. "%s"), each $var value is printed to a string with $fmt, and the results string-concatenated for a string (varchar) result. If $fmt is a numeric code (e.g. "%d" or "%f"), each $var value is cast to the type indicated by the code (with all integer types promoted to int64), and the results arithmetically summed, for a numeric result of the same type.


DIAGNOSTICS
sum returns the arithmetic sum or string concatenation of its $var arguments, depending on the $fmt code.


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

The sum function is implemented as a user function, so its arguments are converted to strings by Vortex (perhaps via Texis SQL type conversion) before it starts. Thus, some floating point arguments may lose precision.


SEE ALSO
fmt strfmt


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.