sbyte

Why casting big double value in sbyte returns 0 in C#?

久未见 提交于 2020-07-22 07:58:27
问题 I actually test the casting behavior in C# in unchecked context. Like the documentation said, in unchecked context, the cast always succeed. But sometimes, in particular cases, the cast from one specific type to another type give unexpected result. For example, i tested three "double to sbyte" casts : var firstCast = (sbyte) -129.83297462979882752; // Result : 127. var secondCast = (sbyte) -65324678217.74282742874973267; // Result : 0. var thirdCast = (sbyte) -65324678216.74282742874973267; /