Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 03:32 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMite array questions

Author Message
MarkF
Regular Member

Joined: 01/08/2023
Location: Australia
Posts: 47
Posted: 03:43am 09 Aug 2023
Copy link to clipboard 
Print this post

Hi. For an one dimensional array with numbers for elements, how would I obtain the "lowest positive' element value, excluding zero(0)? Thanks.
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1114
Posted: 06:21am 09 Aug 2023
Copy link to clipboard 
Print this post

Hi Mark,

If i understand your question right.

Therange of floating point numbers is
1.797693134862316e+308 to 2.225073858507201e-308.

The range of 64-bit integers (whole numbers) that can be manipulated is ± 9223372036854775807.

Cheers
Mart!n
Edited 2023-08-09 16:38 by Martin H.
'no comment
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4247
Posted: 07:38am 09 Aug 2023
Copy link to clipboard 
Print this post

Find the max of the array.
Add 10xmax to all numbers that are equal zero or negative.
Find the min of the array

That is your answer.

Volhout
PicomiteVGA PETSCII ROBOTS
 
MarkF
Regular Member

Joined: 01/08/2023
Location: Australia
Posts: 47
Posted: 07:47am 09 Aug 2023
Copy link to clipboard 
Print this post

Thanks Martin and Volhout.

I should have given an example.

One dim array e.g.  (12,0,14.5,3,62)

The lowest element in the array is 0, but I wanted to get 3 instead (the lowest min above zero).

MMBasic function ====> MATH(MIN arrayname()) is a solution.

But it returns 0 if I use it on the above example array. Whereas I would like to get 3.

MATH(MIN arrayname() [,index%])
Perhaps the index can be used, but I don't know how to use it.

-thanks
Edited 2023-08-09 18:38 by MarkF
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9128
Posted: 08:51am 09 Aug 2023
Copy link to clipboard 
Print this post

Can't think of any way to do this with the MATH commands or functions so you will need to just write a loop

General solution

max = 1.797693134862316e+308 ' or 9223372036854775807 if integer array
for i=bound(array(),0) to bound(array())
 if(array(i)>0 and array(i)<max then max = array(i)
next i
print max
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6100
Posted: 10:23am 09 Aug 2023
Copy link to clipboard 
Print this post

Not the fastest:
'
DIM a(4) = (12,0,14.5,3,62)

DO
m = MATH(MIN a(), index%)
IF m = 0 THEN
a(index%) = 100000
ENDIF
LOOP UNTIL m > 0
PRINT index%, m



Make a copy of the array first if you need to retain all elements.

Another way is 'sort' then step through to skip over the zero values.

Jim
VK7JH
MMedit   MMBasic Help
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 10:39am 09 Aug 2023
Copy link to clipboard 
Print this post

Don't reject zero values. Add 0.001 to everything and don't have them to start with. ;)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
MarkF
Regular Member

Joined: 01/08/2023
Location: Australia
Posts: 47
Posted: 01:33pm 09 Aug 2023
Copy link to clipboard 
Print this post

Thanks Matt, Jim and Mick .  Jim's example of the MATHS MIN function is very interesting.

- Mark
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024