Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert::NativeToInt64 with SUPPORT_ANY_BASE_CONVERSION delivers incorrect results #412

Closed
MatthiasJentsch opened this issue Sep 14, 2018 · 0 comments · Fixed by nanoframework/nf-interpreter#855

Comments

@MatthiasJentsch
Copy link
Contributor

Details about Problem

nanoFramework area: nanoCLR preview 1010 / mscorlib perview 73

Worked before? No

Detailed repro steps so we can see the same problem

It's reproducible with all firmware that was compiled with SUPPORT_ANY_BASE_CONVERSION=ON.

E.g. Convert.ToInt16("1011110101001010", 2) should return -17078 because the MSB is set. But that return 0. It's caused by the native call to Convert::NativeToInt64. We shouldn't convert the 16bit base 2 string via strtoll. That results in the value 48458. After the check (result > maxValue || result < minValue) ? zero : result NativeToInt64 returns 0.
We have the same issue with ToInt32 and ToSByte.

With ToInt64 we have another issue:

long x1 = Convert.ToInt64("1100001001001011001001010101001100100000011011011111111111110011", 2);
long x2 = Convert.ToInt64("1411131125144033377763", 8);
long x3 = Convert.ToInt64("-4446419168141639693");
long x4 = Convert.ToInt64("C24B2553206DFFF3", 16);

All x values should be -4446419168141639693. But only x3 has this value. The other values are 9223372036854775807 which is not correct.

And last issue is Convert.ToUInt64 which is implemented in mscorlib with this call: return (ulong)NativeToInt64(value, true, 0, 0, fromBase);. Min and max value are set to 0 and second parameter signals a signed conversion. That can't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant