diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-09-22 21:48:21 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-09-22 21:48:21 +0200 |
commit | 88a6e495154f72127f208455f40201d3e17e423a (patch) | |
tree | 751e72b8d78f807d97ad8ffde9349baf1c079b12 | |
parent | 01bcfc5d692236bffeec5b8de2c27138e71d2bd6 (diff) | |
download | toolame-dab-88a6e495154f72127f208455f40201d3e17e423a.tar.gz toolame-dab-88a6e495154f72127f208455f40201d3e17e423a.tar.bz2 toolame-dab-88a6e495154f72127f208455f40201d3e17e423a.zip |
Repair PSY model 2 and 4
Fix an undefined behaviour arising when a float infinite is casted
to an int.
-rw-r--r-- | fft.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -1191,8 +1191,16 @@ static void fht (FLOAT * fz) INLINE FLOAT atan_table(FLOAT y, FLOAT x) { int index; + double index_d = ATANSCALE * fabs(y/x); + + // Don't cast an infinite to an int, that's undefined behaviour + if (isfinite(index_d)) { + index = (int)(ATANSCALE * fabs(y/x)); + } + else { + index = ATANSIZE-1; + } - index = (int)(ATANSCALE * fabs(y/x)); if (index>=ATANSIZE) index = ATANSIZE-1; |