QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: johnno56 on September 22, 2021, 02:43:37 am

Title: min() and max()
Post by: johnno56 on September 22, 2021, 02:43:37 am
Does anyone know how to simulate the min() and max() function using QB64?

J
Title: Re: min() and max()
Post by: SMcNeill on September 22, 2021, 02:56:21 am
To find the min and max values of an array?


FUNCTION min (array() AS LONG) ‘or other type as needed
    min = array(LBOUND(array))
    FOR i = LBOUND(array) TO UBOUND(array)
        if min > array(i) THEN min = array(i)
    NEXT
END FUNCTION

Same for max, basically.
Title: Re: min() and max()
Post by: johnno56 on September 22, 2021, 04:07:31 am
The basic min() and max() command, that I am planning on,  will not be handling arrays but only two variables. From the example provided I should be able to work it out. Thanks Steve.

J
Title: Re: min() and max()
Post by: Pete on September 22, 2021, 01:43:00 pm
Steve just might be the sharpest tool in the shed... Oh wait, I can't believe I shed that!

Pete
Title: Re: min() and max()
Post by: doppler on September 22, 2021, 03:34:29 pm
Steve just might be the sharpest tool in the shed... Oh wait, I can't believe I shed that!

Pete

You may want to revise that statement.  Remember Steve started this thread: https://www.qb64.org/forum/index.php?topic=4194.0
Title: Re: min() and max()
Post by: SpriggsySpriggs on September 22, 2021, 03:36:25 pm
@johnno56  Can you show basic usage of the function you are planning?
Title: Re: min() and max()
Post by: FellippeHeitor on September 22, 2021, 03:38:27 pm
This is min() and max() in p5js.bas (https://github.com/FellippeHeitor/p5js.bas/blob/master/p5js.bas):

Code: QB64: [Select]
  1. 'Calculate minimum value between two values
  2. Function min! (a!, b!)
  3.     If a! < b! Then min! = a! Else min! = b!
  4.  
  5. 'Calculate maximum value between two values
  6. Function max! (a!, b!)
  7.     If a! > b! Then max! = a! Else max! = b!
Title: Re: min() and max()
Post by: SMcNeill on September 22, 2021, 03:54:58 pm
You may want to revise that statement.  Remember Steve started this thread: https://www.qb64.org/forum/index.php?topic=4194.0

Remember, even the best of tools get wore out over time.  Have some pity on an old, broken down fat fellow — let ‘em have a few nice glories and kindly overlook all the countless failures.  😭😭😭

(And I still say that arrow is possessed by the devil and has hid from me for the last several years, just so I wouldn’t notice it and think the forums had broken!)
Title: Re: min() and max()
Post by: Pete on September 22, 2021, 04:26:31 pm
You may want to revise that statement.  Remember Steve started this thread: https://www.qb64.org/forum/index.php?topic=4194.0

Why Steve,why?!

Oh well, when I throw out a compliment, I really throw out a compliment. Consider that one recycled!

Yep, sometimes even us sharpest tools shed all over ourselves.

Pete :D
Title: Re: min() and max()
Post by: johnno56 on September 22, 2021, 04:36:23 pm
SpriggsySpriggs,

I certain can. I am converting a simple Xmas-type game from Naalaa to QB64. At my skill level I should be done by Xmas! But it could be close... lol

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
(line #141)

Fillippe,

What is the purpose of the exclamation marks within a function? Just curious. (Thanks for the functions, by the way!)

... and how do you add those 'personal' blue hyper links to messages?


Title: Re: min() and max()
Post by: Pete on September 22, 2021, 04:41:33 pm
@johnno56   - In your "Profile" there are two input lines, one for the title of the site, and one for the link.

Pete
Title: Re: min() and max()
Post by: FellippeHeitor on September 22, 2021, 04:52:22 pm
Exclamation points indicate data type SINGLE precision, for variables and functions.

To add a url to a post you use the [url] tag (or just click the globe button, next to the QB64 code box button in the post editor page. Try quoting my post to see the source.
Title: Re: min() and max()
Post by: Pete on September 22, 2021, 05:43:42 pm
Hmm, I thought Fell used his profile signature for that... Let's see if it works for me. Adding a message and link with   (http://) tags to my signature in my profile. Let's see if it worked...

Pete
Title: Re: min() and max()
Post by: doppler on September 22, 2021, 06:37:09 pm
@SMcNeill Everyone is allowed a DOH moment.  I lost count of my DOH's here.  That arrow is a bit small.  Hell I missed the big announcement in QB64 saying to exclude QB64 directory tree from virus scanning.  That was a real slap to the forehead event.