obliczenia_naukowe/l1/2.jl

22 lines
487 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
kahanmacheps(T::Type{<: AbstractFloat})::T
2024-10-27 21:56:24 +01:00
Calculate the Kahan machine epsilon
using the following expression: `3(4/3 - 1) - 1`.
# Arguments
2024-11-08 10:23:19 +01:00
- `T`: the floating point type
2024-10-27 21:56:24 +01:00
"""
2024-11-08 12:29:30 +01:00
kahanmacheps(T::Type{<: AbstractFloat})::T = T(3) * ((T(4) / T(3)) - one(T)) - one(T)
2024-10-27 21:56:24 +01:00
2024-11-08 10:54:40 +01:00
for T::Type{<: AbstractFloat} in [Float16, Float32, Float64]
2024-10-27 21:56:24 +01:00
println("kahanmacheps($T): $(kahanmacheps(T))")
println("eps($T): $(eps(T))")
println()
end