![]() |
Forum Index : Microcontroller and PC projects : PicoMite array questions
Author | Message | ||||
MarkF Regular Member ![]() Joined: 01/08/2023 Location: AustraliaPosts: 47 |
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: GermanyPosts: 1233 |
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: NetherlandsPosts: 5089 |
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: AustraliaPosts: 47 |
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 KingdomPosts: 10310 |
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: AustraliaPosts: 6283 |
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 |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
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: AustraliaPosts: 47 |
Thanks Matt, Jim and Mick ![]() - Mark |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |