Author Topic: Bad conversion of int to double  (Read 748 times)

Offline rudolf128

  • Multiple posting newcomer
  • *
  • Posts: 29
Bad conversion of int to double
« 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: [Select]
#define REAL2 double

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

Par.ed, 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, = 350342, and Oldtime = 350342 at the time.
Any help will be appreciated.

Online stahta01

  • Lives here!
  • ****
  • Posts: 6909
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
When in doubt, read the CB WiKi FAQ.