|
Philippe, Thanks for your review. See replies to specific points below. On 8/28/2010 10:24 AM, Philippe Sigaud wrote:
Don't worry about module issues. As Lars pointed out, the library will not be named rational if/when it's integrated into Phobos. It will be std.rational or be included in std.numerics.
I fixed this right after I sent out the request for comment, because I realized that not allowing it was a bit silly. Unfortunately, I accidentally sent a link that pointed to a specific revision. Here's a new link that updates will be reflected in: http://dsource.org/projects/scrapple/browser/trunk/rational/rational.d
I can't believe I forgot to test this edge case. Fixed by simply testing for zero as a special case in simplify().
Good point. Done. Also added comparison.
You may be right, but I'd rather wait until more user defined integer and floating point types are around to see exactly what such templates should require.
Good point. Fixed.
No particular reason. Any reasonable type should return the same type for either one. I can't see why it would matter either way.
I'd rather leave it as a free function for a few reasons: 1. In general the convention in Phobos is that non-trivial construction steps for structs are done in free functions. Even though the reasons for that convention don't apply here, I'd rather follow it unless there's really a good reason to violate it. 2. IIRC templated constructors are generally buggy, though I can't remember specifically how they're buggy. 3. Lower case names are easier to type and read. 4. It's what I already have written and I'm lazy. :-) I don't feel very strongly about this, though. If you really feel strongly that it should be a constructor, though, and can explain why, then I'm willing to reconsider.
I think GCF is already in there. I rolled my own so that I could tweak it easily to make it do exactly what I want with regard to types, but in the long run you're right that it should be included in std.numerics and whatever changes I made should be merged.
This is a great idea, and trivial to implement. I'll add it as soon as I decide for sure what to do about the user-defined fixed width issue.
Ditto.
Again, good idea. Using std.math sucks because a major point of Rational is that it's supposed to work with arbitrary precision, and reals aren't arbitrary precision.
Probably not. I really despise NaNs in floating point code because they break fundamental mathematical axioms that appear to be common sense (such as x == x, x * 0 == 0, if !(x <= y) then x > y, and x < y || x == y || x > y). For example, try making a sorting algorithm or a binary tree with floating point numbers if they may be NaNs. I'd rather just leave it the way it is, where it throws if the denominator is zero.
I think what I'm going to do here is just throw an exception iff the denominator has both the highest and lowest order bit set. This is enough of a corner case in that it will only happen close to the limit of the largest denominator value that can be represented that I don't consider it a major limitation. It's easily detectable because the numerator will never become bigger than the denominator by bit shifting iff either the numerator is zero or the denominator has its highest order bit set. If the denominator's lowest order bit isn't set then I can shift the denominator right to make it not have its highest order bit set. If anyone has any better ideas, or considers this too severe a limitation, let me know.
This code has been around in some form for almost a year. It's just that the proposal for a units library made me remember that I've been meaning to clean up all the bit rot, improve it and submit it for inclusion.
Great. I look forward to when this code is ready. |
_______________________________________________ phobos mailing list [email protected] http://lists.puremagic.com/mailman/listinfo/phobos
