floatf - wrong result

I am getting 0 instead 1 why?

1
2
H=1;
data->row_pointers[y][x]=(unsigned char)(roundf((H/360)*255));


result in float should be 0,7083 rounded should be 1.

Yet in watch panel I got result 12576! Confused
Last edited on
¿are you getting 0 or 12576?

Post a minimal snip that does reproduce your issue.
roundf((1/360)*255)
Produces 12576 according watch panel
Last edited on
1/360=0
0*255=0

not sure what are you watching
Ah, it's not float. Ok, I'll better use this:
roundf(H*0.002777*255)
OK, so what I must do to get 1?

1
2
H=1;
data->row_pointers[y][x]=roundf(H*0.002777*255);

Now it does correct result.
Topic archived. No new replies allowed.