A double variable equals one, it also doesn't equal one.
I have this code:
Code:
#include <stdio.h>
int main()
{
double temp;
temp = 0;
temp = temp + .6;
temp = temp + .3;
temp = temp + .1;
printf("%lf\n", temp);
if(temp != 1)
{
printf("Improper matrix! Please use another.\n");
}
return(0);
}
I'm sure most people know why it prints "Improper matrix! Please use another."
I have no idea what to search for, so I guess I'll ask you guys/girls why it does this (besides the fact that .6+.3+.1 != 1).
Yesterday when I was working on it, it printed it when I was using if(temp == 1), today it won't.
Edit: Apparently using %.999lf prints:
.9999999999999998889776975374843459576368331909179 687500..0 How interesting. Is there a way to get around this?