S
Stef
Hello
I have been programming C now for a couple of months but at this
moment I am a bit confused with types like double float etc..
My question wat type does the result have when a double value is mixed
with an int... In the snippet below I substract a double with an int
but the results are.. unpredictable for me.
Can I mix ints with doubles doing floating point calculations ?
#include <stdio.h>
int main(int argc, char *argv[]) {
double C, M, Y;
int R, G, B;
C = M = Y = 0;
R = 128;
G = 211;
B = 87;
printf("type is INT: red:%d, green:%d, blue:%d\n", R, G, B);
printf("type is DOUBLE: red:%g, green:%g, blue:%g\n",
(double)R / 255, (double)G / 255, (double)B / 255);
C = 1.0 - (R / 255);
M = 1.0 - (G / 255);
Y = 1.0 - (B / 255);
printf("ONE - C: %g, M: %g, Y: %g\n", C, M, Y);
printf("TWO - C: %g, M: %g, Y: %g\n", (double)C, (double)M,
(double)Y);
printf("THREE - C: %g, M: %g, Y: %g\n",
(1.0 - (R / 255)), (1.0 - (G / 255)), (1.0 - (Y / 255)));
printf("FOUR - C: %g, M: %g, Y: %g\n",
(double)(1.0 - (R / 255)), (double)(1.0 - (G / 255)), (double)(1.0
- (Y / 255)));
return 0;
}
I have been programming C now for a couple of months but at this
moment I am a bit confused with types like double float etc..
My question wat type does the result have when a double value is mixed
with an int... In the snippet below I substract a double with an int
but the results are.. unpredictable for me.
Can I mix ints with doubles doing floating point calculations ?
#include <stdio.h>
int main(int argc, char *argv[]) {
double C, M, Y;
int R, G, B;
C = M = Y = 0;
R = 128;
G = 211;
B = 87;
printf("type is INT: red:%d, green:%d, blue:%d\n", R, G, B);
printf("type is DOUBLE: red:%g, green:%g, blue:%g\n",
(double)R / 255, (double)G / 255, (double)B / 255);
C = 1.0 - (R / 255);
M = 1.0 - (G / 255);
Y = 1.0 - (B / 255);
printf("ONE - C: %g, M: %g, Y: %g\n", C, M, Y);
printf("TWO - C: %g, M: %g, Y: %g\n", (double)C, (double)M,
(double)Y);
printf("THREE - C: %g, M: %g, Y: %g\n",
(1.0 - (R / 255)), (1.0 - (G / 255)), (1.0 - (Y / 255)));
printf("FOUR - C: %g, M: %g, Y: %g\n",
(double)(1.0 - (R / 255)), (double)(1.0 - (G / 255)), (double)(1.0
- (Y / 255)));
return 0;
}