Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: rudolf128 on May 01, 2019, 09:55:58 pm

Title: Bad conversion of int to double
Post by: rudolf128 on May 01, 2019, 09:55:58 pm
I have a rather large program of a Software Synthesizer. While modifying it, it gave me an error. I traced the error to a small routine, and there I found a failing conversion of int to double. I tried to construct a very small program that did the same thing, but the routine worked OK then. The original routine is as follows:

Code
#define REAL2 double

void Fadeinmag(void)
// "Magic" fade-in
{
  REAL2 a, t;
  a = (Oldtime - Par.sr) / (REAL2)(Par.ed - Par.sr);
  t = a * a;
  Pars[Par.ix].fade = t / (1 + (t - a) * 2);
}

Par.ed, Par.sr and Oldtime are all int global variables. My PC is 64 bits, and I use Windows 10 and Mingw compiler and last Code::Blocks version, but I am not using any nightly build.
While debugging it with the standard debugger, I found that after being assigned, variable 'a' had a NAN value, which should instead be 0, because Par.ed = 352597, Par.sr = 350342, and Oldtime = 350342 at the time.
Any help will be appreciated.
Title: Re: Bad conversion of int to double
Post by: stahta01 on May 02, 2019, 04:32:47 am
http://www.catb.org/~esr/faqs/smart-questions.html#forum (http://www.catb.org/~esr/faqs/smart-questions.html#forum)
http://forums.codeblocks.org/index.php/topic,9996.0.html (http://forums.codeblocks.org/index.php/topic,9996.0.html)