views:

111

answers:

4

How variable beyond "unsigned long long" size is represented in C or any programming language. Is there are variable type to represent Infinity?

+2  A: 

See: Floating point Infinity

NullUserException
+2  A: 

Both floats and doubles have representations for infinity. Integral types do not have this capacity built into the language but, if you need it, there are tricks you can use to assign INT_MAX or LONG_MAX from limits.h for that purpose.

Of course, to do that, you have to have complete control of the calculations - you don't want a regular calculation ending up with that value and then being treated as infinity from there on.

For numbers larger than those that can be represented by the native types, you can turn to an arbitrary precision math library such as GMP.

paxdiablo
+2  A: 

Are you talking about representing the number infinity, or working with numbers too big to fit into a single native data type? For the latter, it's possible to create data structures that represent larger numbers, and write your own logic to implement arithmetic for those structures.

I've done this on a basic level for some problems at Project Euler. My approach was to extend the algorithms used in elementary school, which let you do operations on multi-digit numbers by breaking them down into operations using only single-digit numbers plus some carrying, remainders, borrowing, etc.

You might also be interested in this wikipedia article on arbitrary-precision arithmetic.

grossvogel
A: 
dreamlax
The C standard may not require it, but IEEE-754 does. Search for infinity in the following page: http://steve.hollasch.net/cgindex/coding/ieeefloat.html
George