obliczenia_naukowe/l1/4.jl

38 lines
845 B
Julia
Raw Normal View History

2024-10-27 21:56:24 +01:00
#!/usr/bin/env julia
# Jacek Poziemski 272389
"""
2024-11-08 10:54:40 +01:00
findsmallest(start::Float64, finish::Float64)::Float64
2024-10-27 21:56:24 +01:00
Find the smallest Float64 larger than `start`
and smaller than `finish` that satisfies the
following inequality `x * (1/x) ≠ 1`.
# Arguments
- `start::Float64`: bottom limit for the wanted number
- `finish::Float64`: upper limit for the wanted number
"""
2024-11-08 10:54:40 +01:00
function findsmallest(start::Float64, finish::Float64)::Float64
x::Float64 = nextfloat(Float64(start))
res::Float64 = zero(Float64)
2024-10-27 21:56:24 +01:00
while x < Float64(finish)
res = x * (one(Float64) / x)
if res != one(Float64)
return x
end
x = nextfloat(x)
end
return missing
end
2024-11-08 10:54:40 +01:00
smallest::Float64 = findsmallest(1.0, 2.0)
2024-10-27 21:56:24 +01:00
if ismissing(smallest)
println("smallest not found")
else
println("smallest: $smallest")
end