12-26-2025 07:05 AM
Given any value, I want to snap it to a value such that the MSD is 1, 2, or 5, and the remaining digits are zeros.
Here's what I've come up with.
Can anyone come up with something better?
Solved! Go to Solution.
12-26-2025 10:27 AM
Plese check that
12-26-2025 10:40 AM
Paul,
Thanks for the brain-teaser. I tried to figure out what you were doing from the image (didn't notice you'd actually attached code. I recognized the "magic numbers" were log (2) and log (5), understood using log10 and exp10 to isolate "significant digits" and "location of decimal point", but the central function I didn't recognize, nor could I readily find it.
Then I noticed you'd included the VI (thanks!!). Turns out that's "Threshold 1D Array", which is part of a library (Scope?) that I don't have in my current installation of LabVIEW 2024. I did read the description in the Help, and can see that it's something like "put this value in the correct bin of specified widths". Probably if I installed the "Scope" library, I'd learn more about this function (which is possibly a malleable VI).
My intuition is that this is probably as efficient as you are likely to get, as far as an algorithm is concerned.
Where is the Library that contains this function? What "loads" this Library? Is it a Malleable VI, in fact?
Bob (always learning) Schor
12-26-2025 10:56 AM - edited 12-26-2025 11:47 AM
Seems like a reasonable approach but I don't understand the need for EXT representation of the diagram constant.
12-26-2025 12:43 PM
(cannot look at Ahmed's code)
Here's what I might do instead. Result differ somewhat because this operates on the linear range. Not sure what you prefer.
Attached is a comparison. Note that in my case, the "bins" are filled more evenly.
12-26-2025 03:33 PM - edited 12-26-2025 03:35 PM
@paul_a_cardinale wrote:
Given any value, I want to snap it to a value such that the MSD is 1, 2, or 5, and the remaining digits are zeros.
Here's what I've come up with.
Can anyone come up with something better?
Are you looking for a Knob? Like an O'Scope? I think Dr. Darrin K had an algorithm a few years ago. Even if he didn't, a 1,2,5 progression is not as hard as you think it is 🤔
3dB
12-26-2025 05:43 PM
@Bob_Schor wrote:
Paul,
Thanks for the brain-teaser. I tried to figure out what you were doing from the image (didn't notice you'd actually attached code. I recognized the "magic numbers" were log (2) and log (5), understood using log10 and exp10 to isolate "significant digits" and "location of decimal point", but the central function I didn't recognize, nor could I readily find it.
Then I noticed you'd included the VI (thanks!!). Turns out that's "Threshold 1D Array", which is part of a library (Scope?) that I don't have in my current installation of LabVIEW 2024. I did read the description in the Help, and can see that it's something like "put this value in the correct bin of specified widths". Probably if I installed the "Scope" library, I'd learn more about this function (which is possibly a malleable VI).
My intuition is that this is probably as efficient as you are likely to get, as far as an algorithm is concerned.
Where is the Library that contains this function? What "loads" this Library? Is it a Malleable VI, in fact?
Bob (always learning) Schor
"Threshold 1D Array" is a built-in function. I thought it would be present in all versions of LV.
12-26-2025 05:50 PM
@altenbach wrote:
Seems like a reasonable approach but I don't understand the need for EXT representation of the diagram constant.
Yields about 1 more digit of accuracy (but I don't really need it).
12-26-2025 06:05 PM
@altenbach wrote:
(cannot look at Ahmed's code)
Here's what I might do instead. Result differ somewhat because this operates on the linear range. Not sure what you prefer.
Attached is a comparison. Note that in my case, the "bins" are filled more evenly.
I like it, but I'm more of a feedback-node kind of guy.
12-26-2025 06:22 PM
@Bob_Schor wrote:
Paul,
Thanks for the brain-teaser. I tried to figure out what you were doing from the image (didn't notice you'd actually attached code. I recognized the "magic numbers" were log (2) and log (5), understood using log10 and exp10 to isolate "significant digits" and "location of decimal point", but the central function I didn't recognize, nor could I readily find it.
Then I noticed you'd included the VI (thanks!!). Turns out that's "Threshold 1D Array", which is part of a library (Scope?) that I don't have in my current installation of LabVIEW 2024. I did read the description in the Help, and can see that it's something like "put this value in the correct bin of specified widths". Probably if I installed the "Scope" library, I'd learn more about this function (which is possibly a malleable VI).
My intuition is that this is probably as efficient as you are likely to get, as far as an algorithm is concerned.
Where is the Library that contains this function? What "loads" this Library? Is it a Malleable VI, in fact?
Bob (always learning) Schor
I wasn't really trying to tease brains, just wondering if someone could come up with something better for me.
Ages ago I used to send brain teasers to my coworkers (usually VIs that didn't behave as expected). Mostly they caught on fairly quickly; but eventually I stumped them with this one: Open the .vi file and both the FP & BD open, but they're both empty (really empty, not just stuff hidden from view). Click the run button, and usually nothing would happen, but after a few to several times, the block diagram would fill in with some simple code. Subsequent runs would just run that code. The opposite of self-deleting code, this was self-writing code. The trick stopped working sometime around '08. If you remember some quirky old LV behaviors, you might be able to figure out what I did.