Skip to content

Commit

Permalink
Fix float comparison solution (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha authored May 3, 2024
1 parent 89d465e commit e419b84
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions basic_datatypes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@
},
"outputs": [],
"source": [
"import math\n",
"\n",
"a = 0.1 + 0.2\n",
"b = 0.3\n",
"print(f\"Is {a} equal to {b}? {a == b}\")\n",
Expand Down Expand Up @@ -2203,7 +2205,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -2739,7 +2740,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.11.1"
},
"vscode": {
"interpreter": {
Expand Down
3 changes: 2 additions & 1 deletion tutorial/tests/test_basic_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_quadratic_equation(


def reference_a_plus_b_equals_c(a: float, b: float, c: float) -> bool:
return a + b == c
return math.isclose(a + b, c)


@pytest.mark.parametrize(
Expand All @@ -103,6 +103,7 @@ def reference_a_plus_b_equals_c(a: float, b: float, c: float) -> bool:
(23.1, 1.8, 14.2),
(-10.5, 7.4, 84),
(1e-5, 3.5e-5, 2.5),
(0.1, 0.2, 0.3),
],
)
def test_a_plus_b_equals_c(
Expand Down

0 comments on commit e419b84

Please sign in to comment.