Giant constant numbers.

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

Giant constant numbers.

Unread post by kingchris » 7 Aug 2017 15:26

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.


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

Unread post by Thomas Linder Puls » 7 Aug 2017 19:24

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

Martin Meyer
VIP Member
Posts: 279
Joined: 14 Nov 2002 0:01

Unread post by Martin Meyer » 7 Aug 2017 23:47

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.
(12.24 KiB) Downloaded 130 times
Regards Martin

Active Member
Posts: 26
Joined: 26 Sep 2005 9:35

Unread post by kingchris » 8 Aug 2017 5:54

Thanks gentlemen for your assistance.

Much appreciated

Post Reply