25

Why is it called a single in VB.net? I'm sure there is a good reason but it doesn't seem intuitive to a non formally trained programmer like me.

dfasdljkhfaskldjhfasklhf
  • 1,162
  • 2
  • 10
  • 18

6 Answers6

35

BPAndrew's question seems to be really "why float in C# and Single in VB.NET", which noone actually answered, so here's my 2p...

The use of "float" in C# seems to be a throwback to its C/C++ heritage. "float" still maps to the System.Single type in C#, so the keyword just exists for convenience. You could just as well declare the variable as "Single" in C# the same as you do in VB.NET.

(And as stated above, naming them Single/Double actually makes more sense as they are single/double precision floating-point numbers.)

Xiaofu
  • 15,523
  • 2
  • 32
  • 45
19

As others have said, they map to "single" and "double" precision binary floating point types. Personally I think it was a sideways step to just name System.Single and System.Double - why not System.Float32 and System.Float64 to match the integer types?

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 2
    Also, the [CIL](http://en.wikipedia.org/wiki/Common_Intermediate_Language) calls them `float32` and `float64`, respectively, corresponding exactly to the `System.Single` and `System.Double` of the [BCL](http://en.wikipedia.org/wiki/Base_Class_Library). – Jeppe Stig Nielsen Jan 22 '15 at 15:43
8

The reason is that both single and double are both Floating Point numbers.

single is short for Single Precision Floating Point Number (32 bits)
double is short for Double Precision Floating Point Number (64 bits)

Therefore to call a floating point number float is ambiguous.

http://en.wikipedia.org/wiki/Single_precision
http://en.wikipedia.org/wiki/Double_precision

LeppyR64
  • 5,251
  • 2
  • 30
  • 35
2

I think it is a shorthand for "Single-precision" Double is "Double-precision"

While C-style int and float was probably referring to "integer" and "floating point"

ArunPratap
  • 4,816
  • 7
  • 25
  • 43
chakrit
  • 61,017
  • 25
  • 133
  • 162
  • int means integer, which is wholly different than a fixed-point (decimal) number. fixed-point is exactly that, a real number with a pre-set (fixed) precision. http://mathforum.org/dr.math/faq/faq.integers.html – Robert Paulson Nov 07 '08 at 23:07
1

I would like to add my hypothesis for the naming convention.

In the C/C++ word that Java and then C# were born out of, int/long and float/double could vary based on the architecture in which it resides, 32-bit or 64-bit.

In portable VM languages like Java and C#, these types do NOT change, and therefore, the naming convention could reflect that. Or it could just be what's most comfortable the last generation of programmers. Or we could create aliases for everything and let everyone do whatever they want!!

max
  • 716
  • 7
  • 22
0

The technical name is a 'single precision floating point', 'single' because it takes a single word in memory (32 bits). A double, meanwhile, takes 64 bits on most architectures.

C. Broadbent
  • 753
  • 4
  • 11
  • 1
    Originally the single didn't mean single word, since they were 16 bit machines. Floating point and its precision has been around longer than 32 bit machines have. – kenny Nov 07 '08 at 13:13