Minkowski question-mark function: Difference between revisions

m (syntax highlighting fixup automation)
Line 518:
 
=={{header|Julia}}==
 
{{trans|FreeBASIC}}
<syntaxhighlight lang="julia">function minkowskiquestionmark(x)
y, p = Int(floorfldmod(x), 1)
(xq, >d = 1 || x < 0) && return- p, + minkowski(x).5
q,while r, s, m, n = 1, py + 1, 1,d 0,> 0y
d, y = 1.0, Float64(if p) < q
while true q -= p
d /= 2.0
y + d == y && break
m = p + r
(m < 0 || p < 0) && break
n = q + s
n < 0 && break
if x < (m / n)
r, s = m, n
else
y, p, q -= y + d, m, nq
y + d == y &&+= breakd
end
d /= 2.0
end
return y + d
end
 
function minkowski_invquestionmark_inv(x, maxiter=151)
py, bits = Int(floorfldmod(x), 1)
currlo, coun, ihi = [0, 1], 0[1, 1]
(x > 1 || x < 0) && return p + minkowski_inv(x - p, maxiter)
while (xy ==+ 1 || x/(lo...)) =!= 0)(y &&+ return x/(hi...))
bit, bits = fldmod(2*bits, 1)
contfrac = [0]
bit > 0 ? (lo .+= hi) : i(hi .+= 1lo)
curr, coun, i = 0, 1, 0
while i < maxiter
x *= 2
if curr == 0
if x < 1
coun += 1
else
i += 1
push!(contfrac, 0)
contfrac[i] = coun
coun = 1
curr = 1
x -= 1
end
else
if x > 1
coun += 1
x -= 1
else
i += 1
push!(contfrac, 0)
contfrac[i] = coun
coun = 1
curr = 0
end
end
if x == Int(floor(x))
contfrac[i + 1] = coun
break
end
end
rety = 1.0+ /((lo contfrac[i .+ 1]hi)...)
for j in i:-1:1
ret = contfrac[j] + 1.0 / ret
end
return 1.0 / ret
end
 
x, y = 0.718281828, 0.1213141516171819
println(" ", minkowski((1 + sqrt(5)) / 2), " ", 5 / 3)
for (a, b) ∈ [
println(minkowski_inv(-5/9), " ", (sqrt(13) - 7) / 6)
(5/3, questionmark((1 + √5)/2)),
println(" ", minkowski(minkowski_inv(0.718281828)), " ",
((√13-7)/6, questionmark_inv(-5/9)),
minkowski_inv(minkowski(0.1213141516171819)))
(x, questionmark_inv(questionmark(x))),
(y, questionmark(questionmark_inv(y)))]
println(a, a ≈ b ? " ≈ " : " != ", b)
end
</syntaxhighlight>{{out}}
<pre>
1.6666666666666667 ≈ 1.666666666667894
1.6666666666696983 1.6666666666666667
-0.5657414540893352 ≈ -0.5657414540893351
-0.5657414540893351 -0.5657414540893352
0.718281828 ≈ 0.7182818279999971
0.7182818280000092 0.12131415161718191
0.1213141516171819 ≈ 0.12131415161718095
</pre>
 
39

edits