On Mon, Oct 08, 2012 at 09:08:57AM +0200, Simen Kjaeraas wrote: > 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.
I'd like to chime in to state that I'd love to have Rational support BigInt. If necessary, use an arbitrary-width floating point format for floating point conversions (BigFloat?). [...] > 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 +1. > Also, irrational numbers? How'd you get those in a *Rational* library? :p [...] Ironically enough, if Rational supports BigInt, then it makes it possible to implement a representation of quadratic irrationals in a straightforward way (by storing them in the form a+b*sqrt(r) where a and b are Rationals and r is a square-free Rational). The reason BigInt is necessary is that while these things are closed under field operations, any non-trivial work with them tends to overflow built-in integer types very quickly. BigInt becomes even more necessary if you want to represent quadratic irrationals of *two* distinct square roots, which can be represented as a+b*sqrt(r)+c*sqrt(s)+d*sqrt(rs), where a,b,c,d are Rationals and r,s are square-free Rationals. Believe it or not, these little monsters are also closed under field operations. But they also overflow built-in integers *very* fast. With BigInt support, however, you can do *exact* arithmetic with these irrational numbers, something very useful for applications in computational geometry, where the lack of exact arithmetic makes many problems intractible or prone to wrong results. T -- I'm still trying to find a pun for "punishment"...