Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ To VB.Net Conversion Help 1

Status
Not open for further replies.

3L4CK5C0RP10N

Programmer
Dec 25, 2004
5
0
0
PT
Hi.

I´m tryin´ to convert a C++ algorythm to VB.Net but i get an overflow error
in a int32 variable.

[ C++ ]

long Var;

Var = 228886641;
Var = Var * Var;

This code returns -1820311071 in C++, but gives a overflow error
in VB.NET!

Someone can help me, plz ???

I´ll be apreciated... [upsidedown]
 
Visual Basic Int64 returns 52389094428262881.

C# correctly returns 52389094428262881 with the same code as C++.


Why would 228886641 * 228886641 return -1820311071 ?
 
Thanks for tryin´ to help me.

I know that .Net compilers return 52389094428262881 in an int64 variable.

But in C++ int32 return -1820311071, i don´t know why.
And i need to know how to make it return like the C++ version or else the algorythm won´t work.

Do you know why?

Thanks for helping... [wink]
 
Thanks.

That helped me understanding the algo.
Now all i have to do is study a way to get VB multiplications the same way.

I´ll try, with some hard work, to find a way.

Thanks again for your help...
 
Does it bother you to knowingly reproduce the erroneous C++ result which represents an overflow?

I believe your C++ version uses the equivalent of Int32. I wonder if VB.NET will faithfully reproduce the erroneous C++ result using Int32 instead of Int64 (which incidentally gives the correct result), or it will give an overflow exception, in which case you could catch it and display the erroneous result.
 
You could leave it as int32 and turn off the "Check for Integer Overflows" option in the solution properties. Although that could be rather dangerous depending on the rest of your application.

-Rick

----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top