128 bit number implementation

J

John

Does anyone know of a 128bit number implementation?
I can use "long long" to get 64 bit numbers on my machine.
Anyone has "paired" two longs together using simd/code
to do this? Is this available in any particular compiler?

Thanks,
--j
 
P

Puppet_Sock

John said:
Does anyone know of a 128bit number implementation?
I can use "long long" to get 64 bit numbers on my machine.
Anyone has "paired" two longs together using simd/code
to do this? Is this available in any particular compiler?

Search back through the archives for things like
"arbitrary accuracy" and "very long integers" and
things like that. There have been posts on libs with
numerical accuracy of arbitrary length. Of course,
you will find that things get slower with longer
numbers, in some cases much slower. There is also,
of course, an overhead to having the mechanism for
unlimited accuracy even when you do calcs that only
require a regular number of digits.
Socks
 
J

John

I have used gmp and cln before. But I want is a pair of 64 bit numbers
and no additional overhead except what is required. Anyone who
has seen this implemented somewhere? A class that can make sure
that when the precision for one "long long" is not enough, it can
switch
to two "long long";s? or can just give me an interface to use two
"long long"s. It seems that gmp and cln have other overheads and
are overkill for what i need.

Probably in a year or two, this 128 bit number will come bundled
with the machine and the compiler, just not now :(
 
R

Rob Williscroft

John wrote in
in comp.lang.c++:
Does anyone know of a 128bit number implementation?

You can try the 2 libs "unsigned_int< N >" and "signed_int< N >"
on my home page:

http://www.victim-prime.dsl.pipex.com/
I can use "long long" to get 64 bit numbers on my machine.
Anyone has "paired" two longs together using simd/code
to do this?

My libs don't "simd" (Single Instruction Multiple Data - I had
to google :) ).
Is this available in any particular compiler?

Its been tested on various versions of g++ (IIRC 3.3, 3.4 and a
beta of 4.0) and MSVC++ 7.1, though that does have some limitations:

<http://www.victim-prime.dsl.ppex.com/docs/signed_int/uint-
promotion.html#msvc-workaround>


Rob.
 
J

John

Thanks, dont need simd. But do they implement everything , like
shifts, multplies etc...?
 
J

John

Is there a way to change the internal representation from "unsigned"
to "unsigned long long".

Also in my application each number has fixed number of bits. 128
So I dont really wanna store

enum uint_enum_t
{
NBits = N,
NWords = NWORDS_IMP_( N )
};


for every number, can I make it static or better a global constant?

Thanks,
--j
 
R

Rob Williscroft

John wrote in
in comp.lang.c++:
Is there a way to change the internal representation from "unsigned"
to "unsigned long long".

No.

I use unsigned as its standard (and thus portable), "unsigned long long"
or __ulong_long or ULONGLONG or whatever its called on any given
implementation isn't.

Also I've seen implementations of "long long" (i.e. 64 bit types) that
simply don't work. They don't add up, at least not correctly :).

In fact this was part of the motivation for writing the library so
Also in my application each number has fixed number of bits. 128
So I dont really wanna store

enum uint_enum_t
{
NBits = N,
NWords = NWORDS_IMP_( N )
};

The enum is only used to do a compile time calculation, no instances are
ever created. If I had started writing this lib' with a modern compiler,
say g++ 3.4 or MSVC++ 7.1, I would have probaly static intergral
constants to do this, but the was a time when enum's were more portable.
for every number, can I make it static or better a global constant?

Enumaration values are compile time constants, and no it can't be global
as its dependant on a template paramiter, N above.

On a 32 bit machine (typical windows/x86 desktop) you should find:

sizeof( imp::unsigned_int< 128 > ) == 16.

I.e. it 4 * 4 byte (32 bit) unsigned's big.

Rob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top