473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

128 bit number implementation


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

Jul 23 '05 #1
8 3977
John wrote:
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

Jul 23 '05 #2
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 :(

Jul 23 '05 #3
John wrote in news:11*********************@g44g2000cwa.googlegro ups.com
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...gned_int/uint-
promotion.html#msvc-workaround>
Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 23 '05 #4

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

Jul 23 '05 #5
John wrote in news:11**********************@f14g2000cwb.googlegr oups.com in
comp.lang.c++:

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


<http://www.victim-prime.dsl.pipex.co...ned_int/shift-
unsigned.html>

<http://www.victim-prime.dsl.pipex.co..._int/multiply-
unsigned.html>

IOW, Yes.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 23 '05 #6
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

Jul 23 '05 #7
John wrote in news:11**********************@g47g2000cwa.googlegr oups.com
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
I'd have a workng and portable signed_int< 64> and unsigned_int< 64 >
types.
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.
--
http://www.victim-prime.dsl.pipex.com/
Jul 23 '05 #8
Perfect :)

Thanks,
--j

Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Vasilis Serghi | last post by:
Presently I define the number of lines to be expected in a file when defining the array size and the initialisation of this array. This works fine for now, but i'm sure that in the future this...
7
by: vikky | last post by:
hi all, Out of sheer curosity, I decided to initialize an integer with a number bigger than INT_MAX, however I still am not able to justify its output. Here is the program : #include<stdio.h> ...
4
by: Rubbrecht Philippe | last post by:
Hi there, I would like to develop an interface that when implemented in a class requires a number of shared properties or methods to be available. It seems a Shared Member can not be used as...
5
by: Heiko Wundram | last post by:
Hi all! I'm wondering whether there is some form of number set type implemented in pure Python. I'm currently in the process of implementing one myself (for an IPv4 address range type), and if...
27
by: Simon Biber | last post by:
The following Example 3 is given in the 1999 C standard for the function fscanf: I have tested several implementations and none of them get the last case right. In no case does fscanf return 0...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
0
by: JosAH | last post by:
Greetings, Introduction At this moment we have a TextProcessor, a LibraryBuilder as well as the Library itself. As you read last week a Library is capable of producing pieces of text in a...
25
by: Daniel Kraft | last post by:
Hi, I do need to implement something similar to C++'s std::bitset in C; for this, I use an array of int's to get together any desired number of bits, possibly larger than 32/64 or anything like...
11
by: magicman | last post by:
can anyone point me out to its implementation in C before I roll my own. thx
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.