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.