12-28-2009 01:46 PM
Of course the code would need some tweaking, because it is not perfect.
For example 1.99 would currently result in "1 1/1" with the default resolution and 2.0001 results in "2 1/32".
Both cases should return 2! 😞
12-28-2009 01:56 PM
altenbach wrote:Of course the code would need some tweaking, because it is not perfect.
For example 1.99 would currently result in "1 1/1" with the default resolution and 2.0001 results in "2 1/32".
Both cases should return 2! 😞
You think that is annoying, what do you suppose happens when you try -2.1?
12-28-2009 02:24 PM - edited 12-28-2009 02:25 PM
altenbach wrote:Of course the code would need some tweaking, because it is not perfect.
Here's a very quick and crude attempt at an improvement (LV 8.0). Please verify correct operations and modify as needed. 😉
02-25-2010 11:13 AM
Of course better would be to convert to I64 instead of I32, but then we would need to rewrite the GCD code in I64 (no big deal, simply inlining the current subVI will automatically remove the coercions :D).
For higher bit resolutions, we'll quickly run out of bits by using I32.
We also need some range checking on the inputs and generate an error if things get outside the valid ranges.
01-30-2017 11:44 AM - edited 01-30-2017 11:48 AM
Dead thread, I know, but sharing another solution for future searchers.
I had to put this solution together when there was a forum problem and I could not download or view the solutions posted, and once I could see them it seemed to work better. At least handled negative and just-barely-off issues better than the original, and gave more layman-friendly options for fraction resolution.
I didn't benchmark this against Altenbach's solution, though, which seemed to work pretty well on a few minor test cases once I could finally see it...
02-01-2017 10:22 AM
This screams to be made into an XControl.
I couldn't resists.
02-01-2017 11:53 AM
Here it is in LV2015 (and with all the pieces this time).
02-01-2017 02:05 PM
Yet another version. Pretty simple.
02-01-2017 02:27 PM
Entering 2.8 yields "No fraction"
02-01-2017 02:42 PM
Oops, looking for a fix ...