Csound Csound-dev Csound-tekno Search About

[Csnd-dev] nans and fastmath

Date2022-05-08 12:55
FromEduardo Moguillansky
Subject[Csnd-dev] nans and fastmath
Hi. I need to detect nans coming from a sensor. When building csound with fast-math (which sets no-infinite-math or finite-math-only flags depending on the compiler) the 'isnan' function is optimized away. In this context the opcode 'qnan' always returns 0.
I have a fix against the csound6 branch. The same fix can applied to csound7.
Csound code to test:

<CsoundSynthesizer>
<CsInstruments>    

instr 1
  i0 = 0/0
  i1 = 1
  prints "i0: %f, nan: %d\n", i0, qnan:i(i0)
  prints "i1: %f, nan: %d\n", i1, qnan:i(i1)

endin

schedule 1, 0, 0

</CsInstruments>
</CsoundSynthesizer>

This prints:
i0: -nan, nan: 0
i1: 1.000000, nan: 0


After the fix:

i0: -nan, nan: 1
i1: 1.000000, nan: 0


Fix:

https://github.com/gesellkammer/csound/commit/ef66b9b715aabd115d584d82d207700afd03601c