On Mon, Oct 8, 2012 at 2:08 AM, Simen Kjaeraas <[email protected]> wrote: > On 2012-44-08 06:10, Arlen <[email protected]> wrote: > >> >> 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. >
Some computations with rational numbers produce irrational numbers, and to store irrational numbers you need real numbers. What do we do in those cases? > 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). > Yes, std.math.abs and std.numeric.gcd are very easy to implement for BigInt, but I'm not talking about those. I'm talking about things like std.math.pow(), and std.math.log().
