I hate this stupid fucking language
This commit is contained in:
parent
7a407fcfe4
commit
8516a022e6
3 changed files with 6 additions and 18 deletions
4
l1/2.jl
4
l1/2.jl
|
@ -11,9 +11,7 @@ using the following expression: `3(4/3 - 1) - 1`.
|
||||||
# Arguments
|
# Arguments
|
||||||
- `T`: the floating point type
|
- `T`: the floating point type
|
||||||
"""
|
"""
|
||||||
function kahanmacheps(T::Type{<: AbstractFloat})::T
|
kahanmacheps(T::Type{<: AbstractFloat})::T = T(3) * ((T(4) / T(3)) - one(T)) - one(T)
|
||||||
return T(3) * ((T(4) / T(3)) - one(T)) - one(T)
|
|
||||||
end
|
|
||||||
|
|
||||||
for T::Type{<: AbstractFloat} in [Float16, Float32, Float64]
|
for T::Type{<: AbstractFloat} in [Float16, Float32, Float64]
|
||||||
println("kahanmacheps($T): $(kahanmacheps(T))")
|
println("kahanmacheps($T): $(kahanmacheps(T))")
|
||||||
|
|
8
l1/6.jl
8
l1/6.jl
|
@ -10,9 +10,7 @@ Calculate `sqrt(x^2 + 1) - 1`.
|
||||||
# Arguments
|
# Arguments
|
||||||
- `x::Float64`: function argument
|
- `x::Float64`: function argument
|
||||||
"""
|
"""
|
||||||
function f(x::Float64)::Float64
|
f(x::Float64)::Float64 = sqrt(x^2 + one(Float64)) - one(Float64)
|
||||||
return sqrt(x^2 + one(Float64)) - one(Float64)
|
|
||||||
end
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
g(x::Float64)::Float64
|
g(x::Float64)::Float64
|
||||||
|
@ -22,9 +20,7 @@ Calculate `x^2 / (sqrt(x^2 + 1) + 1)`.
|
||||||
# Arguments
|
# Arguments
|
||||||
- `x::Float64`: function argument
|
- `x::Float64`: function argument
|
||||||
"""
|
"""
|
||||||
function g(x::Float64)::Float64
|
g(x::Float64)::Float64 = x^2 / (sqrt(x^2 + one(Float64)) + one(Float64))
|
||||||
return x^2 / (sqrt(x^2 + one(Float64)) + one(Float64))
|
|
||||||
end
|
|
||||||
|
|
||||||
for i::Int in 1:20
|
for i::Int in 1:20
|
||||||
x::Float64 = 8.0^(-i)
|
x::Float64 = 8.0^(-i)
|
||||||
|
|
12
l1/7.jl
12
l1/7.jl
|
@ -10,9 +10,7 @@ Calculate `sin(x) + cos(3x)`.
|
||||||
# Arguments
|
# Arguments
|
||||||
- `x::Float64`: function argument
|
- `x::Float64`: function argument
|
||||||
"""
|
"""
|
||||||
function f(x::Float64)::Float64
|
f(x::Float64)::Float64 = sin(x) + cos(Float64(3) * x)
|
||||||
return sin(x) + cos(Float64(3) * x)
|
|
||||||
end
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
fderivative(x::Float64)::Float64
|
fderivative(x::Float64)::Float64
|
||||||
|
@ -22,9 +20,7 @@ Calculate the derivative of `sin(x) + cos(3x)`, `cos(x) - 3sin(3x)`.
|
||||||
# Arguments
|
# Arguments
|
||||||
- `x::Float64`: function argument
|
- `x::Float64`: function argument
|
||||||
"""
|
"""
|
||||||
function fderivative(x::Float64)::Float64
|
fderivative(x::Float64)::Float64 = cos(x) - Float64(3) * sin(Float64(3) * x)
|
||||||
return cos(x) - Float64(3) * sin(Float64(3) * x)
|
|
||||||
end
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
derivative(f::Function, x0::Float64, h::Float64)::Float64
|
derivative(f::Function, x0::Float64, h::Float64)::Float64
|
||||||
|
@ -37,9 +33,7 @@ using `h` in the following formula: `(f(x0 + h) - f(x0)) / h`.
|
||||||
- `x0::Float64`: function argument
|
- `x0::Float64`: function argument
|
||||||
- `h::Float64`: value used in the approximation formula
|
- `h::Float64`: value used in the approximation formula
|
||||||
"""
|
"""
|
||||||
function derivative(f::Function, x0::Float64, h::Float64)::Float64
|
derivative(f::Function, x0::Float64, h::Float64)::Float64 = (f(x0 + h) - f(x0)) / h
|
||||||
return (f(x0 + h) - f(x0)) / h
|
|
||||||
end
|
|
||||||
|
|
||||||
x::Float64 = one(Float64)
|
x::Float64 = one(Float64)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue