Julian West wrote:...with "possible loss of precision"
Campbell Ritchie wrote:
I am not sure I would call that loss of precision.Ganesh Patekar wrote:. . . results var = 2 because var/4 means 10 /4 which results 2 where we lost precision i.e. 0.5 because both diviser and dividend are int. . . .
5.1.3. Narrowing Primitive Conversion wrote:A narrowing primitive conversion from double to float is governed by the IEEE 754 rounding rules (§4.2.4). This conversion can lose precision, but also lose range,e resulting in a float zero from a nonzero double and a float infinity from a finite double. A double NaN is converted to a float NaN and a double infinity is converted to the same-signed float infinity.
A narrowing conversion of a signed integer to an integral type T simply discards all but the nlowest order bits, where n is the number of bits used to represent type T. In addition to a possible loss of information about the magnitude of the numeric value, this may cause the sign of the resulting value to differ from the sign of the input value.
Daniel Cox wrote:
Julian West wrote:...with "possible loss of precision"
From information I gathered in this thread, since integer division always discards the fractional part, you cannot say that integer division results in "loss of precision". You can say that integer division results in "loss of information" (which is worse than "loss of precision"). Precision comes into play with datatypes that have fractional parts. Precision is about how close measured values are to each other. So if you take multiple double measurements, you will get higher precision than multiple float measurements.
Campbell Ritchie wrote:
I am not sure I would call that loss of precision.Ganesh Patekar wrote:. . . results var = 2 because var/4 means 10 /4 which results 2 where we lost precision i.e. 0.5 because both diviser and dividend are int. . . .
Stephan van Hulst wrote:Try assigning a double to an int without casting it, and see what compiler error you get.
Julian West wrote:You quoted me out of context, missing my point.
Daniel Cox wrote:However, when dealing with whole numbers (as in integer division), there is no precision to lose.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |