View previous topic :: View next topic |
Author |
Message |
hzz
Joined: 20 Feb 2007 Posts: 314
|
Posted: Wed Dec 01, 2021 6:51 pm Post subject: Please check MIN(ar(1), m , idx) |
|
|
Code: | '____________________________________________________________________________________
$regfile = "xm256a3Udef.dat"
$hwstack = 256
$swstack = 128
$framesize = 128
'____________________________________________________________________________________
' For 16MHz crystal
Config Osc = Disabled , Extosc = Enabled , Range = 12mhz_16mhz , Startup = Xtal_1kclk , 32khzosc = Enabled
' Set PLL OSC conditions:
Osc_pllctrl = &B1100_0010 ' reference external oscillator, set the PLL' multiplication factor to 2 (bits 0 - 4)
Set Osc_ctrl.4 ' Enable PLL Oscillator
Bitwait Osc_status.4 , Set ' wait until the pll clock reference source is stable
Clk_ctrl = &B0000_0100 ' switch system clock to pll
' Prescale
Config Sysclock = Pll , Prescalea = 1 , Prescalebc = 1_1
$crystal = 32000000
'____________________________________________________________________________________
Dim Test_array(6) As Byte
Dim Index_min As Byte
Dim Value_min As Byte
Test_array(1) = 5
Test_array(2) = 6
Test_array(3) = 2
Test_array(4) = 7
Test_array(5) = 1
Test_array(6) = 8
Min(test_array(2) , Value_min , Index_min) |
The previous code should result in Value_min=1 and Index_min=5 (or 4?)
however the result is Value_min=0 and Index_min=6 ¿!?
(BASCOM-AVR version : 2.0.8.3 , Latest : 2.0.8.4 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed Dec 01, 2021 7:54 pm Post subject: |
|
|
Guess any other index than array start is ignored and the count of values to be looked up equals the array size.
Makes sense insofar that no upper array limit is possible either.
Try what happens if you use MIN on OL_array(1)
Code: | Dim Test_array(6) As Byte
Dim OL_array(4) At Test_array(2) Overlay |
|
|
Back to top |
|
|
hzz
Joined: 20 Feb 2007 Posts: 314
|
Posted: Wed Dec 01, 2021 11:26 pm Post subject: |
|
|
It works Ok when the index of the array is 1 but reading the Help seems that it was supposed to work also with other values so it may be a bug:
MIN(ar(1), m , idx)
Ar(1) Starting element to get the minimum value and index of
M Returns the minimum value of the array
Idx Return the index of the array that contains the minimum value. Returns 0 if there is no minimum value. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Dec 02, 2021 12:56 am Post subject: |
|
|
hzz wrote: | it may be a bug: |
One may assume that, however it's likely the help is not clear enough, it explicitly reads
it does not read
or
|
|
Back to top |
|
|
hzz
Joined: 20 Feb 2007 Posts: 314
|
Posted: Thu Dec 02, 2021 8:21 pm Post subject: |
|
|
OK, I pointed out just in case MIN and MAX were intended to work as SORT |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sat Dec 04, 2021 11:34 am Post subject: |
|
|
it works as designed.
otherwise there would be an additional parameter so you can specify the number of elements to check. now it resorts to the total. which was logical for me at design time. otherwise why using precious memory and not use it totally. but i am sure you have a good reason not to use the total array. so let me know how/why with a good sample. _________________ Mark |
|
Back to top |
|
|
|