On 2012-44-08 06:10, Arlen <arlen...@gmx.com> wrote:

On Sat, Oct 6, 2012 at 1:32 PM, Dmitry Olshansky <dmitry.o...@gmail.com> wrote:

Cool, does it work with BigInt?


No it doesn't work with BigInt, but I did look into it today briefly.
There are issues with BigInt that I'm not sure what to do about:

1.  To convert a BigInt to floating-point one needs to convert it to
the built-in integer types first.  If you go beyond the limits of the
built-in types (long), then what's the point?  You might as well be
using int or long.

I thought (part of) the point of Rational was to use it when it would
be more fitting than floating-point. If it's only there to be converted
to floating-point, I don't know what it's there for.

As for a workaround, right-shift num and den to reasonable values
(which fit in a long), divide to get a float, and multiply by
2.0^^(log2(num)-log2(den)). Oughta work.


2.  The functions in std.math don't support BigInt, and most likely
never will.  Even if they did, you would still need multi-precision
floating point to store the irrational numbers.  If you decided to use
the built-in types, then again what's the point?  You might as well go
with int or long.

The only function you use from std.math is abs, right? That should be
fairly easy to implement for BigInt.

It'd mean you'd have to specialize a bit for BigInt, though (just
create your own abs function that calls the correct one).

Another option: lobby for BigInt support in std.math. :p


Also, irrational numbers? How'd you get those in a *Rational* library? :p


--
Simen

Reply via email to