Code archives/Algorithms/Min Max

This code has been declared by its author to be Public Domain code.

Download source code

Min Max by Diego2
(Posted 20 years ago)
Something simple but useful.

Edit:
I added a functions to process strings and the InRange function, which returns the value, if it's between min% and max% or otherwise min% or max% self. Maybe this is useful if you calculated some colors to draw and want to make sure, it's between 0 and 255. The Example would be:
InRange(0, MyColor%, 255)

- - - - -
Etwas einfaches aber nützliches.

Edit:
Ich habe Funktionen hinzugefügt um Strings zu verarbeiten und die InRange-Funktion, welche den Wert zurück gibt, wenn er zwischen min% und max% liegt oder im anderen Fall min% bzw. max% selbst. Vielleicht ist das nützlich, falls du Farben zum Zeichnen berechnet hastund du sicherstellen willst, dass sie zwischen 0 und 255 liegen. Das Beispiel dafür ist:
InRange(0, Farbe%, 255)
Function Min(Zahl1%, Zahl2%)
If Zahl1% < Zahl2% Then Return Zahl1% Else Return Zahl2%
End Function

Function MinFloat#(Zahl1#, Zahl2#)
If Zahl1# < Zahl2# Then Return Zahl1# Else Return Zahl2#
End Function

Function MinString$(String1$, String2$)
If String1$ < String2$ Then Return String1$ Else Return String2$
End Function

Function Max(Zahl1%, Zahl2%)
If Zahl1% > Zahl2% Then Return Zahl1% Else Return Zahl2%
End Function

Function MaxFloat#(Zahl1#, Zahl2#)
If Zahl1# > Zahl2# Then Return Zahl1# Else Return Zahl2#
End Function

Function MaxString$(String1$, String2$)
If String1$ > String2$ Then Return String1$ Else Return String2$
End Function

Function InRange(Min%, Value%, Max%)
If Value% < Min% Then Return Min%
If Value% > Max% Then Return Max%
Return Value%
End Function

Function InRangeFloat#(Min#, Value#, Max#)
If Value# < Min# Then Return Min#
If Value# > Max# Then Return Max#
Return Value#
End Function

Function InRangeString$(Min$, Value$, Max$)
If Value$ < Min$ Then Return Min$
If Value$ > Max$ Then Return Max$
Return Value$
End Function