Discussions related to Visual Prolog
kingchris
Active Member
Posts: 28
Joined: 26 Sep 2005 9:35

Giant constant numbers.

Post by kingchris »

If I am doing some odd maths how does one get large numbers into integer64 variables and constants.

There is a unsigned64:value function I think that takes two parameters.

One of my constants is 80 characters for I might have to call a 128 bit library.

In C and C++ one always added a L to the end of your number constant.

unsigned var = 7362398263876L;

I believe that C++ 11 has 128 bit numbers now.

Cheers
User avatar
Thomas Linder Puls
VIP Member
Posts: 1469
Joined: 28 Feb 2000 0:01

Post by Thomas Linder Puls »

I do not think there are 128 bit numbers (by default) in C++ 11, but it is not something I know for sure.

However, the 'L' in C/C++ literals indicates a 64 bit number.

I Visual Prolog you can use the types unsigned64 and integer64 and you do not need to use any special marks to write such numbers:

Code: Select all

constants    value : unsigned64 = 7362398263876.   class predicates     p : (unsigned64 X) -> unsigned64 Y. clauses     p(X) = 7362398263876 + value + X.
unsigned64 have the range [0..18446744073709551615].
integer64 have the range [-9223372036854775808..9223372036854775807].

128 bit numbers cannot hold a 80 digit number, the largest number in an 128 bit unsigned is 2^128 ~ 3,4e38 (i.e. 39 digits).

A real can hold very large numbers, but (only) with ~15 digits precision.
Regards Thomas Linder Puls
PDC
Martin Meyer
VIP Member
Posts: 354
Joined: 14 Nov 2002 0:01

Post by Martin Meyer »

Hello Chris (and Thomas and all),

the below attached project gives an example how one could deal with numbers which exceed the limits of the build-in number domains. The example implements large unsigned integer numbers encoded in binaries. The implemented arithmetics uses however only the -simple- school methods. For multiplication and especially for division faster (but more complicated) algorithms are known.
You do not have the required permissions to view the files attached to this post.
Regards Martin
kingchris
Active Member
Posts: 28
Joined: 26 Sep 2005 9:35

Post by kingchris »

Thanks gentlemen for your assistance.

Much appreciated