Page 1 of 1
highest_value = Max ( value1, value2 [,value3...] )
Posted: Sun Apr 13, 2008 5:44 pm
by Joakim Christiansen
highest_value = Max ( value1, value2 [,value3...] )
With at least up to 16 values or infinitive if possible...
PHP has this function:
http://www.php.net/manual/en/function.max.php
Posted: Mon Apr 14, 2008 7:15 am
by Michael Vogel
I miss such a "norm" function, too. Every programmer does his own versions, but a standardized one would be cool!
I miss some of these tiny little helpers for integer math (Max, Min, Abs, Sgn etc.) and boolean logik (SetBit, ClrBit etc.)...
Michael
Posted: Mon Apr 14, 2008 1:43 pm
by Hroudtwolf
Hi,
Here is a solution.
Code: Select all
Procedure MaxLong ( *Array.LONG )
Protected *EOA = *Array + PeekL ( *Array - 8 ) * SizeOf ( LONG )
Protected lHighest.l = 0
While *Array < *EOA
If lHighest < *Array\l
lHighest = *Array\l
EndIf
*Array + SizeOf ( LONG )
Wend
ProcedureReturn lHighest
EndProcedure
Dim test.l ( 7 )
test.l ( 0 ) = 5
test.l ( 1 ) = 8
test.l ( 2 ) = 1
test.l ( 3 ) = 7
test.l ( 4 ) = 5
test.l ( 5 ) = 9
test.l ( 6 ) = 2
test.l ( 7 ) = 3
Debug MaxLong ( @ test () )
Best regards
Wolf
Posted: Mon Apr 14, 2008 2:34 pm
by IceSoft
@Wolf,
Using SortArray(test(), #PB_Sort_Descending) is easier
Code: Select all
Dim test.l ( 7 )
test.l ( 0 ) = 5
test.l ( 1 ) = 8
test.l ( 2 ) = 1
test.l ( 3 ) = 7
test.l ( 4 ) = 5
test.l ( 5 ) = 9
test.l ( 6 ) = 2
test.l ( 7 ) = 3
SortArray(test(), #PB_Sort_Descending)
Debug test (0)
Posted: Mon Apr 14, 2008 3:06 pm
by Hroudtwolf
But absolutly untricky and not nearly so fast ^^
Posted: Mon Apr 14, 2008 4:05 pm
by Derek
But you might not actually want the contents of the array sorted, just want to know what is the highest (or lowest) so both ways have their merits.

Posted: Mon Apr 14, 2008 7:20 pm
by IceSoft
Hroudtwolf wrote:But absolutly untricky and not nearly so fast ^^
Of course
