03-22-2020 07:15 PM
How do you display your answer as a non-reduced fraction using 3 indicators. 1 for the whole number, 1 for the numerator, and 1 for the denominator.
03-22-2020 07:40 PM
Well, that's gonna depend on what "answer" you're referring to.
Do you start with both dividend and divisor? That should be easy. Or do you start with a single value with digits to the right of the decimal? That's more complicated.
Either way, you'll probably want to make use of the Quotient & Reminder function. If you start from a single decimal value, you'll want to look into rational approximation. I'd recommend the Mathscript node if you have it available in your installation. Otherwise, my link in that thread will lead you to a more brute-force method.
-Kevin P
03-23-2020 04:46 AM
The GCD (greatest common denominator) function is useful too.
Depending on the details...
03-23-2020 07:14 AM
wiebe@CARYA wrote:
The GCD (greatest common denominator) function is useful too.
Depending on the details...
The OP did state "nonreduced", which is you would still have 2/8 instead of 1/4. Therefore, I think the Quotient & Remainder is all that is needed here.
03-23-2020 07:39 AM - edited 03-23-2020 07:41 AM
@crossrulz wrote:
wiebe@CARYA wrote:
The GCD (greatest common denominator) function is useful too.
Depending on the details...
The OP did state "nonreduced", which is you would still have 2/8 instead of 1/4. Therefore, I think the Quotient & Remainder is all that is needed here.
If he has a float, what exactly is the non reduced fraction supposed to be? Is "1.040" "1 4/100", "1 40/1000?" or "1 400/10000" or "1 400/100000"? Q&R is only very little help.
If he already has a nominator and denominator, how is the Q&R going to help?
03-23-2020 08:09 AM
wiebe@CARYA wrote:If he already has a nominator and denominator, how is the Q&R going to help?
The OP stated they wanted a whole number as well. So I am left to assume they want something like X = 10, Y = 4, therefore the outputs should be Whole Number = 2, Numerator = 2, Denominator = 4. So you can just use Q&R to get the Whole Number (Quotient) and the Numerator (Remainder) and then just pass Y as the Denominator.
But this is mostly speculation until the OP clarifies, preferably with an example.
03-23-2020 08:55 AM
@crossrulz wrote:
wiebe@CARYA wrote:If he already has a nominator and denominator, how is the Q&R going to help?
The OP stated they wanted a whole number as well. So I am left to assume they want something like X = 10, Y = 4, therefore the outputs should be Whole Number = 2, Numerator = 2, Denominator = 4. So you can just use Q&R to get the Whole Number (Quotient) and the Numerator (Remainder) and then just pass Y as the Denominator.
But this is mostly speculation until the OP clarifies, preferably with an example.
That makes sense now.
03-23-2020 10:43 AM
Maybe this will be helpful.
03-24-2020 02:17 AM
@Kevin_Price wrote:
If you start from a single decimal value, you'll want to look into rational approximation. I'd recommend the Mathscript node if you have it available in your installation.
Actually, the Mathscript function might be buggy unless they fixed CAR 702329. See my code here and surrounding discussion. It is trivial to go from the rational approximation to "Number =~ (X + Y/Z)" and display the three values, of course.
03-24-2020 06:10 AM
Yikes! Thanks for the tip. (Interestingly, I had tested the MathScript funciton briefly and successfully with the same small tolerance of 1.0e-8 that didn't work in your linked example. The code was still up in a background window, and I fed in the pi constant as input. The one (of many) "bad" values you illustrated 0.6251 failed for me in LV 2016 too. I guess it's not a new bug.
-Kevin P