User forums > General (but related to Code::Blocks)

Bad conversion of int to double

(1/1)

rudolf128:
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);
}


--- End code ---
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.

stahta01:
http://www.catb.org/~esr/faqs/smart-questions.html#forum
http://forums.codeblocks.org/index.php/topic,9996.0.html

Navigation

[0] Message Index

Go to full version