visual studio 10 express的可用性水平是多少 [英] What is the level of usability of visual studio 10 express

查看:60
本文介绍了visual studio 10 express的可用性水平是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

最近我下载了Visual Studio 10 Express C ++,

注册了它并开始使用它。

我做的很简单windows form app,

,带一个按钮和两个textBox控件,用于显示结果。

按钮点击事件,程序应该通过一个简单的

for..next循环并测量执行时间。

结果显示在textBox1和textBox2控件中。



程序的一个重要部分代码:



private:System :: Void button1_Click(System :: Object ^ sender,System :: EventArgs ^ e)

{

秒表时钟;



clock.Start();



int i = 0;

double k = 0;

for(i = 0; i< 100; i = i + 1)

{

k = k + 0.1;

}



clock.Stop();



textBox1-> Text =(clock.Elapsed.TotalSeconds).ToString();



textBox2-> Text = k.ToString();

}



问题是连续递增值的结果
不正确:



k = 9,99999999999998而不是k = 10.



这是因为Visual Studio 10的版本是EXPRESS

并且仅用于评估。



什么我试过了:



我已阅读C ++手册,看看我是否在逻辑上错误地编写了这个程序代码,也许是因为这个错误了给出错误的结果,我发现代码中没有错误。

解决方案

引用:

问题是连续递增值的结果

里面的变量k是不正确的:



k = 9,99999999999998代替k = 10.

这是不正确的。

0.1以二进制浮点v编码alue,你必须知道在浮点值编码的0.1不精确。这是c,C ++和C#的标准编码。

要使用精确编码处理这些值,您必须使用专门的库。



一个解决方案id将所有内容乘以10并使用整数然后除以10除以显示。



浮点 - 维基百科,免费的百科全书 [ ^ ]

C / FloatingPoint [ ^ ]


Hello,
recently I have downloaded Visual Studio 10 Express C++,
registered it and started using it.
I have made simple windows form app,
with one button and two textBox controls for showing result.
On button click event, program should runt trough a simple
for..next loop and measure the time of execution.
Results are shown in textBox1 and textBox2 controls.

An important part of program code :

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
Stopwatch clock;

clock.Start();

int i = 0;
double k = 0;
for (i=0; i<100; i=i+1)
{
k = k + 0.1;
}

clock.Stop();

textBox1->Text = (clock.Elapsed.TotalSeconds).ToString();

textBox2->Text = k.ToString();
}

The problem is that result of successive incrementing of value
of variable k inside looop is incorrect :

k = 9,99999999999998 instead k = 10.

Is this because the version of Visual Studio 10 is EXPRESS
and intended for evaluation only.

What I have tried:

I have read manual for C++, to see if I have made this program code wrong logically, and perhaps because of that error it gives wrong result, and I have found no error inside the code.

解决方案

Quote:

The problem is that result of successive incrementing of value
of variable k inside looop is incorrect :

k = 9,99999999999998 instead k = 10.

It is not incorrect.
0.1 is coded in binary floating point value, and you have to know that 0.1 coded in floating point value is not exact. This is the standard coding for c, C++ and C#.
To handle such values with exact coding, you have to specialized library.

One solution id to multiply everything by 10 and use integer and then divide by 10 when you want to display.

Floating point - Wikipedia, the free encyclopedia[^]
C/FloatingPoint[^]


这篇关于visual studio 10 express的可用性水平是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