Single more 'powerful' than Integer although both use same amount of bytes ???

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi,

a Single and Integer variable each take 4 bytes.
(check on :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vagrpdatatype.asp)

But how come then that the range for valid values for an integer is
-2,147,483,648 through 2,147,483,647
(OK: 2pow32 = 4,294,967,296 E+09 different posibillities )

and for a single

-3.4028235E+38 through -1.401298E-45 for negative values
1.401298E-45 through 3.4028235E+38 for positive values.

so many more values with the same amount of 32 bits ????

Any logical explanation for this ?

thnx

Christian
 
Chris said:
a Single and Integer variable each take 4 bytes.
(check on :
http://msdn.microsoft.com/library/default.asp?url=/library/
en-us/vblr7/html/vagrpdatatype.asp)

But how come then that the range for valid values for an integer is
-2,147,483,648 through 2,147,483,647
(OK: 2pow32 = 4,294,967,296 E+09 different posibillities )

and for a single

-3.4028235E+38 through -1.401298E-45 for negative values
1.401298E-45 through 3.4028235E+38 for positive values.

so many more values with the same amount of 32 bits ????

No, it doesn't have more values. There are various ints which aren't
exactly represented as singles. (Of course there are also many, many
singles which aren't exactly represented as ints, too.) Don't confuse
"range" with "number of values". How many even numbers are there
between 0 and 20? How many integers are there between 0 and 15? Which
has more values, and which has a larger range?

In fact, there are more "significantly different" ints than singles, as
there are many different Not-a-Number (NaN) values which are all likely
to be dealt with in the same way by almost all programs.
 
Every single integer in the range -2,147,483,648 through 2,147,483,647 can
be represented in a 4-byte int.

Not every single integer in the range -3.4E+38 to +3.4E+38 can be
represented in a 4-bit single. In fact, only a tiny fraction of the integers
in that range can be represented exactly. The rest are approximated.
Example:

float s = 1983428725782477258345f;
Console.WriteLine("{0:0}", s);

The output of this is

1983429000000000000000
 
Back
Top