Showing the changes to Bitcrusher/Bitcrusher.cpp (1 of 72 files). Show all
Unified · Split
| @@ -120,9 +120,17 @@ CK_DLL_TICK(bitcrusher_tick) · 119 unmodified lines | ||
| 120 | 120 | |
| 121 | 121 | // convert to 32-bit int |
| 122 | 122 | t_CKINT shift = 32-bcdata->bits; |
| 123 | − int q32 = theSample * INT_MAX; | |
| 123 | + // cast to double for avoid floating point precision warning/error | (ge) 2023.4.14 | |
| 124 | + // "implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648" | |
| 125 | + // https://stackoverflow.com/questions/23420783/convert-int-max-to-float-and-then-back-to-integer | |
| 126 | + // for example... | |
| 127 | + // int i = ((float)(INT_MAX)); // on mac (intel and arm64) seem to produce arbitrary and different values | |
| 128 | + // int i = ((float)(INT_MAX)-64); // on mac appears stable | |
| 129 | + // int i = ((double)(INT_MAX)); // on mac appears stable | |
| 130 | + // int i = ((double)(INT_MAX)+.1); // on mac appears stable | |
| 131 | + // int i = ((double)(INT_MAX)+1); // on mac not stable | |
| 132 | + int q32 = ((double)theSample) * INT_MAX; | |
| 124 | 133 | q32 = (q32 >> shift) << shift; |
| 125 | − | |
| 126 | 134 | *out = q32 / ((float) INT_MAX); |
| 127 | 135 | |
| 128 | 136 | return TRUE; |