Mail Archives: djgpp/1998/08/27/13:35:16
From: | Kevin Ashley <k DOT ashley AT ulcc DOT ac DOT uk>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: LARGE numbers.
|
Date: | Thu, 27 Aug 1998 18:29:06 +0100
|
Organization: | Posted via ULCC Internet Services
|
Lines: | 36
|
Message-ID: | <35E59762.41C6@ulcc.ac.uk>
|
References: | <1103_904198596 AT isaacc>
|
NNTP-Posting-Host: | silver.ulcc.ac.uk
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
isaacc AT flash DOT net wrote:
> I want to store the following number (25834242042) as an int, I declare it as usual:
>
> int var = 258342042;
>
> yet the number is obviouslu too large to store as an integer (even an unsigned one).
> Subsequently I try to store it as both 'float' and 'double' - yet they wont even hold a number of
> this size!
Yes, this number (the 11-digit one that I presume you meant) is too
large for an int. You could use long long int (64-bit) as others have
pointed out, but this is gcc or architecture specific and the I/O libraries
did not fully support them when I last checked.
You can store such number in a double (you can do it in a float too, but
the accuracy won't be enough to represent it exactly.) Your problem
probably came because you wrote something like:
double dvar;
dvar = 25834242042;
This won't work because the RHS of this expression is an INTEGER constant.
We've already established this number's too big for an integer.
Instead, write:
dvar = 25834242042.;
That trailing dot turns it into a double constant.
----------------------------------------------------------------------------
Kevin Ashley K DOT Ashley AT Ulcc DOT ac DOT uk
Special Projects Manager http://www.ulcc.ac.uk/staff/Kevin+Ashley
ULCC ...ukc!ncdlab!K.Ashley (but probably not any more)
This is not a signature
- Raw text -