1

Have i been sitting in front of the code too long? To me it seems that 1.254771 is evaluated to be less than or equal to 0.255?

Both are floats. Maybe im just reserving things in my head but if i want true only if audiosrc.time is less than or equal to sfxPriorityRange this is correct right?

This is the code

   foreach (var audiosrc in playingAs)
    {
        if (audiosrc.time <= sfxPriorityRange)
        {
            hiPriorityAs.Add(audiosrc);
        }
}

enter image description here

Ruzihm
  • 19,749
  • 5
  • 36
  • 48
Daarwin
  • 2,896
  • 7
  • 39
  • 69
  • 1
    Have you manually checked their types to make sure they are floats and not strings? because if they are strings `sfxPriorityRange` would be less than `audiosrc.time` – CoderTang Nov 21 '21 at 17:11
  • 1
    If you can reproduce this issue, I'd recommend you to put a Debug.Log inside the if statement and see if it also reports the same values. Perhaps it's a rare VS bug. – yasirkula Nov 21 '21 at 17:19
  • 1
    Thabks for confirming that the code is correct at least. I'll try the debug log. And yes they are floats. The code is very small so far. So I know it all very well. – Daarwin Nov 21 '21 at 17:41
  • did you try replace "var" for the real type/class definition? For both elements. – Leandro Bardelli Nov 22 '21 at 18:30
  • Does this answer your question? [Floating point comparison functions for C#](https://stackoverflow.com/questions/3874627/floating-point-comparison-functions-for-c-sharp) – Leandro Bardelli Nov 22 '21 at 18:34

0 Answers0