Xilinx / Vitis-HLS-Introductory-Examples

Other
599 stars 158 forks source link

truncate toward to zero #2

Closed kimstik closed 2 years ago

kimstik commented 3 years ago

hamming_window.c

C++ on casting float to integer truncate toward to 0 here: rom_array[i] = (int16_t)(WIN_COEFF_SCALE * real_val);

Guess that correct rounding should be applied instead. hamm

ramanan-radhakrishnan commented 2 years ago

According to C++ rules, a C-style cast to an integer of a float value will result in the truncation of the value and the digits to the right of the decimal point are ignored.

kimstik commented 2 years ago

@ramanan-radhakrishnan C++ on casting float to integer truncate toward to 0. This is behavior according to C++. I don’t think we should rely on it to calculate the coefficients for windows. We are talking about the numerically correct hamming windowing implementation.

@ravicho It was excellent example What is the reason to drop it?

https://github.com/Xilinx/Vitis-HLS-Introductory-Examples/commit/eb18e89caf94324b9ea836a09d2d33c12c5af70b

ramanan-radhakrishnan commented 2 years ago

Hi @kimstik,

Okay - we will add a call to round before the cast to integer to achieve the desired result.

The example will be back soon. Good to hear feedback that it was a good example. It will be updated and brought back soon.