JuliaKurs23/nb/example.ipynb
2023-05-12 20:12:56 +02:00

147 lines
2.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "1847e5bc",
"metadata": {},
"source": [
"# Some Julia Code\n",
"\n",
"\n",
"1. ?forvarianrte\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd1a489b",
"metadata": {},
"outputs": [],
"source": [
"?for"
]
},
{
"cell_type": "markdown",
"id": "62aee612",
"metadata": {},
"source": [
"## Einfache rechnerei\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23afd224",
"metadata": {},
"outputs": [],
"source": [
"2^33+33"
]
},
{
"cell_type": "markdown",
"id": "d1f050b2",
"metadata": {},
"source": [
"## colored console graphs produced by `Benchmarktools.jl`\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a9b6a7c8",
"metadata": {},
"outputs": [],
"source": [
"using BenchmarkTools\n",
"\n",
"@benchmark sum(rand(1000))"
]
},
{
"cell_type": "markdown",
"id": "948d948e",
"metadata": {},
"source": [
"## structure of floating point numbers\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fbe94ce0",
"metadata": {},
"outputs": [],
"source": [
"function printbitsf64(x::Float64)\n",
" s = bitstring(x)\n",
" printstyled(s[1], color = :blue, reverse=true)\n",
" printstyled(s[2:12], color = :green, reverse=true)\n",
" printstyled(s[13:end], color=:red, bold=true, reverse=true)\n",
" print(\"\\n\")\n",
"end\n",
"\n",
"printbitsf64(27.56640625)"
]
},
{
"cell_type": "markdown",
"id": "611f43fa",
"metadata": {},
"source": [
"### illustrate machine epsilon...\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "294f9e7e",
"metadata": {},
"outputs": [],
"source": [
"Eps=0.5\n",
"while 1 != 1 + Eps\n",
" Eps /= 2\n",
" printbitsf64(1+Eps)\n",
"end"
]
},
{
"cell_type": "markdown",
"id": "34e578b1",
"metadata": {},
"source": [
"### ... some ugly colors\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9771dbc3",
"metadata": {},
"outputs": [],
"source": [
"function printbits2f64(x::Float64)\n",
" s = bitstring(x)\n",
" printstyled(s[1], color = 142, reverse=true)\n",
" printstyled(s[2:12], color = 190, reverse=false, underline=true)\n",
" printstyled(s[13:end], color= 27, bold=true, reverse=true)\n",
" print(\"\\n\")\n",
"end\n",
"\n",
"printbits2f64(27.56640625)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.8.5",
"language": "julia",
"name": "julia-1.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}