Description
Switch expression in C# 8 behaves differently on x86 vs x64 Android. After third call it behaves differently for float type.
Reproduction Steps
Copy paste the below code in mono/samples/Android and try to run on x86 android emulator.
GetNumberAsString after third call starts returning NAN, even if it is called for the same value (float.MaxValue).
publicstaticintMain(string[]args){varrandom=newRandom(42);List<float>Floats=newList<float>{// 0.000f,//1.1234e1f,//-1.1234e1f,float.MaxValue,float.MinValue};for(inti=0;i<10;i++){floatvalue=NextFloat(random);Floats.Add(value);}Console.WriteLine("GetNumberAsString conversion is {0}",GetNumberAsString(float.MaxValue));Console.WriteLine("GetNumberAsString conversion is {0}",GetNumberAsString(Floats[3]));Console.WriteLine("GetNumberAsString conversion is {0}",GetNumberAsString(Floats[4]));Console.WriteLine("GetNumberAsString conversion is {0}",GetNumberAsString(Floats[5]));Console.WriteLine("GetNumberAsString conversion is {0}",GetNumberAsString(float.MaxValue));//RunAsRootTypeTest(Floats);return42;}publicstaticfloatNextFloat(Randomrandom){doublemantissa=(random.NextDouble()*2.0)-1.0;doubleexponent=Math.Pow(2.0,random.Next(-126,128));floatvalue=(float)(mantissa*exponent);returnvalue;}privatestaticvoidRunAsRootTypeTest<T>(List<T>Floats){foreach(TfinFloats){Console.WriteLine("GetNumberAsString from foreach conversion is {0}",GetNumberAsString(f));}}privatestaticstringGetNumberAsString<T>(Tnumber){/*switch (Type.GetTypeCode(typeof(T))) { case TypeCode.Double: return Convert.ToDouble(number).ToString("G9", System.Globalization.CultureInfo.InvariantCulture); case TypeCode.Single: return Convert.ToSingle(number).ToString("G9", System.Globalization.CultureInfo.InvariantCulture); case TypeCode.Decimal: return Convert.ToDecimal(number).ToString(System.Globalization.CultureInfo.InvariantCulture); default: return number.ToString(); }*/returnnumberswitch{double@double=>@double.ToString("G9",System.Globalization.CultureInfo.InvariantCulture),float@float=>@float.ToString("G9",System.Globalization.CultureInfo.InvariantCulture),decimal@decimal=>@decimal.ToString(System.Globalization.CultureInfo.InvariantCulture),
_ =>number.ToString()};}Expected behavior
GetNumberAsString should convert correctly after third call also.
To get expected behaviour please uncomment first switch in GetNumberAsString and comment last one.
TypeCode enum switch works correct on both x64 and x86, so my guess is switch expression in C# 8 behaves differently on x86 vs x64 Android.
Actual behavior
First 3 times GetNumberAsString returns correct value. After that it starts to return NAN.
Regression?
No response
Known Workarounds
Using TypeCode enum switch works fine on both x64 and x86.
Configuration
Try on Android x86.
Other information
returnnumberswitch{//double @double => @double.ToString("G9", System.Globalization.CultureInfo.InvariantCulture),float@float=>@float.ToString("G9",System.Globalization.CultureInfo.InvariantCulture),//decimal @decimal => @decimal.ToString(System.Globalization.CultureInfo.InvariantCulture),
_ =>number.ToString()};When I comment other cases in switch seems it works.
Description
Switch expression in C# 8 behaves differently on x86 vs x64 Android. After third call it behaves differently for float type.
Reproduction Steps
Copy paste the below code in mono/samples/Android and try to run on x86 android emulator.
GetNumberAsString after third call starts returning NAN, even if it is called for the same value (float.MaxValue).
Expected behavior
GetNumberAsString should convert correctly after third call also.
To get expected behaviour please uncomment first switch in GetNumberAsString and comment last one.
TypeCode enum switch works correct on both x64 and x86, so my guess is switch expression in C# 8 behaves differently on x86 vs x64 Android.
Actual behavior
First 3 times GetNumberAsString returns correct value. After that it starts to return NAN.
Regression?
No response
Known Workarounds
Using TypeCode enum switch works fine on both x64 and x86.
Configuration
Try on Android x86.
Other information
When I comment other cases in switch seems it works.