Created
January 31, 2024 05:38
-
-
Save zeddee/0ad9c0e1d0ec69e225edb185807b183f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "initial_id", | |
"metadata": { | |
"collapsed": true, | |
"ExecuteTime": { | |
"end_time": "2024-01-31T04:11:38.586157Z", | |
"start_time": "2024-01-31T04:11:38.582315Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"True\n", | |
"True\n", | |
"False\n", | |
"True\n", | |
"True\n", | |
"False\n", | |
"False\n", | |
"True\n", | |
"True\n" | |
] | |
} | |
], | |
"source": [ | |
"# https://docs.python.org/3/tutorial/floatingpoint.html\n", | |
"a = 0.1\n", | |
"print(a * 1 == 0.1)\n", | |
"print(a * 2 == 0.2)\n", | |
"print(a * 3 == 0.3)\n", | |
"print(a * 4 == 0.4)\n", | |
"print(a * 5 == 0.5)\n", | |
"print(a * 6 == 0.6)\n", | |
"print(a * 7 == 0.7)\n", | |
"print(a * 8 == 0.8)\n", | |
"print(a * 9 == 0.9)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"False\n", | |
"False\n", | |
"True\n", | |
"False\n", | |
"False\n", | |
"True\n", | |
"True\n", | |
"False\n", | |
"False\n" | |
] | |
} | |
], | |
"source": [ | |
"print(a * 1 > 0.1)\n", | |
"print(a * 2 > 0.2)\n", | |
"print(a * 3 > 0.3)\n", | |
"print(a * 4 > 0.4)\n", | |
"print(a * 5 > 0.5)\n", | |
"print(a * 6 > 0.6)\n", | |
"print(a * 7 > 0.7)\n", | |
"print(a * 8 > 0.8)\n", | |
"print(a * 9 > 0.9)" | |
], | |
"metadata": { | |
"collapsed": false, | |
"ExecuteTime": { | |
"end_time": "2024-01-31T05:19:46.395912Z", | |
"start_time": "2024-01-31T05:19:46.390028Z" | |
} | |
}, | |
"id": "53d537f580ef3a6c", | |
"execution_count": 16 | |
}, | |
{ | |
"cell_type": "code", | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n" | |
] | |
} | |
], | |
"source": [ | |
"import math\n", | |
"# Equality only\n", | |
"print(math.isclose(a * 1, 0.1))\n", | |
"print(math.isclose(a * 2, 0.2))\n", | |
"print(math.isclose(a * 3, 0.3))\n", | |
"print(math.isclose(a * 4, 0.4))\n", | |
"print(math.isclose(a * 5, 0.5))\n", | |
"print(math.isclose(a * 6, 0.6))\n", | |
"print(math.isclose(a * 7, 0.7))\n", | |
"print(math.isclose(a * 8, 0.8))\n", | |
"print(math.isclose(a * 9, 0.9))" | |
], | |
"metadata": { | |
"collapsed": false, | |
"ExecuteTime": { | |
"end_time": "2024-01-31T05:35:07.258823Z", | |
"start_time": "2024-01-31T05:35:07.240412Z" | |
} | |
}, | |
"id": "d20f6c5afdb8cf36", | |
"execution_count": 18 | |
}, | |
{ | |
"cell_type": "code", | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n" | |
] | |
} | |
], | |
"source": [ | |
"print(math.floor(a * 1) == math.floor(0.1))\n", | |
"print(math.floor(a * 2) == math.floor(0.2))\n", | |
"print(math.floor(a * 3) == math.floor(0.3))\n", | |
"print(math.floor(a * 4) == math.floor(0.4))\n", | |
"print(math.floor(a * 5) == math.floor(0.5))\n", | |
"print(math.floor(a * 6) == math.floor(0.6))\n", | |
"print(math.floor(a * 7) == math.floor(0.7))\n", | |
"print(math.floor(a * 8) == math.floor(0.8))\n", | |
"print(math.floor(a * 9) == math.floor(0.9))" | |
], | |
"metadata": { | |
"collapsed": false, | |
"ExecuteTime": { | |
"end_time": "2024-01-31T05:37:29.853404Z", | |
"start_time": "2024-01-31T05:37:29.839919Z" | |
} | |
}, | |
"id": "60172cdcba77ba74", | |
"execution_count": 21 | |
}, | |
{ | |
"cell_type": "code", | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n", | |
"True\n" | |
] | |
} | |
], | |
"source": [ | |
"print(math.floor(a * 1) > math.floor(0.1))\n", | |
"print(math.floor(a * 2) > math.floor(0.2))\n", | |
"print(math.floor(a * 3) > math.floor(0.3))\n", | |
"print(math.floor(a * 4) > math.floor(0.4))\n", | |
"print(math.floor(a * 5) > math.floor(0.5))\n", | |
"print(math.floor(a * 6) > math.floor(0.6))\n", | |
"print(math.floor(a * 7) > math.floor(0.7))\n", | |
"print(math.floor(a * 8) > math.floor(0.8))\n", | |
"print(math.floor(a * 9) > math.floor(0.9))" | |
], | |
"metadata": { | |
"collapsed": false, | |
"ExecuteTime": { | |
"end_time": "2024-01-31T05:37:54.291153Z", | |
"start_time": "2024-01-31T05:37:54.283402Z" | |
} | |
}, | |
"id": "9467639687c0299d", | |
"execution_count": 23 | |
}, | |
{ | |
"cell_type": "code", | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"b = 1\n", | |
"(b * 3)/10 == 0.3" | |
], | |
"metadata": { | |
"collapsed": false, | |
"ExecuteTime": { | |
"end_time": "2024-01-31T04:11:38.598311Z", | |
"start_time": "2024-01-31T04:11:38.590087Z" | |
} | |
}, | |
"id": "be8cbef72dc8dfd9", | |
"execution_count": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"round(0.1, 1) + round(0.1, 1) + round(0.1, 1) == round(0.3, 1)" | |
], | |
"metadata": { | |
"collapsed": false, | |
"ExecuteTime": { | |
"end_time": "2024-01-31T04:11:38.598436Z", | |
"start_time": "2024-01-31T04:11:38.593900Z" | |
} | |
}, | |
"id": "1bf5363d15ca5675", | |
"execution_count": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"0.1 * 10**18 == 1 * 10**17" | |
], | |
"metadata": { | |
"collapsed": false, | |
"ExecuteTime": { | |
"end_time": "2024-01-31T04:11:38.598590Z", | |
"start_time": "2024-01-31T04:11:38.596204Z" | |
} | |
}, | |
"id": "217b0281906d864", | |
"execution_count": 5 | |
}, | |
{ | |
"cell_type": "code", | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"True\n", | |
"True\n", | |
"False\n", | |
"True\n", | |
"True\n", | |
"False\n", | |
"False\n", | |
"True\n", | |
"True\n" | |
] | |
} | |
], | |
"source": [ | |
"import numpy as np\n", | |
"b = np.float64(0.1)\n", | |
"\n", | |
"print(b * 1 == np.float64(0.1))\n", | |
"print(b * 2 == np.float64(0.2))\n", | |
"print(b * 3 == np.float64(0.3))\n", | |
"print(b * 4 == np.float64(0.4))\n", | |
"print(b * 5 == np.float64(0.5))\n", | |
"print(b * 6 == np.float64(0.6))\n", | |
"print(b * 7 == np.float64(0.7))\n", | |
"print(b * 8 == np.float64(0.8))\n", | |
"print(b * 9 == np.float64(0.9))" | |
], | |
"metadata": { | |
"collapsed": false, | |
"ExecuteTime": { | |
"end_time": "2024-01-31T05:21:32.909524Z", | |
"start_time": "2024-01-31T05:21:32.904953Z" | |
} | |
}, | |
"id": "28d860bbd6d7e63c", | |
"execution_count": 17 | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment