hexagon logo

PCL; how to sort 2D array?

I am trying to sort node IDs by position. I created 2D REAL array where 1st column is node ID and second is position. Next I use mth_sort_column to sort by position column. However, it does not produce expected result. The first problem is that I cannot convert correctly INTEGER into REAL number:
 
example:
 
REAL a
INTEGER b
b=31100069
a=b
dump a, b
 
The result is:
$# REAL a = 31100068.
$# INTEGER b = 31100069
 
How to explain change of the value? How to make conversion correctly? Do I have to write my own sorting function?
Parents
  • Hi, yes that is neater.
    You may well come up with a more concise method.
    At the time I was thinking of transposing and using sys_move_raw and sys_reallocate_array to give space for the index but decided it would not gain anything. There are times when the underlying array row storage architecture(aka C) is not as convenient as column format (aka Fortran) when wanting to resize arrays, and of course times when it's great.
Reply
  • Hi, yes that is neater.
    You may well come up with a more concise method.
    At the time I was thinking of transposing and using sys_move_raw and sys_reallocate_array to give space for the index but decided it would not gain anything. There are times when the underlying array row storage architecture(aka C) is not as convenient as column format (aka Fortran) when wanting to resize arrays, and of course times when it's great.
Children
No Data