Projectitis
Well-known member
I am using the Arduino IDE, so yes, it exists there in my case.
Yes, the f suffix can be used - see code below. Other suffixes exist too, for binary, long etc, to force the compiler to use a specific type for that constant/literal.
Running your example gives results as expected.
Also running this modified example which is much closer to my code gives results as expected:
However, the matching code snippet within my project (also in Arduino IDE) gives the error that I explained.
The compiler is very clever and makes assumptions based on all sorts of things. The resulting assembler for this basic example is sure to be different from the same code in my full project because of the differences in the code that surrounds it. For example - in the code snippets above, the compiler will probably deduce that idx, ix and iy are all just constants, and compile differently than in other cases. There are many other subtle differences between my full code and these smaller examples.
Yes, the f suffix can be used - see code below. Other suffixes exist too, for binary, long etc, to force the compiler to use a specific type for that constant/literal.
Running your example gives results as expected.
Also running this modified example which is much closer to my code gives results as expected:
Code:
float i[2] = {0.0f, 0.0f};
uint16_t idx = 0;
float ix = -1.0f;
float iy = 1.0f;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(2000);
}
void loop() {
i[idx] += 0.01;
int16_t smp = 2048 + (i[idx] * 2048);
Serial.println( smp );
if (i[idx] >= iy) i[idx] = ix;
delay(20);
}
However, the matching code snippet within my project (also in Arduino IDE) gives the error that I explained.
The compiler is very clever and makes assumptions based on all sorts of things. The resulting assembler for this basic example is sure to be different from the same code in my full project because of the differences in the code that surrounds it. For example - in the code snippets above, the compiler will probably deduce that idx, ix and iy are all just constants, and compile differently than in other cases. There are many other subtle differences between my full code and these smaller examples.