Author Topic: min() and max()  (Read 4348 times)

0 Members and 1 Guest are viewing this topic.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
min() and max()
« on: September 22, 2021, 02:43:37 am »
Does anyone know how to simulate the min() and max() function using QB64?

J
Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: min() and max()
« Reply #1 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: min() and max()
« Reply #2 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
Logic is the beginning of wisdom.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: min() and max()
« Reply #3 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: min() and max()
« Reply #4 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

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: min() and max()
« Reply #5 on: September 22, 2021, 03:36:25 pm »
@johnno56  Can you show basic usage of the function you are planning?
Shuwatch!

FellippeHeitor

  • Guest
Re: min() and max()
« Reply #6 on: September 22, 2021, 03:38:27 pm »
This is min() and max() in 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!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: min() and max()
« Reply #7 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!)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: min() and max()
« Reply #8 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: min() and max()
« Reply #9 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

  [ You are not allowed to view this attachment ]  
(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?


Logic is the beginning of wisdom.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: min() and max()
« Reply #10 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: min() and max()
« Reply #11 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.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: min() and max()
« Reply #12 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 tags to my signature in my profile. Let's see if it worked...

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: min() and max()
« Reply #13 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.