Simple math returining diff values in VB and C++

Darc

Well-known member
Joined
Apr 18, 2003
Messages
89
I had a simple mathequation that I thought I might speed up using a Win32 DLL but its returning a different value than in VB (the one that I hoped for). Heres the code in VB (the one that works) and the code in C++ (which returns a bad value):

Code:
Dim y As Integer = CInt(arY + (((arHeight - crdHeight) / NumCards) * crdNum))

Code:
//C++ VS 2003
return arY + (((arHeight - crdHeight) / NumCards) * crdNum);
 
what are the data types for arHeight, crdHeight, NumCards and crdNum in both VB and C++? Also in C++ what is the functions return type?
 
oh, arY, arHeight and crdHeight are integers in both, and NumCards and crdNum are longs in both. The Function returns an integer
 
What are the differing results? Also you will probably find the difference in speed is going to be minimal at best, it really may not be worth the effort of moving this function to C / C++
 
well the program I use this for does this function about 1 000 times on average per frame.

the C++ portion is returning arY, thats it
 
How are the results differing? Is the C++ one just comming up with a completely wrong number or just returning a number that is slightly off?

Could be down to rounding errors in the choice of data types.
 
Try this, grouping everything may help, Im not a C++ programmer though so I cant be sure
Code:
//C++ VS 2003
return (arY + (((arHeight - crdHeight) / NumCards) * crdNum));
 
ok, I changed the Function definition to:

C#:
short _stdcall SetYPosition(long NumCards, long crdNum, int crdHeight, int arHeight, int arY)

//it was:
//short _stdcall SetYPosition(int arY, long NumCards, long crdNum, int crdHeight, int arHeight)

now its returning the value of crdHeight every time!
 
got it! longs in C++ are integers in .NET :S working fine now thanx everyone
 
Back
Top