Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Problems with multiplications of doubles and/or floats

Reply
Thread Tools

Problems with multiplications of doubles and/or floats

 
 
Matt
Guest
Posts: n/a
 
      04-15-2004
J.K. Becker wrote:
> 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.

 
Reply With Quote
 
 
 
 
Michiel Salters
Guest
Posts: n/a
 
      04-15-2004
"J.K. Becker" <(E-Mail Removed)> wrote in message news:<c5jfaq$reo$(E-Mail Removed)-mainz.de>...
> 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
 
Reply With Quote
 
 
 
 
Benoit Mathieu
Guest
Posts: n/a
 
      04-15-2004
J.K. Becker wrote:
> 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...)
 
Reply With Quote
 
Matt
Guest
Posts: n/a
 
      04-23-2004
J.K. Becker wrote:
> 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?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do you convert and array of doubles into floats? SpreadTooThin Python 7 09-16-2006 01:14 AM
++ / -- operators with floats and doubles my.correo.basura@gmail.com C Programming 14 05-26-2005 12:59 PM
Re: Floats, doubles C and MSVC Andrew Reilly C Programming 2 10-14-2004 02:50 PM
floats doubles long doubles dan C++ 1 11-26-2003 05:12 AM
Comparing two floats or doubles to a precision {AGUT2} {H}-IWIK C++ 4 09-12-2003 02:51 PM



Advertisments