我需要在WPF控件层次结构中搜索与给定名称或类型匹配的控件。我该怎么做呢?

下面的代码显然是错误的。有什么问题吗?

i <- 0.1
i <- i + 0.05
i
## [1] 0.15
if(i==0.15) cat("i equals 0.15") else cat("i does not equal 0.15")
## i does not equal 0.15

我在浮点数中有值25.00,但当我在屏幕上打印它时,它是25.0000000。 如何显示只有两位小数点后的值?

众所周知,nan在算术中传播,但我找不到任何演示,所以我写了一个小测试:

#include <limits>
#include <cstdio>

int main(int argc, char* argv[]) {
    float qNaN = std::numeric_limits<float>::quiet_NaN();

    float neg = -qNaN;

    float sub1 = 6.0f - qNaN;
    float sub2 = qNaN - 6.0f;
    float sub3 = qNaN - qNaN;

    float add1 = 6.0f + qNaN;
    float add2 = qNaN + qNaN;

    float div1 = 6.0f / qNaN;
    float div2 = qNaN / 6.0f;
    float div3 = qNaN / qNaN;

    float mul1 = 6.0f * qNaN;
    float mul2 = qNaN * qNaN;

    printf(
        "neg: %f\nsub: %f %f %f\nadd: %f %f\ndiv: %f %f %f\nmul: %f %f\n",
        neg, sub1,sub2,sub3, add1,add2, div1,div2,div3, mul1,mul2
    );

    return 0;
}

这个例子(在这里运行)基本上产生了我所期望的(否定是有点奇怪,但它是有道理的):

neg: -nan
sub: nan nan nan
add: nan nan
div: nan nan nan
mul: nan nan

MSVC 2015也产生了类似的东西。然而,Intel c++ 15产生:

neg: -nan(ind)
sub: nan nan 0.000000
add: nan nan
div: nan nan nan
mul: nan nan

具体来说,qNaN - qNaN == 0.0。

这个…不可能是对的,对吧?相关标准(ISO C, ISO c++, IEEE 754)对此做了什么说明,为什么编译器之间的行为有差异?

例如:

9 / 5  #=> 1

但我以为是1.8。我怎样才能得到正确的十进制(非整数)结果?为什么返回1呢?

我正在尝试添加授权到我的MongoDB。 我使用MongoDB 2.6.1在Linux上完成所有这些工作。 我的mongo .conf文件是旧的兼容格式 (这就是安装的方式)。

1)我创建了admin用户,如(3)所述

http://docs.mongodb.org/manual/tutorial/add-user-administrator/

2)然后我通过取消注释这一行来编辑mongo .conf

真实的

3)最后,我重启了mongod服务,并尝试登录:

/usr/bin/mongo localhost:27017/admin -u sa -p PWD

4)我可以连接,但它说这个连接。

MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current date/time is: Thu May 29 2014 17:47:16 GMT-0400 (EDT)
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }

5)现在我创建的sa用户似乎没有任何权限。

root@test02:~# mc
MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current date/time is: Thu May 29 2014 17:57:03 GMT-0400 (EDT)
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
[admin] 2014-05-29 17:57:03.011 >>> use admin
switched to db admin
[admin] 2014-05-29 17:57:07.889 >>> show collections
2014-05-29T17:57:10.377-0400 error: {
        "$err" : "not authorized for query on admin.system.namespaces",
        "code" : 13
} at src/mongo/shell/query.js:131
[admin] 2014-05-29 17:57:10.378 >>> use test
switched to db test
[test] 2014-05-29 17:57:13.466 >>> show collections
2014-05-29T17:57:15.930-0400 error: {
        "$err" : "not authorized for query on test.system.namespaces",
        "code" : 13
} at src/mongo/shell/query.js:131
[test] 2014-05-29 17:57:15.931 >>>

有什么问题吗?我把整个过程重复了三次 我想我做的都是在MongoDB文档中指定的。但这并不奏效。 我期望这个sa用户被授权做任何事情,以便 然后,他可以创建其他用户,并给予他们更具体的权限。

我试图从数据网格解析两个值。字段是数字,当它们有逗号(例如554,20)时,我无法获得逗号后的数字。我试过parseInt和parseFloat。我该怎么做呢?

为什么改变求和顺序会返回不同的结果?

23.53 + 5.88 + 17.64 = 47.05

23.53 + 17.64 + 5.88 = 47.050000000000004

Java和JavaScript都返回相同的结果。

我知道,由于浮点数用二进制表示的方式,一些有理数(如1/3 - 0.333333…)不能精确地表示。

为什么仅仅改变元素的顺序就会影响结果?

我一直在各种图形头文件中看到这个常量弹出

0.0039215689

这似乎和颜色有关?

下面是谷歌的首支热门单曲:

void RDP_G_SETFOGCOLOR(void)
{
    Gfx.FogColor.R = _SHIFTR(w1, 24, 8) * 0.0039215689f;
    Gfx.FogColor.G = _SHIFTR(w1, 16, 8) * 0.0039215689f;
    Gfx.FogColor.B = _SHIFTR(w1, 8, 8) * 0.0039215689f;
    Gfx.FogColor.A = _SHIFTR(w1, 0, 8) * 0.0039215689f;
}

void RDP_G_SETBLENDCOLOR(void)
{
    Gfx.BlendColor.R = _SHIFTR(w1, 24, 8) * 0.0039215689f;
    Gfx.BlendColor.G = _SHIFTR(w1, 16, 8) * 0.0039215689f;
    Gfx.BlendColor.B = _SHIFTR(w1, 8, 8) * 0.0039215689f;
    Gfx.BlendColor.A = _SHIFTR(w1, 0, 8) * 0.0039215689f;

    if(OpenGL.Ext_FragmentProgram && (System.Options & BRDP_COMBINER)) {
        glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 2, Gfx.BlendColor.R, Gfx.BlendColor.G, Gfx.BlendColor.B, Gfx.BlendColor.A);
    }
}

//...more like this

这个数字代表什么?为什么没有人把它声明为const?

我在谷歌上找不到任何可以解释的东西。

有时,Activerecord数据类型让我感到困惑。经常犯错,。我的一个永恒的问题是,对于一个给定的情况,

我应该使用:decimal还是:float?

我经常遇到这个链接,ActiveRecord::decimal vs:float?,但答案还不够明确,我无法确定:

我见过很多人极力建议不要使用的线程 浮点数,总是使用小数。我也看到了一些建议 人们只在科学应用中使用浮子。

以下是一些例子:

地理位置/纬度/经度:-45.756688,120.5777777,… 比例/百分比:0.9,1.25,1.333,1.4143,…

我过去使用过:decimal,但我发现在Ruby中处理BigDecimal对象比处理float对象更尴尬。例如,我还知道我可以使用:integer来表示钱/分,但它不太适合其他情况,例如当精度随时间变化的数量时。

使用每种方法的优点/缺点是什么? 有什么好的经验法则来知道使用哪种类型?