2024-01-20 12:43 AM - edited 2024-01-20 12:44 AM
Hello everyone, can someone tell me why casting doesn't work. I want to convert int values of an array to float.
for (int i = 0; i<= adcBufferSize; i++)
{
adc_buffer_float[i] = (float)adc_buffer [i];
}
2024-01-20 12:55 AM
Show an example data set that's "Not Working"
2024-01-20 01:05 AM
2024-01-20 01:17 AM - edited 2024-01-20 01:18 AM
Ok that seems to illustrate the input, it doesn't show the "not working" nor does it show or explain how the output is wrong or incorrect.
What's the expectation and how does that differ from reality?
2024-01-20 01:53 AM
Aren't the float numbers supposed to look like this 4076.0 ; 4082.0 ; 3.0 ; 1.0 ?
2024-01-20 09:00 AM
One might hope the debugger would display that way.
Hard to tell from here how the array is actually defined.
You could do the conversion / ranging in a single step. Probably want to use 2048.0f there
2024-01-20 09:39 AM - edited 2024-01-20 10:36 AM
Nope, debugger traditionally displays the float format as *(float*)( & variable ) rather than (float)variable. If you want the latter, use expressions.
2024-01-20 09:59 AM
Maybe you expect something new - but : 946 (int) -> still 946 (float) , just could write as 946.0 ;
so debug shows correct your float, just without x.000 , if nothing fractional there.
b= 2.6 , but for b= 3. 0 ->
ok ?
2024-01-21 09:43 AM
2024-01-21 09:43 AM
Great, thank you very much for the feedback!