On Monday, 30 September 2013 at 12:14:10 UTC, Joseph Rushton
Wakeling wrote:
On 27/09/13 20:20, Walter Bright wrote:
On 9/27/2013 6:47 AM, Joseph Rushton Wakeling wrote:
[...]
Sounds like we have a new champion! Thanks, Joseph!
I've opened up issue tracking on my fork of std.rational:
https://github.com/WebDrake/Rational/issues
This includes the greatest-common-factor bug discovered by
MrSmith and others that I've identified on detailed
consideration of the code. Some are more "need to check out
how this works" rather than "it's a problem" style issues.
Quite a few issues arise out of the fact that David Simcha
obviously wanted the rational type to work effectively with any
well-defined integer type of any degree of precision -- from
the built-in types to std.bigint.BigInt to any arbitrary
user-defined integer types. (I can imagine that David must
have been anticipating that people might want to use GMP, for
example, or to hook into languages that inherently support
arbitrary-precision arithmetic, like Common Lisp, Haskell or
Scheme.)
Most Phobos functions don't have such generic support, so David
was forced to roll his own solutions, including some templates
(isIntegerLike, CommonInteger) to handle these use-cases. In
one case (his least-common-multiple function) there is in any
case no Phobos equivalent that I'm aware of.
It seems to me that the best way to handle these issues in the
long term is to ensure that Phobos' existing functions are
sufficiently generic to handle what std.rational needs.
However, it'd be nice to get a working std.rational in place as
soon as possible.
So -- what do people advise I do? Take what I can out of
std.rational and submit Phobos patches, or patch it up as it is
and submit std.rational for review, with the review process
deciding what stays in and what needs to be farmed out to other
parts of Phobos?
Here is my thoughts:
1) instead of gcf use updated std.numeric.gcd. Replace lcm, iAbs,
floor, ceil, round functions with appropriate analogues from
phobos.
2) instead of isIntegerLike use similar template from std.traits
(like isIntegral).
3) replace isAssignable by std.traits.isAssignable or better use
std.traits.isImplicitlyConvertible. Now i am unable to assign
integer directly to rational, instead i am forced to use
rational(integer) method;
4) replace CommonInteger by std.traits.CommonType