How to get 64-bit intermediate results

R

Richard Cavell

Hi,

If I'm doing something like this:

#include<stdint.h>

uint64_t i = (0xffff * 0xffff ) ;

Or indeed any arbitrarily long expression, how do I ensure the
intermediate results won't be truncated to 32 bits without putting
irritating (uint64_t) casts next to each operand? And how do I get a
default sizeof(int) == 8 on an IA-64/G5?
 
M

msalters

Richard said:
Hi,

If I'm doing something like this:

#include<stdint.h>

uint64_t i = (0xffff * 0xffff ) ;

Wrong group, ask in comp.lang.c
( This is C99, in comp.lang.c++ only C++98/C++2003 are on-topic
and they are not based on C99 )

Regards,
Michiel Salters
 
R

Richard Cavell

Wrong group, ask in comp.lang.c
( This is C99, in comp.lang.c++ only C++98/C++2003 are on-topic
and they are not based on C99 )

Okay, then what's the equivalent C++ way to do it?
 
I

Ioannis Vranos

Richard said:
Hi,

If I'm doing something like this:

#include<stdint.h>

uint64_t i = (0xffff * 0xffff ) ;

Or indeed any arbitrarily long expression, how do I ensure the
intermediate results won't be truncated to 32 bits without putting
irritating (uint64_t) casts next to each operand? And how do I get a
default sizeof(int) == 8 on an IA-64/G5?


If your question is about C, you should ask in comp.lang.c.


If your question is .NET related (Visual C++ .NET) you should ask in
microsoft.public.dotnet.languages.vc newsgroup.

If it doesn't appear in your news server use the public MS news server:

msnews.microsoft.com
 
M

msalters

Richard said:
Okay, then what's the equivalent C++ way to do it?

unsigned long i = (0xffffUL*0xffffUL);

which will not overflow, but I don't see what 64 bits code has to
do with it. Besides, IIRC math base 2^32 doesn't care about overflows
on multiplications. ~0UL*~0UL==01UL, even if I use a 64-bits
intermediate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top