News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Bad conversion of int to double

Started by rudolf128, May 01, 2019, 09:55:58 PM

Previous topic - Next topic

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:


#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.

stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]