相关疑难解决方法(0)

C++我刚刚读到浮点数不精确,并且不存储确切的整数值.这是什么意思?

我在二进制级别考虑这个问题.

将值为1的浮点值和值为1的整数不编译为(在此省略大量的零)

0001

如果他们两者都编译到这个,那么这种不精确性会在哪里出现.

我正在使用的资源是http://www.cprogramming.com/tutorial/lesson1.html

谢谢.

c++ floating-accuracy

2
推荐指数
2
解决办法
4787
查看次数

为什么2不等于√2*√2?

据Lua说,我注意到了 2 ~= math.sqrt(2) ^ 2

print(2 == math.sqrt(2) ^ 2) --> false
print(2, math.sqrt(2) ^ 2) --> 2  2
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

math floating-point lua sqrt

2
推荐指数
1
解决办法
387
查看次数

Flash添加错误

在Flash中创建一个新的AS3文档,粘贴以下代码并运行它:

var a:Number=0;
trace(a)  //  0
a+=0.3;
trace(a)  //  0.3
a+=0.3;
trace(a)  //  0.6
a+=0.3;

trace(a)  //  0.8999999999999999
a+=0.3;
trace(a)  //  1.2
a+=0.3;
trace(a)  //  1.5
a+=0.3;
trace(a)  //  1.8
a+=0.3;
trace(a)  //  2.1
a+=0.3;
          //  ^ This is the output. Notice the inaccuracy starting from 0.9 / 0.89
Run Code Online (Sandbox Code Playgroud)

为什么错误?我只是做一个普通的高分辨率加法.

任何解决方法?

math flash floating-point actionscript-3

1
推荐指数
1
解决办法
854
查看次数

在C++中截断

今天我试着编写一个程序来总结用户输入的整数.例如,如果用户输入683它将返回6 + 8 + 3 = 17.

但我在代码中遇到了一些奇怪的问题

代码 :

#包括

using namespace std;
int computeSum(int num);
int computeInteger(int num, int position);

int main()
{
    int num;
    int sum;
    int total;
    cin >> num;

    total = computeSum(num);

    cout << total;
    return 0;
}

int computeSum(int num) 
{
    int position = 10;
    int temp = num;
    double total = 0;
    bool finish = false;

    while(!finish)
    {
        total = total + computeInteger(num, position);

        if(num/ position == 0)
            break;
        position *= …
Run Code Online (Sandbox Code Playgroud)

c++ floating-point truncation

0
推荐指数
2
解决办法
1165
查看次数