On 20/12/2024 12:46, beni.falk--- via Gcc-help wrote:
#define X_MIN -7.5
#define X_MAX 12.7
#define X_STEP 0.1
#define NPOINTS ((unsigned) (X_MAX - X_MIN) / X_STEP))
static int state[NPOINTS];
First, I hope you also got an error about the incorrect parentheses for
NPOINTS - when giving sample code, it's a good idea to test it!
The obvious fix here is :
#define X_MIN -75
#define X_MAX 127
#define X_STEP 01
#define NPOINTS (unsigned) ((X_MAX - X_MIN) / X_STEP)
int state[NPOINTS];
This has the additional advantage of getting NPOINTS correct. When you
use floating point, you can get surprising rounding errors - your
floating point version gave an array of 201 int's, while the expected
answer (which you get from the integer arithmetic version) is 202.