Click here to Skip to main content
16,011,482 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Finding the dimensions of a PNG File Pin
David Crow8-May-03 7:33
David Crow8-May-03 7:33 
GeneralRe: Finding the dimensions of a PNG File Pin
Real World8-May-03 7:40
Real World8-May-03 7:40 
GeneralRe: Finding the dimensions of a PNG File Pin
Real World8-May-03 7:56
Real World8-May-03 7:56 
GeneralRe: Finding the dimensions of a PNG File Pin
David Crow8-May-03 9:09
David Crow8-May-03 9:09 
GeneralRe: Finding the dimensions of a PNG File Pin
David Crow8-May-03 10:22
David Crow8-May-03 10:22 
GeneralI hate __int64! Pin
Simon Steele8-May-03 3:43
Simon Steele8-May-03 3:43 
GeneralRe: I hate __int64! Pin
David Crow8-May-03 4:08
David Crow8-May-03 4:08 
GeneralRe: I hate __int64! Pin
Len Holgate8-May-03 4:26
Len Holgate8-May-03 4:26 
Check your tests?

The second two should work fine. The first one fails because the values are multiplied as longs and then returned as a uint64. The multiplication as a long wraps. Casting one value to a uint64 will make the multiplication occur on uint64's and should give correct results.

Your message mentions 0xba5da800 * 0x38E = 0x29678EB3000 at the top and your tests use 0xba5e3500 * 1000...

The code below seeems to give the results you expect.

typedef unsigned __int64 uint64_t;<br />
<br />
unsigned long myVal = 0xba5da800 ;<br />
<br />
uint64_t myfunction1(unsigned long val)<br />
{<br />
	return val * 0x38E;<br />
}<br />
<br />
uint64_t myfunction2(unsigned long val)<br />
{<br />
	return ((uint64_t)val * (uint64_t)0x38E);<br />
}<br />
<br />
uint64_t myfunction3(unsigned long val)<br />
{<br />
	return (uint64_t)((uint64_t)val * (uint64_t)0x38E);<br />
}<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
	uint64_t result1 = myfunction1(myVal);<br />
	uint64_t result2 = myfunction2(myVal);<br />
	uint64_t result3 = myfunction3(myVal);<br />
<br />
	printf("myfunction1 - 0x%I64x\n", result1);<br />
	printf("myfunction2 - 0x%I64x\n", result2);<br />
	printf("myfunction3 - 0x%I64x\n", result3);<br />
<br />
	return 0;<br />
}


Len Holgate
www.jetbyte.com
The right code, right now.
GeneralRe: I hate __int64! Pin
Simon Steele8-May-03 4:41
Simon Steele8-May-03 4:41 
Generalfile properties Pin
urid8-May-03 3:32
urid8-May-03 3:32 
GeneralRe: file properties Pin
JensB8-May-03 3:44
JensB8-May-03 3:44 
GeneralRe: file properties Pin
David Crow8-May-03 4:10
David Crow8-May-03 4:10 
GeneralRe: file properties Pin
urid8-May-03 4:24
urid8-May-03 4:24 
GeneralRe: file properties Pin
David Crow8-May-03 3:52
David Crow8-May-03 3:52 
GeneralRe: file properties Pin
urid8-May-03 4:15
urid8-May-03 4:15 
GeneralRe: file properties Pin
David Crow8-May-03 4:43
David Crow8-May-03 4:43 
Generalcenter text in title bar of app. Pin
JensB8-May-03 3:04
JensB8-May-03 3:04 
GeneralRe: center text in title bar of app. Pin
David Crow8-May-03 4:25
David Crow8-May-03 4:25 
GeneralRe: center text in title bar of app. Pin
JensB8-May-03 4:30
JensB8-May-03 4:30 
GeneralRe: center text in title bar of app. Pin
Renjith Ramachandran8-May-03 5:14
Renjith Ramachandran8-May-03 5:14 
GeneralRe: center text in title bar of app. Pin
User 66588-May-03 6:17
User 66588-May-03 6:17 
GeneralRe: center text in title bar of app. Pin
Joan M8-May-03 5:57
professionalJoan M8-May-03 5:57 
GeneralRe: center text in title bar of app. Pin
Hari Krishnan (Noida)8-May-03 6:14
Hari Krishnan (Noida)8-May-03 6:14 
GeneralRe: center text in title bar of app.(Found the link) Pin
Hari Krishnan (Noida)8-May-03 6:22
Hari Krishnan (Noida)8-May-03 6:22 
QuestionC++ Function objects - how to use them? Pin
Ilushka8-May-03 2:37
Ilushka8-May-03 2:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.