Finding the closest number - How to make it show the two options when just in the middle of two numbers?
These are very good ways to find the closest number to certain number.
However, when the input number (the one you want to go to its closest number) its exactly in the middle, just between two other numbers (for example, 7 is just between 5 and 9) it will always go to the lowest closest number.
Any ideas of how to make it choose the upper one??? For example, 7 going to 9 instead of 5. Or way better... Any ideas of how to make it show the two options?
Make it show the two options will be way better.
Thanks!
hello
I don't know if it's useful..
![](https://cycling74-web-uploads.s3.amazonaws.com/58ed0578285705c15ccfce94/2022-01-21T13:07:41Z/image.png)
Hi.
It is not useful for what I'm looking for.
The goal is to still be able to show the closest number and if the input is just in the middle of two numbers, then, show the two options.
This is the best solution so far... Provided by Italo Lombardo
The toggle option to show the two closest numbers (the upper and the lower ones) will only work when the input number is just in the middle of two numbers (e.g. 7 is just between 5 and 9), but that was the goal actually, so its perfect.
if x is greater than y (or equal to) AND also smaller than the middle between y and z, then output y, alternatively, if x is smaller than z AND also greater than the middle between y and z, then output z
[expr ( ($f1>=$f2) && ($f1<(($f2+$f3)/2.)) ) * $f2 + ( ($f1>$f3) && ($f1> (($f2+$f3)/2.)) ) * $f3]
"output whichever of A, B, C or D is closest to X"
-> which is the smallest: the difference of a and x, b and x., c and x, or d and x?
difference to x:
(abs($f1-$f5))
output only the smallest of 4 numbers:
min((min($f1, $f2)), (min($f3, $f4)))
afte comparing all to find the smallest, we now need to check which of the input values causes that smallest difference in order to send that out.
[expr (((min((min((abs($f1-$f5)),(abs($f2-$f5)))),(min((abs($f3-$f5)),(abs($f4-$f5))))))==(abs($f1-$f5)))*$f1) + (((min((min((abs($f1-$f5)),(abs($f2-$f5)))),(min((abs($f3-$f5)),(abs($f4-$f5))))))==(abs($f2-$f5)))*$f2) + (((min((min((abs($f1-$f5)),(abs($f2-$f5)))),(min((abs($f3-$f5)),(abs($f4-$f5))))))==(abs($f3-$f5)))*$f3) + (((min((min((abs($f1-$f5)),(abs($f2-$f5)))),(min((abs($f3-$f5)),(abs($f4-$f5))))))==(abs($f4-$f5)))*$f4)]
not too convincing, because it breaks the size limit of expr.
so i would either exclude the abs(...) in 4 extra expr objects, or build it around pack/vexpr/minimum (the latter takes lists, too)
splitting it into 3 parts looks much better.
![](https://cycling74-web-uploads.s3.amazonaws.com/574f1ffc3b4a14995d983d8f/2023-04-12T16:02:54Z/grafik.png)