Problems with multiplications of doubles and/or floats

M

Matt

J.K. Becker said:
Hi there,

I am trying to multiply doubles with floats (actually I tried every
possible combination by now) and it never works (well, it does something
but it is always wrong). I have no idea what it is and where to look for
help, maybe some of you know?

double=float*double; (or every possible combination of it). An example:

0.3 * 0.7 would result in 1.7 (with lots more digits). Anyone any idea?
If I change the types of the variables I think the result stays the same
(but I am not 100% sure)...

Jens

Show us the format string for the print statement that prints the
incorrect value.
 
M

Michiel Salters

J.K. Becker said:
Hi there,

I am trying to multiply doubles with floats (actually I tried every
possible combination by now) and it never works (well, it does something
but it is always wrong). I have no idea what it is and where to look for
help, maybe some of you know?

double=float*double; (or every possible combination of it). An example:

0.3 * 0.7 would result in 1.7 (with lots more digits). Anyone any idea?
If I change the types of the variables I think the result stays the same
(but I am not 100% sure)...

Jens

Well, you can't actually multiply a double and a float. However, if you
write 0.3 * 0.7f, you will get a float->double conversion, so in fact
you will multiply two doubles. Why don't you add a few lines to your
main printing this? If it fails, remove parts of your program until
it work. If it works, move these test lines closer to your problem area
until it fails.

Regards,
Michiel Salters
 
B

Benoit Mathieu

J.K. Becker said:
Hi there,

I am trying to multiply doubles with floats (actually I tried every
possible combination by now) and it never works (well, it does something
but it is always wrong). I have no idea what it is and where to look for
help, maybe some of you know?

double=float*double; (or every possible combination of it). An example:

0.3 * 0.7 would result in 1.7 (with lots more digits). Anyone any idea?
If I change the types of the variables I think the result stays the same
(but I am not 100% sure)...

Jens

Some ideas :

Maybe you have macros redefining something (i had a look at
the code on cvs, and i saw things like #define XY 0, so
maybe some very common names are defined somewhere...

Stack overflow ? (does that kind of thing still exist
nowadays ?) (try adding some dummy variable declarations in
the function (double bigarray[1000] or so)

Check again that optimizations are turned off (I don't see
other reasons for the debugger to hop back and forth in the
code...)

Also, try to turn off cpu specific assembly code generation
(-i686 or so...)
 
M

Matt

J.K. Becker said:
Hi there,

I am trying to multiply doubles with floats (actually I tried every
possible combination by now) and it never works (well, it does something
but it is always wrong). I have no idea what it is and where to look for
help, maybe some of you know?

double=float*double; (or every possible combination of it). An example:

0.3 * 0.7 would result in 1.7 (with lots more digits). Anyone any idea?
If I change the types of the variables I think the result stays the same
(but I am not 100% sure)...

Jens

What was the resolution of this?
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top