int.Parse(string) bug?

Developer
Feb 11, 2011 at 6:53 AM

Hi, when I run the guess demo, I notice that the parse result is not correct, for example:

if I input 15, the parse result is 51,

if I input 23, the parse result is 32.

I try to print the input string, it is correct. So it's bug of int.Parse(string)?

Coordinator
Feb 11, 2011 at 7:06 AM
it could be, but other options as well, hard to say... how do you find out that it's in reverse?


On Fri, Feb 11, 2011 at 7:53 AM, pegasusplus <notifications@codeplex.com> wrote:

From: pegasusplus

Hi, when I run the guess demo, I notice that the parse result is not correct, for example:

if I input 15, the parse result is 51,

if I input 23, the parse result is 32.

I try to print the input string, it is correct. So it's bug of int.Parse(string)?

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Developer
Feb 11, 2011 at 9:22 AM

There's a line to write the parsed value in GuessOS.cs:

Console.WriteLine("Your guess was " + xGuess);

When I input "19", it prints "Your guess was 91", and then "Too high."

If I input "123", it prints "Your guess was 321", :(

Coordinator
Feb 11, 2011 at 9:31 AM
but is the problem in Int32.ToString() or in Int32.Parse?

On Fri, Feb 11, 2011 at 10:22 AM, pegasusplus <notifications@codeplex.com> wrote:

From: pegasusplus

There's a line to write the parsed value in GuessOS.cs:

Console.WriteLine("Your guess was " + xGuess);

When I input "19", it prints "Your guess was 91", and then "Too high."

If I input "123", it prints "Your guess was 321", :(

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Developer
Feb 11, 2011 at 9:40 AM

The problem should be in int.Parse, since input "19" causes "Too high." // The guessed number is a fixed number 22, :).

I change the type of xGuess from "int" to "short", the result is correct now.

I'll try to find if it's the bug of M$ or Cosmos parts...

Developer
Feb 11, 2011 at 10:01 AM

Running result of the following code differs on Windows and Cosmos:

            string str123 = "123";
            int i123 = int.Parse(str123);
            short s123 = short.Parse(str123);
            Console.WriteLine("Hi, \"123\" parsed as (short):" + s123 + ", (int):" + i123);
            Console.WriteLine("s123 " + (s123 == i123 ? "==" : "!=") + " i123");

On Cosmos, it shows "s123 != i123", and the i123 parsed as 321.

So the problem might be in Plug of Int32 I guess. How to join the project to help fix this bug?

Coordinator
Feb 11, 2011 at 10:07 AM
join cosmos-dev yahoogroup first..


On Fri, Feb 11, 2011 at 11:01 AM, pegasusplus <notifications@codeplex.com> wrote:

From: pegasusplus

Running result of the following code differs on Windows and Cosmos:

string str123 = "123";
int i123 = int.Parse(str123);
short s123 = short.Parse(str123);
Console.WriteLine("Hi, \"123\" parsed as (short):" + s123 + ", (int):" + i123);
Console.WriteLine("s123 " + (s123 == i123 ? "==" : "!=") + " i123");

On Cosmos, it shows "s123 != i123", and the i123 parsed as 321.

So the problem might be in Plug of Int32 I guess. How to join the project to help fix this bug?

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Developer
Feb 11, 2011 at 10:42 AM

Ohh, found the bug in source2\Kernel\System\Cosmos.System.Plugs.System\Int32Impl.cs

(svn Revision 72638, line 22):

for (int i = s.Length - 1; i >= 0; i--)

 

This line should be:

for (int i = 0; i <= s.Length - 1; i++)

 

Wish this can help

Coordinator
Feb 11, 2011 at 12:52 PM
> Wish this can help

Check your email.