Tech Tip: Utility to get minimum value given a set of values
PRODUCT: 4D | VERSION: 15.1 | PLATFORM: Mac & Win
Published On: September 2, 2016
The 4D command MIN returns the minimum value given a series (field or array). Below is an utility method that returns the minimum of the given values (passed in as parameters).
// Method: UTIL_MIN // Return minimum of given values // Parameters: // {$1} - values // $0 - minimum of the values C_REAL(${1}) C_REAL($0;$min) C_LONGINT($paramLen;$i) $paramLen:=Count parameters If ($paramLen>=1) $min:=$1 For ($i;2;$paramLen) If ($min>${$i}) $min:=${$i} End if End for End if $0:=$min |
Example:
Below is an example of getting the minumum values:
C_REAL($min) $min:=UTIL_MIN(44.3;34.01;546;0x234;-1.3;-0.4) |
The method will return a real. If a longint is necessary, type $min as a longint:
C_LONGINT($min) $min:=UTIL_MIN(44.3;34.01;546;0x234;-1.3;-0.4) |
Commented by Timothy Tse on September 7, 2016 at 2:39 PM
Hi Benoit,
There was an error in the code. The error has now been fixed.
Commented by Benoît BRIERE on September 5, 2016 at 2:48 AM
I can even say that $min will always be <=0…