Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
| const HI = prevfloat(log10(prevfloat(Inf))) | |
| function test(n) | |
| xx = 0.0 | |
| zz = 0.0 | |
| for i = 1:n | |
| x = reinterpret(Float64, rand(reinterpret(UInt64, 1e-18):reinterpret(UInt64, HI))) | |
| if rand(Bool) | |
| x = -x | |
| end |
This file contains hidden or 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
| # sudo apt install llvm-3.9-dev libopenblas-dev libfftw3-dev libgmp3-dev libmpfr-dev libarpack2-dev libopenspecfun-dev libssh2-1-dev libcurl4-openssl-dev | |
| USE_SYSTEM_LLVM:=1 | |
| LLVM_CONFIG:=llvm-config-3.9 | |
| USE_SYSTEM_BLAS:=1 | |
| LIBBLAS:=-lopenblas | |
| LIBBLASNAME:=libopenblas | |
| USE_SYSTEM_LAPACK:=1 | |
| USE_SYSTEM_LIBM:=1 |
This file contains hidden or 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
| import Base: TwicePrecision, significand_bits, significand_mask, exponent_mask, exponent_bias | |
| # Bits of 1/2π | |
| # 1/2π == sum(x / 0x1p64^i for i,x = enumerate(INV2PI)) | |
| # Can be obtained by: | |
| # | |
| # setprecision(BigFloat, 4096) | |
| # I = 0.5/big(pi) | |
| # for i = 1:19 | |
| # I *= 0x1p64 |
This file contains hidden or 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
| @eval macro $(Symbol("ccall"))(expr) | |
| expr.head == :(::) && expr.args[1].head == :call || error("Invalid use of @ccall") | |
| rettype = expr.args[2] | |
| fname = expr.args[1].args[1] | |
| cargs = expr.args[1].args[2:end] | |
| arglist = [] | |
| typlist = [] | |
| tupexpr = :(()) | |
| ccexpr = :(ccall($(esc(fname)), $(esc(rettype)), $(esc(tupexpr)))) |
This file contains hidden or 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
| # read from Raspbery Pi Sense HAT joystick | |
| function _stick_input_dev() | |
| try | |
| for devname in readdir("/sys/class/input") | |
| sysfname = joinpath("/sys/class/input",devname,"device","name") | |
| if startswith(devname, "event") && isfile(sysfname) | |
| if startswith(readstring(sysfname),"Raspberry Pi Sense HAT Joystick") | |
| return joinpath("/dev/input",devname) | |
| end |
This file contains hidden or 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
| using SenseHat | |
| import SenseHat: RGB565 | |
| function spooky(decay, arriv, refresh) | |
| x = rand() | |
| while true | |
| x *= exp(-decay*refresh) | |
| if rand() < arriv*refresh | |
| x += (1-x)*rand() | |
| end |
This file contains hidden or 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
| function lerp0(j, d, a, b) | |
| linspace(a,b,d+1)[j+1] | |
| end | |
| function lerp1(j, d, a, b) | |
| s = (d-j)/d; t = j/d | |
| a*s + b*t | |
| end | |
| function lerp2(j, d, a, b) | |
| (a*(d-j) + b*j)/d | |
| end |
This file contains hidden or 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
| using Unums | |
| import Base: promote_rule | |
| promote_rule{U<:Unums.Ubound}(::Type{U},::Type{Float64}) = U | |
| # Constants | |
| const solar_mass = 4 * pi * pi | |
| const days_per_year = 365.24 |