What's wrong with long long?

M

Michael B Allen

I use long longs occasionally. I know there are some limitations regarding
the standards such as not using long long constants but what's the big
deal? Why is long long not used so much?

Mike
 
J

Joe Wright

Michael said:
I use long longs occasionally. I know there are some limitations regarding
the standards such as not using long long constants but what's the big
deal? Why is long long not used so much?

Mike

I've played with long long but I don't remember using it in a
program. I'm sure that if programming problem arises that requires
integers larger than +-2 or +4 billion, I will use long long quite
naturally.
 
T

Tim Prince

Michael B Allen said:
I use long longs occasionally. I know there are some limitations regarding
the standards such as not using long long constants but what's the big
deal? Why is long long not used so much?
Some people are still using Microsoft compilers which reject long long.
Apparently, MS are using macros such as ULONG64 in some of their headers.
I've asked some of their fans about the rationale for this, and got total
silence as an answer. long long appears to have reached full citizenship in
the recent round of MS road shows.
I have a version of their compiler which does support long long, and yet is
to be obsoleted at the end of the year, along with those which don't. Are
you implying that none of the Microsoft compilers support long long
constants? It's true that MS compilers may not take long constants as long
long.
Would you care to bet on the likelihood of people who still claim that long
long isn't standard changing their mind 6 months from now when MS stops
"supporting" compilers which reject it?
 
M

Malcolm

Michael B Allen said:
Why is long long not used so much?
A number must ultimately represent something in the real world. You seldom
need a number above 4 billion, which is about the number of adults in the
world. An exception is memory size, which can exceed 4GB on large systems
and may soon be around that on desktop PCs, but in C we use size_t for
amounts of memory.
 
D

Dan P.

Malcolm said:
A number must ultimately represent something in the real world. You seldom
need a number above 4 billion, which is about the number of adults in the
world. An exception is memory size, which can exceed 4GB on large systems
and may soon be around that on desktop PCs, but in C we use size_t for
amounts of memory.


This will change soon as we move to IPv6. Networking will be one
application where >32bit numbers are required.



Dan
 
K

Keith Thompson

Dan P. said:
This will change soon as we move to IPv6. Networking will be one
application where >32bit numbers are required.

An IPv6 address is 128 bits, but I don't think it's typically
represented as a single number. I don't know of any systems that
directly support 128-bit integers anyway. (Counterexamples would not
contradict my main point.)
 
C

CBFalconer

Keith said:
.... snip ...

An IPv6 address is 128 bits, but I don't think it's typically
represented as a single number. I don't know of any systems
that directly support 128-bit integers anyway. (Counterexamples
would not contradict my main point.)

That should last throught the first Galactic Empire and the fall
of Trantor :)
 
J

Jack Klein

A number must ultimately represent something in the real world. You seldom
need a number above 4 billion, which is about the number of adults in the
world. An exception is memory size, which can exceed 4GB on large systems
and may soon be around that on desktop PCs, but in C we use size_t for
amounts of memory.

What an absurd line of reasoning. Are you actually this clueless, or
just trolling?

On a heavy trading day on the US stock exchanges, the number of shares
traded on the NASDAQ exchange can exceed the maximum value of a signed
32-bit long int.

I seem to recall, but can't be bothered to look up, that there have
been days when the sum of shares traded on the AMEX and NASDAQ
exchanges exceeded the maximum value of an unsigned 32-bit long.

Not to mention the fact that a large number of simple mathematical and
statistical algorithms, often most efficiently implemented with
integer math, require raising numbers to the second power. The range
of the second power of numbers that fit in a 32-bit integer type most
certainly will not fit in anything less than a 64-bit integer type.
 
C

Christian Bau

Jack Klein said:
Not to mention the fact that a large number of simple mathematical and
statistical algorithms, often most efficiently implemented with
integer math, require raising numbers to the second power. The range
of the second power of numbers that fit in a 32-bit integer type most
certainly will not fit in anything less than a 64-bit integer type.

I think in one of Donald Knuth's book there was a trick question: What
is the fastest algorithm to calculate n raised to the 19th power? The
answer was: Since the result must fit into n bits, the argument can be
at most (some tiny number), so the fastest method is a lookup-table...
 
M

Malcolm

Jack Klein said:
On Sun, 13 Jun 2004 15:05:48 +0100, "Malcolm"


What an absurd line of reasoning. Are you actually this clueless, > or just trolling?

On a heavy trading day on the US stock exchanges,
So you've come up with another exception. No-one is claiming that never ever
will you need a number over 4 billion. Clearly, if you need to give an id
number to the entire population of the world, or you need to tag every US
cent in circulation, or you are doing some fancy statistical work that
generates large integers, then these are exceptions. However the exceptions
don't arise very often, which is why you will seldom see long long used in
real programs.
 
G

Gordon Burditt

What an absurd line of reasoning. Are you actually this clueless, > or
just trolling?
So you've come up with another exception. No-one is claiming that never ever
will you need a number over 4 billion. Clearly, if you need to give an id
number to the entire population of the world, or you need to tag every US
cent in circulation, or you are doing some fancy statistical work that
generates large integers, then these are exceptions. However the exceptions
don't arise very often, which is why you will seldom see long long used in
real programs.

It doesn't take big finances to come up with numbers to overflow a
32-bit integer.

