473,221 Members | 2,048 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,221 software developers and data experts.

128 or 96 bit integer types?

Hi,

Is there build-in or third party support for large integer types, such
as 96 or 128 bits in size? I require such large sizes for precision
issues (nanoseconds). Thanks.

Jul 27 '07 #1
10 14022
On Fri, 27 Jul 2007 16:45:05 +0000, Robert Dailey wrote:
Is there build-in or third party support for large integer types, such
as 96 or 128 bits in size?
Yes there is, just use integer values. If it don't fit into an `int` it
gets promoted to a `long`. Python `long`\s are only bounded by available
memory.

In [59]: 2**128
Out[59]: 340282366920938463463374607431768211456L

Ciao,
Marc 'BlackJack' Rintsch
Jul 27 '07 #2
Robert Dailey wrote:
Is there build-in or third party support for large integer types, such
as 96 or 128 bits in size? I require such large sizes for precision
issues (nanoseconds). Thanks.
>>SECOND = 10**9
YEAR = 365*24*60*60
2**128/SECOND/YEAR
10790283070806014188970L

What are you measuring? The age of the universe? In nanoseconds?

:-)

Peter
Jul 27 '07 #3
On Jul 27, 1:27 pm, Peter Otten <__pete...@web.dewrote:
Robert Dailey wrote:
Is there build-in or third party support for large integer types, such
as 96 or 128 bits in size? I require such large sizes for precision
issues (nanoseconds). Thanks.
>SECOND = 10**9
YEAR = 365*24*60*60
2**128/SECOND/YEAR

10790283070806014188970L

What are you measuring? The age of the universe? In nanoseconds?

:-)
Well, 2**96 would only be 2512308552583 years.
>
Peter

Jul 27 '07 #4
"me********@aol.com" <me********@aol.comwrote:
>
On Jul 27, 1:27 pm, Peter Otten <__pete...@web.dewrote:
>Robert Dailey wrote:
Is there build-in or third party support for large integer types, such
as 96 or 128 bits in size? I require such large sizes for precision
issues (nanoseconds). Thanks.
SECOND = 10**9
YEAR = 365*24*60*60
2**128/SECOND/YEAR

10790283070806014188970L

What are you measuring? The age of the universe? In nanoseconds?

:-)

Well, 2**96 would only be 2512308552583 years.
Yes, but that's still roughly 100 times the estimated age of the universe.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 28 '07 #5
"me********@aol.com" <me********@aol.comwrites:
has 146 digits. And that's just the begining. The above
actually represents a polynomial with 264 terms, the
exponents of which range from 0 to 492. One of those
polynomials can have over 50000 decimal digits when
solved.
You should use gmpy rather than python longs if you're dealing with
numbers of that size. Python multiplication uses a straightforward
O(n**2) algorithm where n is the number of digits. This is the best
way for up to a few hundred or maybe a few thousand digits. After
that, it's better to use more complicated FFT-based algorithms which
are O(n log n) despite their increased constant overhead. Gmpy does this.
Jul 28 '07 #6
On Jul 28, 2:28?am, Paul Rubin <http://phr...@NOSPAM.invalidwrote:
"mensana...@aol.com" <mensana...@aol.comwrites:
has 146 digits. And that's just the begining. The above
actually represents a polynomial with 264 terms, the
exponents of which range from 0 to 492. One of those
polynomials can have over 50000 decimal digits when
solved.

You should use gmpy rather than python longs if you're dealing with
numbers of that size. Python multiplication uses a straightforward
O(n**2) algorithm where n is the number of digits. This is the best
way for up to a few hundred or maybe a few thousand digits. After
that, it's better to use more complicated FFT-based algorithms which
are O(n log n) despite their increased constant overhead. Gmpy does this.
I actually do use gmpy. Great stuff. But one thing I
learned about gmpy is to never use literals inside
a loop. Otherwise the mpz coercion has to be done
every time and that kills performance.

So you would do something like

import gmpy
ONE = gmpy.mpz(1)
TWO = gmpy.mpz(2)
TWE = gmpy.mpz(3)

n = gmpy.mpz(2**177149-1)

while n ONE:
if n % TWO == 1
n = TWE*n + ONE
else:
n = n/TWO

Jul 28 '07 #7
Paul Rubin wrote:
"me********@aol.com" <me********@aol.comwrites:
>has 146 digits. And that's just the begining. The above
actually represents a polynomial with 264 terms, the
exponents of which range from 0 to 492. One of those
polynomials can have over 50000 decimal digits when
solved.

