Here's an oddity (to me, at least). This routine prints true:
double x = 11.0;
double y = 10.0;
if (x-y == 1.0) {
// print true
} else {
// print false
}
But this routine prints false:
double x = 1.1;
double y = 1.0;
if (x-y == 0.1) {
// print true
} else {
// print false
}
Anyone care to explain what's going on here? I'm guessing it has something to do with integer arithmetic for int
s posing as float
s. Also, are there other bases (other than 10
) that have this property?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…