PicoMite array questions


Author Message
MarkF
Regular Member

Joined: 01/08/2023
Location: Australia
Posts: 49
Posted: 03:43am 09 Aug 2023      

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: 1479
Posted: 06:21am 09 Aug 2023      

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.

Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5991
Posted: 07:38am 09 Aug 2023      

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

MarkF
Regular Member

Joined: 01/08/2023
Location: Australia
Posts: 49
Posted: 07:47am 09 Aug 2023      

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: 11614
Posted: 08:51am 09 Aug 2023      

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: 6543
Posted: 10:23am 09 Aug 2023      

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

Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8955
Posted: 10:39am 09 Aug 2023      

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

MarkF
Regular Member

Joined: 01/08/2023
Location: Australia
Posts: 49
Posted: 01:33pm 09 Aug 2023      

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

- Mark