This is probably the fifth time I am reading this book and everytime around I notice little details that I had not noticed previously. This time, right on the beginning of the book, something caught my attention. On page 12, there's a program that prints the Fahrenheit-Celsius table and the authors use floats to store both temperatures. There is also a while loop where they compare the current value of the fahr variable against the value of the upper limit of the table, which is an int. So we have this:
I understand that in an operation, operands have to have the same types, so in this case, upper, which is an int, will be converted to float before the comparison is done, right? Now isn't it dangerous to compare floating-point values? Isn't it almost the same as doing something such as this?Code:float fahr; int upper = 300; while (fahr <= upper) ...
Thanks.Code:float i; for (i = 0.0; i <= 10.0; i += 0.1) ...