处理双 NaN 和 Inf 时的 ILASM 问题

问题描述

我创建了一个简单的程序,初始化了一个 double 类型的值,

var a = double.NaN;

我使用 Visual Studio 2019、.net framework 4.5 构建项目 并使用 ILDASM.exe Version 4.0.30319.0 将其反汇编为 .il 文件

IL_0001: ldc.r8 -nan(ind)

但是当我尝试使用 ILASM.exe 版本 4.8.3752.0 进行组装时出现错误

test.il(65) : error : 标记“-”处的语法错误:IL_0001: ldc.r8 -nan(ind)

这也发生在 Double.PositiveInfinity 和 Double.NegativeInfinity 上。 有人可以帮忙吗?

解决方法

我从 here

中找到了错误原因

而简单的解决方案就是替换:

ldc.r8 -nan(ind) -> ldc.r8 (00 00 00 00 00 00 F8 FF)

ldc.r8 inf -> ldc.r8 (00 00 00 00 00 00 F0 7F)

ldc.r8 -inf -> ldc.r8 (00 00 00 00 00 00 F0 FF)