Re: Converting decimal number to carpenter's fractions
- Posted by DerekParnell (admin) May 08, 2012
- 2775 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

