Dear Mel Smith:
On Wednesday, August 4, 2021 at 7:36:07 AM UTC-7,
meds...@gmail.com wrote:
...
> I'm working on a little Harbour program where my algorithm has to
> decide on the nearness of n sets of numbers. There are two integers
> in each set. I retain a measurement of of each set :
>
> Here is the algo I am using to compute and save the 'nearness' of each set:
>
> nVal := ABS(log(a)-log(b))
Why not just ABS(a-b)? Is {1,2} further apart than {10001,10002}? (0-0.30) vs. (4.00004-4.00009)
Plus log() involves lots of calculations... might be better off with ABS(a/b) or ABS( (a-b)/(a+b) ) if you really want "nearness" to be scaled by "average size". And if you want to stick with logs, just use ln(), slightly faster.
> where a and b are the two numbers in each set. (Typical values of a
> and b will range up in the trillions.) I will save/compare this nVal with
> many thousands of other nVals and decide with nVal is the smallest
> value, and so which set is 'nearest'.
>
> I don't expect a and b to ever be identical, but, if they are, I would be
> delighted. But, first, I wish to find the nearest.
>
> Question: Is there a better algo that you know off than the one I show
> above. ??
Form the "nearness" as you load the array, and have that be one of the terms in the array. Then sort.
David A. Smith