TIP: | 255 |
Title: | Add 'min' and 'max' [expr] Functions |
Version: | $Revision: 1.6 $ |
Author: | Jeff Hobbs <jeffh at activestate dot com> |
State: | Final |
Type: | Project |
Tcl-Version: | 8.5 |
Vote: | Done |
Created: | Thursday, 21 July 2005 |
This TIP proposes enhancing the Tcl expr command with min and max functions.
Many programs need to find the minimum or maximum of a set of numbers, so having functions to do this will make many script programmers' lives easier. This will be adopting yet another feature from TclX, but with the minor enhancement of being able to handle arbitrary numbers of arguments.
The min and max functions shall be created using Tcl commands (in a namespace such all namespaces will pick them up by default) in the new 8.5 expr function style (see TIP #232). They will take one or more numeric arguments (of any valid numeric type) and return the minimum or maximum value of those numbers (depending on which function was invoked).
expr {min(0,3,1)} => 0 expr {max(4.2, 0xF, wide(1))} => 15.0 expr {min(4.2)} => 4.2 expr {min()} => too few arguments for math function
[To be uploaded to SourceForge and URL added to this TIP.]
This document has been placed in the public domain.
[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]