How can I compute the range of signed and unsigned types
Jim Phillips
jim at ks.uiuc.edu
Wed Apr 18 08:12:18 PDT 2001
Hi,
In C++ you can use something like this:
#include <limits>
numeric_limits<int>.min()
numeric_limits<unsigned long>.max()
There are similar things for floating point. See Stroustrup.
In plain C, there is limits.h, which defines symbols like INT_MIN,
LONG_MAX, FLT_MIN, DBL_MAX, etc. The limits man page on Solaris lists a
bunch of them. I think this is the answer you are looking for.
-Jim
On Wed, 18 Apr 2001, Chris Richard Adams wrote:
> This is my point - how can I compute this so my code could run on any
> machine. I need to show the range possible on any machine...how can I
> compute that?
>
> Thanks,
> Chris
>
> -----Original Message-----
> From: James Cownie [mailto:jcownie at etnus.com]
> Sent: Wednesday, April 18, 2001 10:19 AM
> To: Beowulf (E-mail)
> Subject: Re: How can I compute the range of signed and unsigned types
>
>
>
> Jag wrote : -
>
> > Those sizes are defined for the C language. In order words, no
> > matter if you're on a 32-bit machine or a 64-bit machine, an int is
> > always going to be 32-bit and thus have the same numeric range
> > because the standards say so. This goes for all the basic types,
> > not just int's.
>
> No, the C standard says nothing of the sort.
>
> All the C standard says is that
>
> 1) sizeof (char) == 1
> 2) sizeof (short) >= sizeof (char)
> 3) sizeof (int) >= sizeof (short)
> 4) sizeof (long) >= sizeof (int)
> 5) sizeof (long long) >= sizeof (long).
>
> It also does not specify that the representation of an int is two's
> complement, so even on machines with the same sizeof(int) the legal
> ranges could differ.
>
> -- Jim
>
> James Cownie <jcownie at etnus.com>
> Etnus, LLC. +44 117 9071438
> http://www.etnus.com
>
> _______________________________________________
> Beowulf mailing list, Beowulf at beowulf.org
> To change your subscription (digest mode or unsubscribe) visit
> http://www.beowulf.org/mailman/listinfo/beowulf
>
> _______________________________________________
> Beowulf mailing list, Beowulf at beowulf.org
> To change your subscription (digest mode or unsubscribe) visit http://www.beowulf.org/mailman/listinfo/beowulf
>
More information about the Beowulf
mailing list