I wasn't sure where at Microsoft I can submit this as a bug, so I figured I would start here since I am using your hardware.
I have found a bug in the .NET Micro Framework. It occurs when you try to Parse a string into a Double using Double.Parse() or Convert.ToDouble().
The Function works correctly except when the value is between '0.0' and '-1.0'. It then incorrectly reports the values as positive.
A little digging into the Double.Parse code in the Micro Framework, I have found where this happens.
The Double.Parse calls Convert.ToDouble() which calls a private static function GetDoubleNumber(). The problem occurs because the Convert.ToDouble splits the string at the decimal point and calls GetDoubleNumber on each part.
When you have a number such as '-0.5' the Convert.ToDouble returns '0.5' because the function calls GetDoubleNumber on '-0' and '5' and the GetDoubleNumber does not handle returning a -0. This is an issue in v3.0 and v4.0, I've included code to show the original and the 'fix' that I implemented.
Original GetDoubleNumber in Micro Framework
private static double GetDoubleNumber(char[] chars)
{
double num2 = 1.0;
double num3 = 0.0;
int num4 = ((chars[0] == '-') || (chars[0] == '+')) ? 1 : 0;
int num5 = (chars[0] == '-') ? -1 : 1;
for (int i = chars.Length - 1; i >= num4; i--)
{
if ((chars[i] < '0') || (chars[i] > '9'))
{
throw new Exception();
}
int num = chars[i] - '0';
num3 += num * num2;
num2 *= 10.0;
}
return (num3 * num5);
}
Modified so it works GetDoubleNumber
private static double GetDoubleNumber( char[] chars )
{
double num2 = 1.0;
double num3 = 0.0;
int num4 = ( ( chars[ 0 ] == '-' ) || ( chars[ 0 ] == '+' ) ) ? 1 : 0;
int num5 = ( chars[ 0 ] == '-' ) ? -1 : 1;
for ( int i = chars.Length - 1; i >= num4; i-- )
{
if ( ( chars[ i ] < '0' ) || ( chars[ i ] > '9' ) )
{
throw new Exception();
}
int num = chars[ i ] - '0';
num3 += num * num2;
num2 *= 10.0;
}
//==============================
// If num3 (integer magnatude) is 0 and num5 is -1 (sign), then
// the sign is lost because this function will return 0 (no sign)
// Kludge fix is to return a smallest negative fraction just below
// zero when num3 is 0 and num5 is -1
//==============================
//return (num3 * num5);
if ( ( num3 == 0 ) && ( num5 == -1 ) )
return -Double.Epsilon;
else
return ( num3 * num5 );
//==============================
}