- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
(int)((float)10.9 * 10)
的计算结果为 108
。为什么?
IMO (int)
-cast 应该在乘法运算后求值。
最佳答案
有趣的是,这里的问题是表达式是在编译时计算的,显然使用预期的单精度数学。这在调试和发布版本中都会发生:
// this replaces the whole operation
IL_0001: ldc.i4.s 108
IL_0003: stloc.0
IL_0004: ldloc.0
IL_0005: call void [mscorlib]System.Console::WriteLine(int32)
虽然案例 var f =((float)10.9 * 10);int i = (int)f;
仍然针对乘法进行了优化,但使用 double 。因为转换是在单独的步骤中完成的,所以我猜它会使编译器感到困惑(??):
IL_000b: ldc.r4 109 // 109 result for the first part
IL_0010: stloc.1
IL_0011: ldloc.1
IL_0012: conv.i4 // separate conversion to int
IL_0013: stloc.2
// rest is printing it
IL_0014: ldloc.1
IL_0015: box [mscorlib]System.Single
IL_001a: ldstr " "
IL_001f: ldloc.2
IL_0020: box [mscorlib]System.Int32
IL_0025: call string [mscorlib]System.String::Concat(object, object, object)
IL_002a: call void [mscorlib]System.Console::WriteLine(string)
老实说,在第二种情况下,编译器生成了错误的代码,这可能就是为什么 C++ 像瘟疫一样避免优化浮点代码。幸运的是,这只是这种测试代码的问题,完全可以在编译时完成,实际的变量乘法就可以了。
其实我也试过这个:
Console.WriteLine((int)(float.Parse(Console.ReadLine()) * int.Parse(Console.ReadLine())));
并给它 10.9 和 10,结果如预期的那样是 108。
关于c# - 理解给定的计算(cast + multiplication),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33515080/
我很确定我不会是第一个被这个绊倒的人,但我找不到答案。这是作业。 class Tier{} class Fisch extends Tier{} class Vogel extends Tier{}
在接收器开发人员指南中如下: Applications running on the Google Cast receiver device (receiver applications) are a
最近我制作了一个自定义本地 Flask 网站,用于从本地设备转换到连接到我的电视的 RPi4。有一个 GUI它也可以通过 GET 请求控制,这是转换工作的主要方式,实际上是通过 GET 请求将数据从
最近我因为某些原因重置了我的路由器,所以当我尝试将它连接到 chromecast 时,Chromecast 没有在其列表中列出我的 wifi 名称。 之前它工作正常,所以我选择其他并手动输入我的网络名
做这样的 Actor 阵容的好方法是什么? seq { yield (box "key", box "val") } |> Seq.cast 因为这看起来非常难看: seq { yield (box
我继承的遗留 Web 应用程序是在经典 ASP 中为新西兰乐施会定制编写的,它在用户提交的输入上运行字符串替换,删除字符串“cast”,大概是因为 cast 函数。 然而,这意味着我们的参与者都不能拥
我去了三星网站并下载了 Media Control SDK 包。当我在我的 Galaxy S3 Android 4.3 上使用 AllShare Cast 视频播放器时,我的智能电视(在同一网络中)出
如何在 BigQuery 中查看 INT64 的二进制表示形式?将其转换为 BYTES 类型也可以。 最佳答案 正如@Elliot Brossard 所述,INT64 如何执行是一个实现问题。类型表示
Google 的文档要求我们设置自己的网络服务器来托管 receiver.html。 是否有任何人都可以使用的默认公共(public) chrome-cast 接收器? 我只需要非常基本的接收器,与
我在 Eclipse 3.6 (Helios) 中运行某人的代码时遇到问题。代码是用 OpenJDK 7 编写的。我运行的是 Windows 7,我必须为它安装 Java 7。我之前使用的是 Java
所以我有一些 COM 类型,它们的名称很难记住、又长又笨重,所以如果可以避免的话,我宁愿在从对象进行转换时不必键入它们。使用 Seq.cast 它将推断所需的类型并根据需要进行强制转换。 这是一个用
假设您不关心编译器和机器的转换风格,以下之间是否存在明显差异: #include #include #include static int64_t tosigned (void *p) {
我的测试类 XString 有两个转换运算符。但是编译器不会为 fooA 使用显式转换 operator const wchar_t*()。为什么? class XString { public:
我有以下代码: T imageCollectionItem; // This checks if image actually exists, if it doesn't it gets the ne
这有点假设,因为我不太担心性能 - 只是想知道一般来说哪个选项实际上最快/最有效,或者是否没有任何区别。 假设我有以下支持重载的访问者模板代码: #define IMPLEMENT_VISITOR_W
我目前正在存储复选框的真/假状态。在注册表中检查值以在下次加载表单时重置。 加载表单时,我获取值并像这样设置复选框。 string value = (string)Registry.GetValue(
enum Gender { Male, Female } var k = new[] { Gender.Male }.Cast().ToList().Cast().ToList(); //alrigh
我正在按照 https://codelabs.developers.google.com/codelabs/cast-receiver#0 上的教程构建一个 chrome cast 自定义接收器。我无
我看不懂以下作品 SELECT price, CAST(price AS DECIMAL(10,2)) FROM orders; 但是更新失败: UPDATE orders SET price = C
在 Cast v3 中,如何手动更改“停止转换”按钮的颜色? 我可以为其他所有内容更改转换对话框或媒体路由器的样式,但“停止转换”按钮似乎会根据背景颜色切换为黑色/蓝色。 我的主题:
我是一名优秀的程序员,十分优秀!