[comp.lang.c] Breadking 4 billion n

zielke@unssun.nevada.edu (John Zielke) (08/03/90)

Having a hard time breaking the 4 billion decimal mark, has anyone
done it before. Can you help me?

having a hard time seeing the trees through the forest.

thanks

john zielke

zielke@unssun.nevada.edu

decot@hpisod2.HP.COM (Dave Decot) (08/08/90)

> Having a hard time breaking the 4 billion decimal mark, has anyone
> done it before. Can you help me?

Certainly:

    unsigned long int n = 3999999999;

    int main(void)
    {
	n++;
	return 0;
    }

> having a hard time seeing the trees through the forest.

Evidently.  Can you be more explicit as to what you are talking about?

Dave Decot

culliton@cdss.UUCP (Tom Culliton x2278) (08/10/90)

Don't you hate new programmers, don't you wish someone would take them
aside and hand them a copy of the FAQ before turning them loose on the
net? Don't you wish you had never done anything this embarassing
yourself? (I know I have...)

The quick answer is that of course you can't go beyond 2^32 in an
integeral type on a 32 bit machine.  (Yes there are ways around it, but
not using the native types in C) Integer math in most programming
languages has finite limits.  (Just like a hand held calculator or a
slide rule) And the best thing that can be said about floating point or
"real" math is that its a matter of approximations within finite limits
of precision.  (again like a calculator or slide rule)  Plum's "Learning
to Program in C" (Plum Hall, 1983 ISBN 0-911537-00-7) has a decent
introduction to computer math.

wilkins@mailer.jhuapl.edu (Al Wilkins) (08/10/90)

Hey, I have the same problem. It depends on what you want to do with the
numbers. If you are only totaling, you can use a counter to increment the
billions. When your total is greater that 1 billion, add one to the increment
variable and subtract 1 billion from the total. If you are going to manipulate
the total, then I don't know that you can do it. Unsigned Long maximum is
2^32.


Carl Schelin
(using Al's machine)
--