[GiNaC-list] Possible size issue in test in numeric.cpp
Pierangelo Masarati
masarati at aero.polimi.it
Wed Aug 16 17:45:51 CEST 2006
Jens Vollinga writes:
>> I agree it should be
>> i < ((1UL << cl_value_len)-1)
>
> well, I have to correct myself: it should be
> i < (1UL << cl_value_len)
> I guess.
Right, sorry. I obviously had <= in mind :)
>
> But still I want to wait for Richy's response before I put it in CVS,
> because it could be that CLN uses a signed data representation for small
> integers internally (crazy idea, but conceivable ... ;-)) so that the
> original if clause might be correct.
>
Looking at recent CLN stuff, I see that the internal representation of any
type of data is a word, which is basically a "cl_uint" (in cln/object.h:
typedef uintP cl_uint; // This ought to be called `cl_word'.
where
typedef unsigned long uintP;
:)
It doesn't really care about signedness until the value is extracted and
shifted back to its position.
I haven't looked into CLN's CVS yet, though, but this looks like something
that shouldn't change quite often. However, since applications using CLN
shouldn't be aware of those details, I'm getting convinced that the
optimization you're trying to obtain in numeric.cpp should actually be moved
to CLN, in the sense that being CLN a likely candidate as a building block
for higher-level numerical libraries (like GiNaC, for example), it should
provide means for safe and efficient machine and OS independent conversion
between its internal representation and built-in types. Details about how
to implement it are beyond the scope of this message; it could be by
providing standard limits for the builtin types (like INT_MAX, UNIT_MAX and
so in limits.h) or a test (sort of SAFE_CAST_TO_INT(x), SAFE_CAST_TO_UINT(x)
and similar) or so.
Cheers, p.
Dr. Pierangelo Masarati | voice: +39 02 2399 8309
Dip. Ing. Aerospaziale | fax: +39 02 2399 8334
Politecnico di Milano | mailto:pierangelo.masarati at polimi.it
via La Masa 34, 20156 Milano, Italy | http://www.aero.polimi.it/~masarati
Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
More information about the GiNaC-list
mailing list