0

I have sometimes huge numbers where a 0 is expected:

-5.96046e-08, -2.98023e-08 ...

Even though it looks wrong, it still take it as a 0 (or maybe undefined?). Can someone tell me what is it, if it's normal, how to avoid, ...


for (int j = 0; j < samplesPerBlock; ++j)
{
    if (!jobDone)
    {
        job.amplitude =
            (job.elapsed <= job.attack) * (job.velocity / job.attack * job.elapsed) +
            (job.elapsed > job.attack && job.elapsed <= job.decay) * (job.velocity - (job.velocity - job.sustain) / (job.decay - job.attack) * (job.elapsed - job.attack)) +
            (job.elapsed > job.decay && job.on) * (job.sustain) +
            (!job.on && job.elapsed > job.decay) * (job.sustain - (job.sustain / job.release) * job.released);

        job.released += (!job.on && job.elapsed > job.decay);

        job.amplitude -= job.toChocke * (job.amplitude / job.chocke) * job.chocked;

        if (job.chocke == job.chocked)
        {
            jobDone = true;
            DBG(job.amplitude); // <- this is where I get those numbers
        }

        job.chocked += job.toChocke;
    }
}

Nick Mack
  • 75
  • 6
  • 4
    Those are both small numbers – drescherjm Feb 19 '21 at 22:29
  • If `-0.0000000596046` isn't close enough to `0` for your application then don't use floating point numbers – Alan Birtles Feb 19 '21 at 22:32
  • it is, I was just wondering why a float would show up like that instead of simply 0. I get it there's some imprecision, I just don't know if it would break my code or not. And if it's something expected, then I'm fine – Nick Mack Feb 19 '21 at 22:34
  • 3
    See the 'e-08' at the end? That means: times 10 to the power -8, in other words, put the decimal point 8 places to the left. So these aren't huge numbers, they are in fact numbers very close to 0. You sometimes get these because floating point numbers are imprecise, and the result of a calculation is sometimes not exactly 0 but some small number close to 0. – Jesper Feb 19 '21 at 22:35
  • 1
    `-5.96046 e -08` is scientific notation for `-0.0000000596046`. – Mooing Duck Feb 19 '21 at 22:40

0 Answers0