You should use gmpy rather than python longs if you're dealing with
numbers of that size.
Python multiplication uses a straightforward
O(n**2) algorithm where n is the number of digits.
That's untrue since quite a while. CPython now uses
Karatsuba-multiplication if the number of digits is larger than a
certain threshold. Karatsuba is O(n**(log(3) / log(2)).
This is the best
way for up to a few hundred or maybe a few thousand digits. After
that, it's better to use more complicated FFT-based algorithms which
are O(n log n) despite their increased constant overhead. Gmpy does this.
Karatsuba is still slower than these algorithms, but only if you have
quite a big number of digits. Of course the core of your argument
remains valid: CPython is not up to providing extremely good big integer
arithmetic, so if you have extreme needs, you shouldn't use the builtin
longs.

Cheers,

Carl Friedrich Bolz
Jul 29 '07 #8
Paul Rubin wrote:
"me********@aol.com" <me********@aol.comwrites:
>has 146 digits. And that's just the begining. The above
actually represents a polynomial with 264 terms, the
exponents of which range from 0 to 492. One of those
polynomials can have over 50000 decimal digits when
solved.

You should use gmpy rather than python longs if you're dealing with
numbers of that size.
Python multiplication uses a straightforward
O(n**2) algorithm where n is the number of digits.
That's untrue since quite a while. CPython now uses
Karatsuba-multiplication if the number of digits is larger than a
certain threshold. Karatsuba is O(n**(log(3) / log(2)).
This is the best
way for up to a few hundred or maybe a few thousand digits. After
that, it's better to use more complicated FFT-based algorithms which
are O(n log n) despite their increased constant overhead. Gmpy does this.
Karatsuba is still slower than these algorithms, but only if you have
quite a big number of digits. Of course the core of your argument
remains valid: CPython is not up to providing extremely good big integer
arithmetic, so if you have extreme needs, you shouldn't use the builtin
longs.

Cheers,

Carl Friedrich Bolz

Jul 29 '07 #9
In article <11*********************@x40g2000prg.googlegroups. com>,
me********@aol.com <me********@aol.comwrote:
To actually answer you question, there is a known loop
cycle in 3n+85085 for which p=492 and q=264. If there is
one solution, there must be at leats 263 others (the
cyclic permutations), but to brute force search for any
others would require enumerating the answer to how many
ways can 492 marbles be put in 264 bins such that each
bin has at least 1 marble.
Thank you very much. I am awestruck.

--
David Wild using RISC OS on broadband
www.davidhwild.me.uk
Jul 29 '07 #10
"me********@aol.com" <me********@aol.comwrote:
>
So I never let the age of the universe intimidate me.
+1 QOTW.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 30 '07 #11

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

Similar topics

14
by: David Fisher | last post by:
The most common sizes of integer types seem to be: 8 bits - signed char 16 bits - short 16 or 32 bits - int 32 or 64 bits - long Question #1: Does anyone know how common sizes other than...
28
by: Timothy Madden | last post by:
Hello I've read here that only C language has a standard 64bit integer. Can you please tell me what are the reasons for this ? What is special about C language ? Can you please show me some...
13
by: Shailesh Humbad | last post by:
I wrote a short page as a quick reference to c++ integer data types. Any feedback welcome: http://www.somacon.com/blog/page11.php
17
by: Mantorok Redgormor | last post by:
are all integers represented internally as just bit vectors? -- nethlek
61
by: John Baker | last post by:
When declaring an integer, you can specify the size by using int16, int32, or int64, with plain integer being int32. Is integer the accepted default in the programming community? If so, is...
6
by: comp.lang.php | last post by:
I'm involved in a rather nasty debate involving a strange issue (whereby the exasperated tell me to RTFM even after my having done so), where this is insanely possible: print_r(is_int('1'));...
21
by: Frederick Gotham | last post by:
I set about trying to find a portable way to set the value of UCHAR_MAX. At first, I thought the following would work: #define UCHAR_MAX ~( (unsigned char)0 ) However, it didn't work for me....
1
by: charles_gero | last post by:
Hi all, I had a question about the topics in the subject and posted to comp.std.c, but feel it may also be appropriate here. Please excuse this crosspost if it is in bad form. I have a...
159
by: Bob Timpkinson | last post by:
Hi, I have a 32-bit machine... Is there anyway I can get gcc to use the following integer sizes? char: 8 bits short: 16 bits int: 32 bits long: 64 bits long long: 128 bits
130
by: euler70 | last post by:
char and unsigned char have specific purposes: char is useful for representing characters of the basic execution character set and unsigned char is useful for representing the values of individual...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.