highest_value = Max ( value1, value2 [,value3...] )

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

highest_value = Max ( value1, value2 [,value3...] )

Post 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
I like logic, hence I dislike humans but love computers.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post 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
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post 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
User avatar
IceSoft
Addict
Addict
Posts: 1683
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Post 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)
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

But absolutly untricky and not nearly so fast ^^
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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. :)
User avatar
IceSoft
Addict
Addict
Posts: 1683
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Post by IceSoft »

Hroudtwolf wrote:But absolutly untricky and not nearly so fast ^^
Of course ;-)
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Post Reply