Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ILASM problem when dealing with double NaN and Inf

Tags:

c#

.net

cil

ilasm

I create a simple program with a double type value initialized,

var a = double.NaN;

I build the project with Visual Studio 2019, .net framework 4.5 and disassemble it into a .il file using ILDASM.exe Version 4.0.30319.0

IL_0001: ldc.r8 -nan(ind)

but there is an error when I try to assemble it using ILASM.exe Version 4.8.3752.0

test.il(65) : error : syntax error at token '-' in: IL_0001: ldc.r8 -nan(ind)

This happened to Double.PositiveInfinity and Double.NegativeInfinity too. Anyone can help?

like image 734
Hongbii Khaw Avatar asked Nov 07 '22 02:11

Hongbii Khaw


1 Answers

I found the error reason from here

and the simple solution is just to replace the:

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)

like image 149
Hongbii Khaw Avatar answered Nov 12 '22 15:11

Hongbii Khaw