Sam Steingold on Fri, 28 May 2010 19:49:10 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: integer representation in pari |
On 5/28/10, Karim Belabas <Karim.Belabas@math.u-bordeaux1.fr> wrote: > * Bill Allombert [2010-05-28 18:26]: > > On Fri, May 28, 2010 at 11:13:11AM -0400, Sam Steingold wrote: > > > On 5/27/10, Bill Allombert <Bill.Allombert@math.u-bordeaux1.fr> wrote: > > > > > > > > You can also check whether the C macro PARI_KERNEL_GMP is defined, > > > > but usually it is better to use int_W() to acces the mantissa. > > > > > > thanks! > > > can I also use int_W to access the mantissa of a t_REAL? > > > (it never explicitly says that, but ...) > > > > No you cannot. t_REAL mantissa is always in HIGH bytes first, > > so this would not work with the GMP kernel. Note that > > t_REAL mantissa is normalized (i.e. first bit is one). > > All this may change (in fact, it *will* change : it is very annoying to > have different internal representations for t_INTs and t_REALs). indeed. > In general, direct access to an object's internal representation is > strongly discouraged. understandably so. > In the 2.4.* branch (2.5-stable-to-be), you can use trunc2nr() or > trun2nr_lg() to recover any part of the matissa as a t_INT. > > Btw, why do you want to access words of a t_REAL mantissa in the first place ? I want to be able to convert a PARI number (integer or real) to a Lisp number. for that, I need something equivalent to the following API: ulong get_integer_length (GEN gint); /* already present as lgef() */ void get_integer_data (GEN gint, ulong *data); to be used like this: ulong len = get_integer_length(gint); ulong *data = (ulong*)alloca(len*sizeof(ulong)); get_integer_data(gint,data); and a similar interface for reals: ulong get_real_length (GEN greal); /* already present as lgef() */ ulong get_real_exponent (GEN greal); /* already present as expo() */ void get_real_mantissa (GEN greal, ulong* data); to be used like this: ulong len = get_real_length(greal); ulong *data = (ulong*)alloca(len*sizeof(ulong)); get_real_mantissa(greal,data); where the words in data and mantissa are returned in some fixed order (platform- and library-independent). -- Sam Steingold <http://sds.podval.org>