Dollar amounts are best represented as integer quantities of cents,
(assuming you are using integers at all, and you're using dollars),
since accountants like the books to balance exactly. It is often
necessary to use signed numbers for accounting purposes (revenue
and expense, profit and loss). Now you're down to a range of +/-
$20 million. Gas stations, which traditionally have prices ending
in "and nine-tenths of a cent per gallon" might be using integer
quantities of tenths of a cent.

A grocery store (a SINGLE STORE, not a chain) with 10 employees
earning $30,000 annual salary average and margins of 1% (profit
margins tend to be thin in the grocery business) needs to have
revenue of $30 million/year just to support the employees (which
overflows). That money tends to show up on the books multiple times
(e.g. sales of products and purchases of products from vendors).
As grocery stores go, one with only 10 employees is a lot smaller
than most of the ones around here.

Lifetime earnings of some individual higher-paid people (such as
top executives and major-league baseball players) of over $500,000
per year over 40 years would exceed the +/- $20 million limit.

Further, intermediate results often require more range than the
final results do. For example, to calculate sales tax using integer
math, you might multiply by 8,625 and divide by 100,000, then round
(using the peculiar legally-mandated method of rounding for sales
tax, which does not necessarily coincide with any method used by
mathematics.) Suddenly, you overflow this at slightly over $2318,
which isn't even the price of a single good used car. Granted, for
this example, you *CAN* cancel out common factors of 8625 and 100000,
but that 8.625% number is something the state gives you and keeps
changing, and sooner or later they'll give you a prime number. Even
then, you overflow the calculation at something under $300,000.


Gordon L. Burditt
 
J

Jack Klein

So you've come up with another exception. No-one is claiming that never ever
will you need a number over 4 billion. Clearly, if you need to give an id
number to the entire population of the world, or you need to tag every US
cent in circulation, or you are doing some fancy statistical work that
generates large integers, then these are exceptions. However the exceptions
don't arise very often, which is why you will seldom see long long used in
real programs.

You are very foolishly over generalizing from a lack of perceived need
that YOU feel in the programs that YOU write. Not everyone writes
only the types of programs that you do, or have quite such a set of
blinders to other types of code.

And you haven't addressed my second, very real example. It can be
particularly important in real-time calculations to deal with the
relationships not between variables themselves, but the squares of
those variables. And you can't reliably square 32-bit integer
variables without a 64-bit integer type.
 
S

Severian

So you've come up with another exception. No-one is claiming that never ever
will you need a number over 4 billion. Clearly, if you need to give an id
number to the entire population of the world, or you need to tag every US
cent in circulation, or you are doing some fancy statistical work that
generates large integers, then these are exceptions. However the exceptions
don't arise very often, which is why you will seldom see long long used in
real programs.

There are thousands or millions of real-world exceptions (I've coded
many). You are blind to anything beyond your quite specific endeavors.
 
C

Carlos

Malcolm said:
just trolling?


So you've come up with another exception. No-one is claiming that never ever
will you need a number over 4 billion. Clearly, if you need to give an id
number to the entire population of the world, or you need to tag every US
cent in circulation, or you are doing some fancy statistical work that
generates large integers, then these are exceptions. However the exceptions
don't arise very often, which is why you will seldom see long long used in
real programs.
I first encountered the need to represent numbers larger than those
representable by 32 bit ints about 3 days after leaving university, when
dealing with Turkish Lira.

2,147,483,647 TRL is currently less than £800/$1500, so that's a
reasonably common use I'd say.
 
C

Chris Torek

... Why is long long not used so much?

I am not so sure it is not (used much).

The various BSDs support files larger than 4 gigabytes, on
disks (including RAID) of many terabytes. (The LaCie "Bigger
Disk" holds 1 terabyte and costs about $1k, so if you build
your own RAID out of some number of these, you could easily
put together a 10+ TB "disk". BSD/OS, FreeBSD, NetBSD, etc.,
will generally let you make a single partition on a big drive
and use it to hold one large file. (There have been some problems
when you hit 2147483648 blocks, or even sectors; and this
has limited people "less than 1,099,511,627,776" bytes in
a partition. Some of the BSDs have fixed this for some or
perhaps even all of their drivers. Block and sector numbers
have historically been stored in 32-bit integers though, so
the signedness fixes only take you from 1 TB to 2 TB. You
have to update the driver to handle even-larger units, and
even switch to UFS2 if you want to go past 16 TB.)

(Wind River's VxWorks has a hardcoded 40-bit limit in the modified
DOS-style file system, and of course the DOS-FAT-compatible file
system is inherently limited to 32-bit file sizes, because Microsoft
did not plan ahead. If you want to use the 40-bit file sizes,
though, you do have to use "long long".)
 
M

Malcolm

Carlos said:
2,147,483,647 TRL is currently less than £800/$1500, so that's > a reasonably common use I'd say.
So four billion times that is 6 trillion dollars. US government spending is
about 1 trillion dollars a year. So 64 bits is just enough to represent any
amount of money you might need, but only by an order of magnitude.
 
A

Andrey Tarasevich

Malcolm said:
A number must ultimately represent something in the real world. You seldom
need a number above 4 billion, which is about the number of adults in the
world. An exception is memory size, which can exceed 4GB on large systems
and may soon be around that on desktop PCs, but in C we use size_t for
amounts of memory.

Sometimes calculating a value from the "real world" requires a [short]
trip into the realm of "unreal". For example, calculating the Euclidean
distance between two point with "read world"s 'unsigned long'
coordinates might easily involve values that extend beyond 'unsigned
long' range.
 
J

Jeremy Yallop

Malcolm said:
So four billion times that is 6 trillion dollars. US government
spending is about 1 trillion dollars a year. So 64 bits is just
enough to represent any amount of money you might need, but only by
an order of magnitude.

The US national debt currently exceeds 7e12 dollars.

Jeremy.
 
M

Mark McIntyre

So four billion times that is 6 trillion dollars. US government spending is
about 1 trillion dollars a year. So 64 bits is just enough to represent any
amount of money you might need, but only by an order of magnitude.

Governments are not the world's top spenders. One of my clients transacted
over 6Trln Euros last year just on one trading desk in one locale.
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top