Skip to content

Instantly share code, notes, and snippets.

@genkuroki
Created September 1, 2020 01:49
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/f822d11c0339abc3b004596cb5036b94 to your computer and use it in GitHub Desktop.
Save genkuroki/f822d11c0339abc3b004596cb5036b94 to your computer and use it in GitHub Desktop.
How to define a math constant
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "* https://github.com/JuliaLang/julia/blob/master/base/mathconstants.jl\n* https://github.com/JuliaLang/julia/blob/master/base/irrationals.jl"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "?Base.@irrational",
"execution_count": 1,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 1,
"data": {
"text/plain": "\u001b[36m @irrational sym val def\u001b[39m\n\u001b[36m @irrational(sym, val, def)\u001b[39m\n\n Define a new \u001b[36mIrrational\u001b[39m value, \u001b[36msym\u001b[39m, with pre-computed \u001b[36mFloat64\u001b[39m value \u001b[36mval\u001b[39m,\n and arbitrary-precision definition in terms of \u001b[36mBigFloat\u001b[39ms given be the\n expression \u001b[36mdef\u001b[39m.",
"text/markdown": "```\n@irrational sym val def\n@irrational(sym, val, def)\n```\n\nDefine a new `Irrational` value, `sym`, with pre-computed `Float64` value `val`, and arbitrary-precision definition in terms of `BigFloat`s given be the expression `def`.\n",
"text/latex": "\\begin{verbatim}\n@irrational sym val def\n@irrational(sym, val, def)\n\\end{verbatim}\nDefine a new \\texttt{Irrational} value, \\texttt{sym}, with pre-computed \\texttt{Float64} value \\texttt{val}, and arbitrary-precision definition in terms of \\texttt{BigFloat}s given be the expression \\texttt{def}.\n\n"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# Base.@irrational math_constant_name value_in_Float64 how_to_calculate_in_BigFloat\nBase.@irrational 🐻 1.41421356237309504880 √big(2)\n\n\"\"\"\n 🐻\n bear\n\nThe constant √2.\n\"\"\"\n🐻, const bear = 🐻",
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 2,
"data": {
"text/plain": "bear"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "🐻 # \\:bear: TAB",
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 3,
"data": {
"text/plain": "🐻 = 1.4142135623730..."
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "bear",
"execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 4,
"data": {
"text/plain": "🐻 = 1.4142135623730..."
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "float(🐻)",
"execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 5,
"data": {
"text/plain": "1.4142135623730951"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "big(🐻)",
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 6,
"data": {
"text/plain": "1.414213562373095048801688724209698078569671875376948073176679737990732478462102"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "Float32(🐻)",
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 7,
"data": {
"text/plain": "1.4142135f0"
},
"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": "f822d11c0339abc3b004596cb5036b94",
"data": {
"description": "How to define a math constant",
"public": true
}
},
"_draft": {
"nbviewer_url": "https://gist.github.com/f822d11c0339abc3b004596cb5036b94"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment