C# Float 与 VB.net Single - Namin'抱怨'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/272013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# Float vs. VB.net Single - Namin' complainin'
提问by dfasdljkhfaskldjhfasklhf
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.
为什么在VB.net中称为单曲?我确信有一个很好的理由,但对于像我这样未经正式培训的程序员来说,这似乎并不直观。
采纳答案by Xiaofu
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...
BPAndrew 的问题似乎真的是“为什么在 C# 中浮动而在 VB.NET 中浮动”,实际上没有人回答,所以这是我的 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.
在 C# 中使用“float”似乎是对其 C/C++ 传统的回归。"float" 仍然映射到 C# 中的 System.Single 类型,因此关键字只是为了方便而存在。您也可以像在 VB.NET 中一样在 C# 中将变量声明为“Single”。
(And as stated above, naming them Single/Double actually makes more sense as they are single/double precision floating-point numbers.)
(如上所述,将它们命名为 Single/Double 实际上更有意义,因为它们是单/双精度浮点数。)
回答by chakrit
I think it is a shorthand
for "Single-precision"
Double
is "Double-precision"
我认为这是一个shorthand
对"Single-precision"
Double
IS“Double-precision"
While C-style int
and float
was probably referring to "integer"
and "floating point"
虽然C-style int
和float
可能指的是"integer"
和"floating point"
回答by C. Broadbent
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.
技术名称是“单精度浮点”,“单”是因为它在内存中占用一个字(32 位)。与此同时,double 在大多数架构上需要 64 位。
回答by LeppyR64
The reason is that both single and double are both Floating Point numbers.
原因是 single 和 double 都是浮点数。
single is short for Single Precision Floating Point Number (32 bits)
double is short for Double Precision Floating Point Number (64 bits)
single 是 Single Precision Floating Point Number (32 bits)
的缩写 double 是 Double Precision Floating Point Number (64 bits) 的缩写
Therefore to call a floating point number float is ambiguous.
因此,将浮点数称为 float 是不明确的。
http://en.wikipedia.org/wiki/Single_precision
http://en.wikipedia.org/wiki/Double_precision
http://en.wikipedia.org/wiki/Single_precision
http://en.wikipedia.org/wiki/Double_precision
回答by Jon Skeet
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?
正如其他人所说,它们映射到“单”和“双”精度二进制浮点类型。我个人认为这是一个侧身一步,只是名称System.Single
和System.Double
-为什么不System.Float32
和System.Float64
相匹配的整数类型?
回答by max
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.
在 Java 和 C# 诞生的 C/C++ 词中,int/long 和 float/double 可能会根据其所在的体系结构(32 位或 64 位)而有所不同。
In portable VM languages like Java and C#, these types do NOT change, and therefore, the naming convention couldreflect 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!!
在 Java 和 C# 等可移植 VM 语言中,这些类型不会改变,因此,命名约定可以反映这一点。或者它可能只是上一代程序员最舒服的东西。或者我们可以为所有东西创建别名,让每个人为所欲为!!