1. Converting decimal number to carpenter's fractions
- Posted by K_D_R May 04, 2012
- 2613 views
Does anyone have, or can recommend a routine to convert decimals to carpenters inch fractions: 32nds, 16ths, 8ths, 4ths, halfs? I have a list of equivalents so I guess If there is no exact match, I would need to compare up the list until a higher value is reached and then subtract my search value from the larger value and subtract the previous lower value from the decimal value I am seeking to convert and then select the value which has the lowest difference.
sequence decimal_fractions { {.03125, 1, 32}, {.06250, 1, 16}, {.09375, 3, 32}, ..... {.96875, 31, 32} x = 0.07356 0.09375 - 0.07356 = 0.02019 0.07356 - 0.06250 = 0.01106 x = {1,16} or 1/16th inch
Seems like there must be an easier way, though.
Any suggestions would be appreciated.
2. Re: Converting decimal number to carpenter's fractions
- Posted by ne1uno May 05, 2012
- 2584 views
Does anyone have, or can recommend a routine to convert decimals to carpenters inch fractions: 32nds, 16ths, 8ths, 4ths, halfs? I have a list of equivalents so I guess If there is no exact match, I would need to compare up the list until a higher value is reached and then subtract my search value from the larger value and subtract the previous lower value from the decimal value I am seeking to convert and then select the value which has the lowest difference.
sequence decimal_fractions { {.03125, 1, 32}, {.06250, 1, 16}, {.09375, 3, 32}, ..... {.96875, 31, 32} x = 0.07356 0.09375 - 0.07356 = 0.02019 0.07356 - 0.06250 = 0.01106 x = {1,16} or 1/16th inch
Seems like there must be an easier way, though.
Any suggestions would be appreciated.
I've used something like this
-- minimum fraction default 1/64th -- needs more work if want to find the nearest fraction over or under. -- might be nice to return the amount over if any. -- public function dec_frac(atom x1, atom minfraction = 0.015625) atom numerator = 1, denominator = 2, mf = 64 x1 += 0.00002 if minfraction < 1 then mf = floor(math:abs(1/minfraction)) end if for r = numerator to mf - 1 do if abs(x1 - (r/mf)) <= minfraction then numerator = r goto "done" end if end for return {} --error label "done" --simplity return {numerator/math:gcd(numerator, mf) , mf/math:gcd(numerator, mf)} end function test_equal("dec_frac 1/32",{1,32}, trig:dec_frac(1/32)) test_equal("dec_frac 1/16",{1,16}, trig:dec_frac(1/16)) test_equal("dec_frac 3/32",{3,32}, trig:dec_frac(.094)) test_equal("dec_frac 1/4",{1,4}, trig:dec_frac(0.25)) test_equal("dec_frac 5/8",{5,8}, trig:dec_frac(0.625)) test_equal("dec_frac 7mm",{17,64}, trig:dec_frac(0.2756))
3. Re: Converting decimal number to carpenter's fractions
- Posted by bill May 05, 2012
- 2565 views
x/10 = y/32
y = x * 16 / 5
round result
4. Re: Converting decimal number to carpenter's fractions
- Posted by DerekParnell (admin) May 05, 2012
- 2566 views
Does anyone have, or can recommend a routine to convert decimals to carpenters inch fractions: 32nds, 16ths, 8ths, 4ths, halfs?
constant mm_inch = 1/25.4 function carp( atom x, atom conv = 1) integer numerator integer denominator integer units x *= conv if x > 1 then units = floor(x) x -= units else units = 0 end if numerator = floor( x * 64 + 0.5) denominator = 64 while denominator > 1 do if remainder(numerator,2) = 1 then exit end if numerator /= 2 denominator /= 2 end while return {units,numerator,denominator} end function ? carp(0.625) --> {0,5,8} ie. five eigths ? carp(2.314) --> {2,5,16} ie. two and five sixteenths ? carp(38, mm_inch) --> {1,1,2} ie. 38mm -> 1 1/2 inch
5. Re: Converting decimal number to carpenter's fractions
- Posted by K_D_R May 05, 2012
- 2511 views
Thanks to all who responded with helpful instructions and code.
WOW! I am often stunned at the programming expertise you guys share in the forum.
I deeply appreciate the assistance.
6. Re: Converting decimal number to carpenter's fractions
- Posted by bill May 06, 2012
- 2490 views
function carp(atom x) integer u = floor(x) integer n = floor((x-u) * 64 + 0.5) -- boundary conditions -- x-u >= 127/128 if n = 64 then return {u+1, 0, 1} -- orginal function returned {u, 1, 1} -- x-u < 1/128 elsif n = 0 then return {u, 0, 1} -- normal form -- n in range 1-63 else integer d = 64 while remainder(n, 2) = 0 do n /= 2 d /= 2 end while return {u, n, d} end if end function
results:
carp(0) : {0,0,1} carp(1) : {1,0,1} carp(0.625) : {0,5,8} carp(2.314) : {2,5,16} carp(127/128) : {1,0,1} -- rounds up carp(1/128) : {0,1,64}Other comment:
In the original code the normaisation loop went
d = 64 while d > 1 do if remainder(n, 2) = 1 then exit end if n /= 2 d /= 2 end while
The only way this loop can normally terminate is if n started as 0 or 64.
Both conditions meet the test:
remainder(n, 2) = 0 the test d > 1 produces: 64 64 0 64 32 32 0 32 ...... .... 1 1 0 1 <eucode> In the case n = 0, n doesn't change. In the case n = 64, the reduction shouldn't be applied as 64/64 is not a proper fraction. From a programming perspective <eucode> while d > 1 do
is a poor choice because it runs until d <= 1. It exits abnormally in almost all cases.
while remainder(n, 2) = 0
works properly because, *given n is in 0-63*, we know n reduces as d reduces and n must reduce to an odd number.
7. Re: Converting decimal number to carpenter's fractions
- Posted by DerekParnell (admin) May 06, 2012
- 2500 views
A bit more generic version ...
include std/math.e constant mm_inch = 1/25.4, cm_inch = 1/2.54, m_ft = 1000 / 304.8 function carp( atom x, atom conv = 1, integer base = 64) integer numerator integer denominator integer units integer sign -- Apply any Unit-of-measure conversion x *= conv -- Remember original sign and ensure working is on absolute value. if x >= 0 then sign = 1 else sign = -1 x = -x end if -- Express original value in terms of how many 'base' fragments it is (rounded) x = floor(x * base + 0.5) -- Get numerator in range of 0 to base-1 numerator = remainder(x, base) -- Strip off the non-fraction part units = (x - numerator) / base denominator = base if numerator > 0 then -- First, normalize the fraction in terms of GCD x = gcd(numerator, denominator) numerator /= x denominator /= x -- Next, normalize the fraction until either top or botton is an odd number. while remainder(numerator,2) = 0 and remainder(denominator,2) = 0 do numerator /= 2 denominator /= 2 end while end if return {units, numerator, denominator, sign} end function ? carp(0) -- {0,0,64,1} ? carp(1) -- {1,0,64,1} ? carp(-0.625) -- {0,5,8,-1} ? carp(2.314) -- {2,5,16,1} ? carp(127/128) -- {1,0,64,1} ? carp(127/128,,128) -- {1,127,128,1} ? carp(1/128) -- {0,1,64,1} ? carp(257/256) -- {1,0,64,1} ? carp(38, mm_inch) --> {1,1,2,1} ie. 38mm -> 1+1/2 inch ? carp(38, mm_inch, 1000) --> {1,62,125,1} ie. 38mm -> 1+62/125 inch ? carp(1/3, 1, 9) --> {0,1,3,1} ? carp(2/3, 1, 9) --> {0,2,3,1} ? carp(5/27, 1, 9) --> {0,2,9,1}
8. Re: Converting decimal number to carpenter's fractions
- Posted by K_D_R May 06, 2012
- 2503 views
And it just gets better and better...
One question for Derek...
constant -- mm_inch = 1/25.4, -- value to be computed mm_inch = 0.0393700787, -- constant -- cm_inch = 1/2.54, cm_inch = 0.393700787, -- m_inch = 1/.0254, m_inch = 39.3700787, -- m_ft = 1000 / 304.8, m_ft = 1000 / 304.7999995367 m_ft = 3.2808399 -- cm_ft = 10 / 304.7999995367 cm_ft = 0.032808399
I noticed that you choose to computed the value of the constant every time. Jim Roberts used this method in his convert.e utility program as well. Why is it better to calculate the constant each time?
Regards,
9. Re: Converting decimal number to carpenter's fractions
- Posted by DerekParnell (admin) May 06, 2012
- 2446 views
Why is it better to calculate the constant each time?
Well, they only get calculated once, when the program starts up. And of course, translated programs don't calculate them at all. The main reason I do it this way is that some numbers are easier to remember than others. I remember 25.4 and 304.8 better than 0.0393700787 and 3.2808399 respectively. Also, sometimes I do it this way as it explains the magic number better.
10. Re: Converting decimal number to carpenter's fractions
- Posted by bill May 07, 2012
- 2478 views
Comments:
1. Negative lengths make no sense in the real world.
I would prefer to reject a request for an equivalent screw size of -38mm in 64ths of an inch as a type error.
2. The code as written has problems.
denominator = base -- *** 0, base is not normalised: GCD(0,3) = 3, not 0. if numerator > 0 then -- First, normalize the fraction in terms of GCD x = gcd(numerator, denominator) numerator /= x denominator /= x -- *** the following code will never run -- Next, normalize the fraction until either top or bottom is an odd number. while remainder(numerator,2) = 0 and remainder(denominator,2) = 0 do numerator /= 2 denominator /= 2 end while -- *** end if -- *** returns incorrect result when numerator is zero return {units, numerator, denominator, sign} ? carp(0) -- {0,0,64,1} -- *** should be {0,0,1,1} ? carp(1) -- {1,0,64,1} -- *** should be {1,0,1,1} ? carp(-0.625) -- {0,5,8,-1} ? carp(2.314) -- {2,5,16,1} ? carp(127/128) -- {1,0,64,1} -- *** should be {1,0,1,1} ? carp(127/128,,128) -- {1,127,128,1} ? carp(1/128) -- {0,1,64,1} ? carp(257/256) -- {1,0,64,1} -- *** should be {1,0,1,1}
include std/math.e constant MAXINT = 2e30 type Real(atom x) return x >= 0 end type type Nat(integer x) return x >= 0 and x <= MAXINT end type type PNat(integer x) return x > 0 and x <= MAXINT end type function carp(Real size, PNat base=64) Nat t = floor(size * base + 0.5) Nat n = mod(t, base) Nat U = floor(t / base) if n = 0 then return {U, 0, 1} -- accounting for a bug in gcd function else PNat g = gcd(n, base) return {U, n/g, base/g} end if end function /* ? carp(0) -- {0,0,1} ? carp(1) -- {1,0,1} ? carp(2.314) -- {2,5,16} ? carp(1/128) -- {0,1,64} ? carp(127/128) -- {1,0,1} ? carp(257/256) -- {1,0,1} */
function GCD(integer a, integer b) if a < 0 then return GCD(-a, b) elsif b < 0 then return GCD(a, -b) elsif b < a then return GCD(b, a) elsif a = 0 then if b = 0 then return {1, 0} -- error else return {0, b} end if else return GCD(mod(b,a), a) end if end function ? GCD(3,4) -- {0, 1} ? GCD(0,0) -- {1, 0} ? GCD(-4,8) -- {0, 4} ? GCD(3,0) -- {0, 3}
11. Re: Converting decimal number to carpenter's fractions
- Posted by DerekParnell (admin) May 07, 2012
- 2449 views
1. Negative lengths make no sense in the real world.
Thank you, I'll mention that to my Physics professor. He was under the (obviously mistaken) impression that negative lengths could be used to represent direction.
I would prefer to reject a request for an equivalent screw size of -38mm in 64ths of an inch as a type error.
How does the function know what you're measuring. That's why the sign is returned in its own field, so you, the caller, can deal with it as you see fit. It is not in this function's purpose to assume that negative input is an error. Whether or not it's an error is in the caller's knowledge domain.
2. The code as written has problems.
-- *** 0, base is not normalised: GCD(0,3) = 3, not 0.
This is not a mistake. It is a deliberate behaviour of the function. The purpose of returning the base as the denominator when the numerator is zero is to give the caller information about the 'base' - namely what is the default value. The caller, upon receiving the numerator output of zero, can then decide to use the 'base' denominator or not, according to the application's needs. This function does not presume why it is being called.
You would know that given a numerator of zero, the value of the denominator is not really required; it could be anything, so I may as well return something that could be useful.
2. The code as written has problems.
-- *** the following code will never run -- Next, normalize the fraction until either top or bottom is an odd number. while remainder(numerator,2) = 0 and remainder(denominator,2) = 0 do numerator /= 2 denominator /= 2 end while
You are correct. This is totally redundant.
12. Re: Converting decimal number to carpenter's fractions
- Posted by petelomax May 07, 2012
- 2433 views
Why is it better to calculate the constant each time?
LOL. For much the same reason you want carpenters fractions. Humans find them easier.
1. Negative lengths make no sense in the real world.
Not so. Cut a panel the exact size of a hole and there is no room for expansion/beading/silicone/putty. If you have a 1 inch baton, you don't use 1 inch screws. So "-3/32", say, is not only valid but common.
Pete
13. Re: Converting decimal number to carpenter's fractions
- Posted by K_D_R May 07, 2012
- 2444 views
Why is it better to calculate the constant each time?
LOL. For much the same reason you want carpenters fractions. Humans find them easier.
Pete
Carpenter's fractions may be easier for those habituated in their use, but I find the metric system much easier to use. It seems that most of the world, except the U.S. and the U.K., find the metric system easier to us. I think that even the U.K. may be further along than the U. S., as far as adopting the metric system.
Regards,
14. Re: Converting decimal number to carpenter's fractions
- Posted by bill May 07, 2012
- 2432 views
Derek & Pete
Re negative lengths:
Vectors have magnitude and direction,
a length is a magnitude.
Euclid: a point has position but no magnitude.
Physically it is the difference between speed and velocity:
making something smaller doesn't make negative length.
Quoting Wikipedia:
In physics, velocity is speed in a given direction. Speed
describes only how fast an object is moving, whereas velocity
gives both the speed and direction of the object's motion.
To have a constant velocity, an object must have a constant
speed and motion in a constant direction.
Re: non-normalised form (U, 0, 64) "shows the base.."
According to that reasoning {U, 5, 8} should be written {U, 40, 64}
And as a consequence of that you get {U, 1, 64} = {U, 2, 128} = ...
And (as stated) GCD(0,64) = 64. Normalised {U, 0, 64} = [U, 0, 1}.
Comparing sizes you will see normailastion is a GOOD IDEA.
15. Re: Converting decimal number to carpenter's fractions
- Posted by jimcbrown (admin) May 07, 2012
- 2410 views
Derek & Pete
Re negative lengths:
Vectors have magnitude and direction,
a length is a magnitude.
Agreed, if you are going to be fussy about the definitions of length and vectors and speed and velocity and so on...
The differences between these concepts are more-or-less academic to most programmers. More importantly, I can not see a reason to, to use your terminology, allow only lengths to be used by these routines, but forbid the use of vectors with them. Perhaps the programmer intended to, and actually wants to, deal with vectors even though that person calls them lengths. So what?
Of course, you can use a two element sequence to represent magnitude and direction, but if you only need two directions then I can see the elegance of using the sign bit here.
16. Re: Converting decimal number to carpenter's fractions
- Posted by jaygade May 08, 2012
- 2365 views
Why is it better to calculate the constant each time?
LOL. For much the same reason you want carpenters fractions. Humans find them easier.
Pete
Carpenter's fractions may be easier for those habituated in their use, but I find the metric system much easier to use. It seems that most of the world, except the U.S. and the U.K., find the metric system easier to us. I think that even the U.K. may be further along than the U. S., as far as adopting the metric system.
Regards,
For some things, decimals are easier. For other things, fractions are easier.
There are times when fractions are "cleaner" and more exact than are rounded decimals.
17. Re: Converting decimal number to carpenter's fractions
- Posted by K_D_R May 08, 2012
- 2403 views
For some things, decimals are easier. For other things, fractions are easier.
There are times when fractions are "cleaner" and more exact than are rounded decimals.
Please give me an example to illustrate your point.
18. Re: Converting decimal number to carpenter's fractions
- Posted by K_D_R May 08, 2012
- 2386 views
Why is it better to calculate the constant each time?
Well, they only get calculated once, when the program starts up. And of course, translated programs don't calculate them at all. The main reason I do it this way is that some numbers are easier to remember than others. I remember 25.4 and 304.8 better than 0.0393700787 and 3.2808399 respectively. Also, sometimes I do it this way as it explains the magic number better.
Interesting answer. I understand and agree. Thanks.
19. Re: Converting decimal number to carpenter's fractions
- Posted by mattlewis (admin) May 08, 2012
- 2364 views
For some things, decimals are easier. For other things, fractions are easier.
There are times when fractions are "cleaner" and more exact than are rounded decimals.
Please give me an example to illustrate your point.
I think the simplest example is 1/3. It has no exact representation, of course, in binary fractions (e.g., IEEE floating point numbers). Likewise, money fractions tend to be 1/100s, many of which cannot be represented exactly in binary fractions. It can be very important to get exact answers from calculations using these sorts of numbers where the errors introduced by binary approximations are unacceptable.
Matt
20. Re: Converting decimal number to carpenter's fractions
- Posted by DerekParnell (admin) May 08, 2012
- 2369 views
Re negative lengths:
Vectors have magnitude and direction,
a length is a magnitude.
Agreed, but that is not relevant. The function in question is dealing with scalars and it has no concept of what the arguments represent. It doesn't care if the value to translate is a length, vector, or anything else. If the caller wants to use negative numbers then why should the function care? All it's dealing with (the API/contract) is a number. To assist the caller, it preserves the original sign in case the application needs to use it.
The thing with library routines is that they should avoid making demands on the calling application that are orthogonal to the purpose of the function. This particular function just translates a decimal version of a number to some fractional version. The documentation should detail the contract between the caller and the routine.
Re: non-normalised form (U, 0, 64) "shows the base.."
According to that reasoning {U, 5, 8} should be written {U, 40, 64}
If I might, can I reiterate that (mis)quote in context?
The purpose of returning the base as the denominator when the numerator is zero is to give the caller information about the 'base' - namely what is the default value. The caller, upon receiving the numerator output of zero, can then decide to use the 'base' denominator or not, according to the application's needs. This function does not presume why it is being called.
There is no reasoning from {U,0,base} to {U,N,base}. So let me repeat myself ... when the numerator is zero ... the value of the denominator is not really required; it could be anything, so I may as well return something that could be useful. Useful to the caller, that is. To always return {U, 0, 1} when there is no fractional part is perfectly fine, except that its a waste of information bandwidth. This is not a mathematics environment; the function is trying to be useful to the caller by communicating information that may be gainfully employed by the application.
And as a consequence of that you get {U, 1, 64} = {U, 2, 128} = ...
And (as stated) GCD(0,64) = 64. Normalised {U, 0, 64} = [U, 0, 1}.
Comparing sizes you will see normailastion is a GOOD IDEA.
I'm a bit confused by this. You seem to be suggesting that normalization is the process of presenting a fraction such that the numerator and divisor are the smallest integers possible to represent the value. And that such normalization is useful for comparison of values. If I've got this wrong, please improve my understanding.
If this is so, I beg to differ.
Using this function 72/99 normalizes to {0,8,11,1} and 77/99 normalizes to {0,7,9,1}. But if we did a comparison of these normal forms, we find that 77/99 is less than 72/99!
A = carp(72/99, 1, 99) --> {0,8,11,1} B = carp(77/99, 1, 99) --> {0,7,9,1} compare(A,B) --> 1
whereas some better ways to compare them is ...
A = carp(72/99, 1, 99) --> {0,8,11,1} B = carp(77/99, 1, 99) --> {0,7,9,1} compare(A[2] * B[3],B[2] * A[3]) --> -1 compare(A[2] / A[3],B[2] / B[3]) --> -1
21. Re: Converting decimal number to carpenter's fractions
- Posted by K_D_R May 08, 2012
- 2350 views
For some things, decimals are easier. For other things, fractions are easier.
There are times when fractions are "cleaner" and more exact than are rounded decimals.
Please give me an example to illustrate your point.
I think the simplest example is 1/3. It has no exact representation, of course, in binary fractions (e.g., IEEE floating point numbers). Likewise, money fractions tend to be 1/100s, many of which cannot be represented exactly in binary fractions. It can be very important to get exact answers from calculations using these sorts of numbers where the errors introduced by binary approximations are unacceptable.
Matt
Just before logging on, I also thought of the example of 1/3 in terms of being easier to express than .33333... as Derek uses fractions in the code segment that inspired the original question. So, I understand that using fractions can be much easier to remember than long decimal numbers.
But as far as exactness and accuracy... 1/3 may be an exact expression, but that exactness gives an illusion of accuracy and does not appear to me to be more accurate than a rounded decimal, at least for the purpose at hand:
printf(1, "\n1/3 inch = %1.5fmm", 1/3 * 25.4) printf(1, "\n%1.1fmm = ", 1/3 *25.4) ?carp(1/3*25.4,mm_inch,128) puts(1, "1/3 inch, base 128 = ") ?carp(1/3, 1, 128) puts(1, "1/3 inch, base 16 = ") ?carp(1/3, 1, 16) puts(1, "43/128inch-5/16inch = ") ?carp(43/128-5/16,1,32)
1/3 inch = 8.46667mm 8.5mm = {0,43,128,1} 1/3 inch, base 128 = {0,43,128,1} 1/3 inch, base 16 = {0,5,16,1} 43/128inch-5/16inch = {0,1,32,1}
Did I do this right? The rounded decimal figure appears to be as accurate as the most accurate fraction. Also, I dare say it is much easier to use. My metric/inch tape measure is marked in 16ths of an inch. Simple rounding of the metric reading appears to be more accurate by 1/32", right?
Regards, Kenneth Rhodes
22. Re: Converting decimal number to carpenter's fractions
- Posted by DerekParnell (admin) May 08, 2012
- 2346 views
But as far as exactness and accuracy... 1/3 may be an exact expression, but that exactness gives an illusion of accuracy and does not appear to me to be more accurate than a rounded decimal, at least for the purpose at hand:
The effects of this can be more easily seen when we scale up the calculations.
atom a a = 0 for i = 1 to 300 do a += 2/3 end for printf(1, "%15.15f\n", a) --> 199.999999999999318 ? a = 200 --> 0 a = ((2 / 3) * 300) printf(1, "%15.15f\n", a) --> 200.000000000000000 ? a = 200 --> 1 a = 0 for i = 1 to 300 do a += 0.666666666666667 end for printf(1, "%15.15f\n", a) --> 199.999999999999346 ? a = 200 --> 0
23. Re: Converting decimal number to carpenter's fractions
- Posted by mattlewis (admin) May 08, 2012
- 2351 views
Did I do this right? The rounded decimal figure appears to be as accurate as the most accurate fraction. Also, I dare say it is much easier to use. My metric/inch tape measure is marked in 16ths of an inch. Simple rounding of the metric reading appears to be more accurate by 1/32", right?
As always, accuracy and precision don't mean much out of context. If the accuracy is good enough for your purpose, then it's good enough. For stuff like this, my ability to cut / position things is a lot less precise than 1/32". If you're calculating something in a financial context, people may get upset about a penny here or there.
Matt
24. Re: Converting decimal number to carpenter's fractions
- Posted by SDPringle May 08, 2012
- 2334 views
I was surprised by the common usage of U.S.-English measurement systems in Argentina of all places. I was under the impression that the rest of the world was completely metric and it was just in North America where we had the legacy of English measurements. Although wood is often sold using metric units (and with the same sizes as in Canada) often the person behind the counter is as versed in inches as he is in metric. With carpenter sized nuts and bolts as well common place.
25. Re: Converting decimal number to carpenter's fractions
- Posted by bill May 08, 2012
- 2340 views
Derek,
In answer to your questions:
There is no reasoning from {U,0,base} to {U,N,base}. So let me repeat myself ... \\ when the numerator is zero ... the value of the denominator is not really required; \\ it could be anything, so I may as well return something that could be useful. Useful to the caller, that is. To always return {U, 0, 1} when there is no fractional part is perfectly fine, except that its a waste of information bandwidth. This is not a mathematics environment; the function is trying to be useful to the caller by communicating information that may be gainfully employed by the application.
problem: compare for equality: {0, 0, 1, -1} {0, 0, 64, -1} {0, 0, 64, 1} they all equal zero yet they are all different. waste of bandwidth: another view on is: not providing misleading or spurious data.
Bill And as a consequence of that you get {U, 1, 64} = {U, 2, 128} = ... And (as stated) GCD(0,64) = 64. Normalised {U, 0, 64} = [U, 0, 1}. Comparing sizes you will see normalisation is a GOOD IDEA.
Im a bit confused by this. You seem to be suggesting that normalization is the process of presenting a fraction such that the numerator and divisor are the smallest integers possible to represent the value. And that such normalization is useful for comparison of values. If Ive got this wrong, please improve my understanding.
OK: 1. 72/99 * 63/87 * 255/2436 is going to produce a rather large fraction unless normalised. 2 there are an infinite number of unnormalised representations of 1/2 ... -1/-2,1/2 ... comparing a normalised fraction for equality is a/b = c/d if a=c and b=c comparing an unnormalised fraction is a/b = c/d if a*d = c*b the first is the less expensive operation (and particularly so for people) 255/2436 = 85/812?
If this is so, I beg to differ. Using this function 72/99 normalizes to {0,8,11,1} and 77/99 normalizes to {0,7,9,1}. But if we did a comparison of these normal forms, we find that 77/99 is less than 72/99! A = carp(72/99, 1, 99) --> {0,8,11,1} B = carp(77/99, 1, 99) --> {0,7,9,1} compare(A,B) --> 1
Well yes comparing them as sequences is silly.
whereas some better ways to compare them is ... A = carp(72/99, 1, 99) --> {0,8,11,1} B = carp(77/99, 1, 99) --> {0,7,9,1} compare(A[2] * B[3],B[2] * A[3]) --> -1 compare(A[2] / A[3],B[2] / B[3]) --> -1
Yes
function eq(rat a, rat b) return a[1]=b[1] and a[2]=b[2] end function function lt(rat a, rat b) return a[i]*b[2] = b[1]*a[2] end function
BTW as your function stands it still could be improved.
You do not require the denominator to be positive.
If it is 0 the function will blow up when it tries to do a remainder(0,0).
If it is negative it will return peculiar results.
26. Re: Converting decimal number to carpenter's fractions
- Posted by DerekParnell (admin) May 08, 2012
- 2321 views
I was surprised by the common usage of U.S.-English measurement systems in Argentina of all places.
I'm in Australia and work in a spare parts warehouse for automotive equipment. We are constantly working in both metric and imperial every day, sometimes on the same item. We have some hose/tubing whose length is in metric and diameter is in imperial (A customer asks for 1 meter of 5inch tube). Same with some belts; width is in metric and length is in inches.
27. Re: Converting decimal number to carpenter's fractions
- Posted by DerekParnell (admin) May 08, 2012
- 2322 views
BTW as your function stands it still could be improved.
Of course! Who's code couldn't be improved?
28. Re: Converting decimal number to carpenter's fractions
- Posted by useless_ May 11, 2012
- 2291 views
Did I do this right? The rounded decimal figure appears to be as accurate as the most accurate fraction. Also, I dare say it is much easier to use. My metric/inch tape measure is marked in 16ths of an inch. Simple rounding of the metric reading appears to be more accurate by 1/32", right?
As always, accuracy and precision don't mean much out of context. If the accuracy is good enough for your purpose, then it's good enough. For stuff like this, my ability to cut / position things is a lot less precise than 1/32". If you're calculating something in a financial context, people may get upset about a penny here or there.
Matt
Sometimes it matters. I just had some holes drilled, i spec'd 0.234 but was accepting 6mm (0.236). What i got was 0.232, and stuff simply didn't fit such a small hole. Just the same, i need to remove 0.001 from all around the hole perimeter, and 0.002 will be excessive, and the hole must remain round, so care is required, and proper measuring.
useless
29. Thanks for the function - works like a charm
- Posted by K_D_R May 13, 2012
- 2239 views
3-Frequency, Class 1, Method 1, Icosahedron: Current Unit of Measure: ft Dome Diameter: 39.000 Reference Diameter (Sphere): 39.587 Dome Radius: 19.500 Elevation: Riser Wall: 4.500 Bottom Hex Base: 11.295 Apex Bottom Pent: 15.494 Hex Vertex: 16.832 Top Pent Base: 19.694 Top Pent Apex: 20.896 Dome floor center to: edge:Pent Wall: 19.500 Center, Pent Wall: 19.087 Center, Long Wall: 17.789 Lengths: Pent Base/Wall: 7.988 Hex Base/LongWall: 15.975 Area: 1194.591 Circumferance: 122.522 Surface Area: 2461.698 Volume: 16242.057 Length PA/HA 1,1 1,0 7.988 ft = 95 27/32 inches Axial 0,0 1,0 1,1 78.359/11.641 Face 1,1 0,0 1,0 70.731 Face 1,1 2,1 1,0 58.583 Dihedral 1,1 1,0 168.641 Length HB:HC 2,1 2,0 8.163 ft = 97 31/32 inches Axial 0,0 2,0 2,1 78.100/11.900 Face 2,1 1,0 2,0 60.708 Face 2,1 3,1 2,0 60.708 Dihedral 2,1 2,0 166.421 Length PB:PC 3,1 3,0 6.900 ft = 82 13/16 inches Axial 0,0 3,0 3,1 79.962/10.038 Face 3,1 2,0 3,0 54.635 Dihedral 3,1 3,0 165.565 Length HA/PA 3,2 3,1 7.988 ft = 95 27/32 inches Axial 0,0 3,1 3,2 78.359/11.641 Face 3,2 2,1 3,1 58.583 Dihedral 3,2 3,1 165.542 Current unit of measure: ft Default Dome Diameter: 39.000 ft 1: Enter/change diameter of dome, expressed in current units) 2: Change current unit of measure from ft to: m cm mm in: 3: Enter/change height of riser wall, expressed in current units 4: Quit ----------------------------------------------------------------------- 3-Frequency, Class 1, Method 1, Icosahedron: Current Unit of Measure: cm Dome Diameter: 1188.720 (Sphere) Reference Diameter: 1206.625 Dome Radius: 594.360 Elevation: Riser Wall: 137.160 Bottom Hex Base: 344.265 Apex Bottom Pent: 472.262 Hex Vertex: 513.033 Top Pent Base: 600.260 Top Pent Apex: 636.921 Dome floor center to: edge:Pent Wall: 594.360 Center, Pent Wall: 581.760 Center, Long Wall: 542.207 Lengths: Pent Base/Wall: 243.466 Hex Base/LongWall: 486.932 Area: 1109810.989 Circumferance: 3734.474 Surface Area: 2286992.523 Volume: 459923846.840 Length PA/HA 1,1 1,0 243.466 cm = 95 27/32 inches Axial 0,0 1,0 1,1 78.359/11.641 Face 1,1 0,0 1,0 70.731 Face 1,1 2,1 1,0 58.583 Dihedral 1,1 1,0 168.641 Length HB:HC 2,1 2,0 248.813 cm = 97 31/32 inches Axial 0,0 2,0 2,1 78.100/11.900 Face 2,1 1,0 2,0 60.708 Face 2,1 3,1 2,0 60.708 Dihedral 2,1 2,0 166.421 Length PB:PC 3,1 3,0 210.324 cm = 82 13/16 inches Axial 0,0 3,0 3,1 79.962/10.038 Face 3,1 2,0 3,0 54.635 Dihedral 3,1 3,0 165.565 Length HA/PA 3,2 3,1 243.466 cm = 95 27/32 inches Axial 0,0 3,1 3,2 78.359/11.641 Face 3,2 2,1 3,1 58.583 Dihedral 3,2 3,1 165.542 Current unit of measure: cm Default Dome Diameter: 1188.720 cm 1: Enter/change diameter of dome, expressed in current units) 2: Change current unit of measure from cm to: m mm in ft: 3: Enter/change height of riser wall, expressed in current units 4: Quit
30. This is why I like the metric System...
- Posted by K_D_R May 15, 2012
- 2222 views
The text in the previous post would have sufficed, I guess. Seems I have been able to post pics from Flickr here before.
But, Length PA/HA 1,1 1,0 243.466 cm = 95 27/32 inches
Without onerous calculations anyone can easily "see" that 243.466 cm = = 2 meters, 43cm, 4.66mm and round that 4.6mm to 5mm's with confidence as 4.6mm and 5mm both convert to 3/16ths of an inch, even with a "base" of 64. It amounts to rounding up 1/64 inch. Once again, my point here is that for carpentry work a metric measure is incredibly easier to use with virtually no loss of accuracy as most tape measures are list only 16th's of an inch, or 32nd's, at best.
[url=http://www.flickr.com/photos/51759584@N07/7202440250/][img]http://farm8.staticflickr.com/7231/7202440250_a16bb8f490_z.jpg[/img][/url] [url=http://www.flickr.com/photos/51759584@N07/7202440250/]3v39ftcm[/url] by [url=http://www.flickr.com/people/51759584@N07/]Kenneth Rhodes[/url], on Flickr