You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the expression 59.99 + 0.01, the expected result is 60.0, but I'm getting 60.0999.... I understand that this discrepancy is due to floating-point computing. How can I avoid this issue?
I'm also writing a test case, and in most situations, the result is not 60.0. MathSolver is a simple wrapper for try str.evaluate().
func testExample()throws{
// 59.99 + 0.01 -> ("60.099999999999994") is not equal to ("60.0")
fornin1...99{letlhs="59."+ Array(repeating:"9", count: n).joined()letrhs="0."+ Array(repeating:"1", count: n).joined()letresult=MathSolver.solve(lhs +" + "+ rhs)!
XCTAssertEqual(result,60.0,"\n🔢 \(lhs)")}}
The text was updated successfully, but these errors were encountered:
For the expression
59.99 + 0.01
, the expected result is60.0
, but I'm getting60.0999....
I understand that this discrepancy is due to floating-point computing. How can I avoid this issue?I'm also writing a test case, and in most situations, the result is not 60.0.
MathSolver
is a simple wrapper fortry str.evaluate()
.The text was updated successfully, but these errors were encountered: