Skip to content

Instantly share code, notes, and snippets.

@genkuroki
Created September 1, 2020 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genkuroki/befb6d4b94c4a67683b592cc67435e93 to your computer and use it in GitHub Desktop.
Save genkuroki/befb6d4b94c4a67683b592cc67435e93 to your computer and use it in GitHub Desktop.
0.1
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "a = 0.1 # a は Float64 型の 0.1 になる\na",
"execution_count": 1,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 1,
"data": {
"text/plain": "0.1"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "big(0.1) # Float64型の0.1をBigFloatに変換するとこうなる",
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 2,
"data": {
"text/plain": "0.1000000000000000055511151231257827021181583404541015625"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "b = big\"0.1\" # b は BigFloat 型の 0.1 になる\nb",
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 3,
"data": {
"text/plain": "0.1000000000000000000000000000000000000000000000000000000000000000000000000000002"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "Float32(0.1)",
"execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 4,
"data": {
"text/plain": "0.1f0"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "Float64(Float32(0.1)) # 精度が低い型の0.1を高い型の0.1に変換するとこうなる",
"execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 5,
"data": {
"text/plain": "0.10000000149011612"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "function f(b)\n c::Float32 = 0 # c は Float32 型の 0 になる\n c = b # c は Float32 型に変換された b になる\n return c\nend\n\nc = f(b)",
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 6,
"data": {
"text/plain": "0.1f0"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "d = f(a)",
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 7,
"data": {
"text/plain": "0.1f0"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "d = f(Float16(0.1))",
"execution_count": 8,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 8,
"data": {
"text/plain": "0.099975586f0"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "julia-1.6-o3-depwarn",
"display_name": "Julia 1.6.0-DEV depwarn -O3",
"language": "julia"
},
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"base_numbering": 1,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"language_info": {
"file_extension": ".jl",
"name": "julia",
"mimetype": "application/julia",
"version": "1.6.0"
},
"@webio": {
"lastKernelId": null,
"lastCommId": null
},
"gist": {
"id": "befb6d4b94c4a67683b592cc67435e93",
"data": {
"description": "0.1",
"public": true
}
},
"_draft": {
"nbviewer_url": "https://gist.github.com/befb6d4b94c4a67683b592cc67435e93"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment