Open chaseWillden opened 7 years ago
Below C++ code about this situation.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int ten = 10;
float tenf = 10.1;
double tend = 10.1;
long tenl = 10.1;
cout << ten + 10 << endl;
cout << setprecision (15) << fixed << tenf + 10 << endl;
cout << setprecision (15) << fixed << tend + 10 << endl;
cout << setprecision (15) << fixed << tenl + 10 << endl;
return 0;
}
Output:
20
20.100000381469727
20.100000000000001
20
This bug is not about your implementation, I think the only thing to do is format the printed values.
@boranyldrm Interesting, thanks for looking into that. I found this comment on stackoverflow also. So I think instead of defaulting all the numbers to have a precision of 15 decimal places, there should be smarter math to ensure we don't go beyond a float's bounds. I think implementing a NTL number might be beneficial for a bigint or something like that.
When running the following code:
The following output occurs:
A
1
exists at the end. I've isolated where it exactly occurs, but I haven't been able to find out why.