I hate this stupid fucking language

This commit is contained in:
jacekpoz 2024-11-08 12:29:30 +01:00
parent 7a407fcfe4
commit 8516a022e6
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
3 changed files with 6 additions and 18 deletions

View file

@ -11,9 +11,7 @@ using the following expression: `3(4/3 - 1) - 1`.
# Arguments
- `T`: the floating point type
"""
function kahanmacheps(T::Type{<: AbstractFloat})::T
return T(3) * ((T(4) / T(3)) - one(T)) - one(T)
end
kahanmacheps(T::Type{<: AbstractFloat})::T = T(3) * ((T(4) / T(3)) - one(T)) - one(T)
for T::Type{<: AbstractFloat} in [Float16, Float32, Float64]
println("kahanmacheps($T): $(kahanmacheps(T))")

View file

@ -10,9 +10,7 @@ Calculate `sqrt(x^2 + 1) - 1`.
# Arguments
- `x::Float64`: function argument
"""
function f(x::Float64)::Float64
return sqrt(x^2 + one(Float64)) - one(Float64)
end
f(x::Float64)::Float64 = sqrt(x^2 + one(Float64)) - one(Float64)
"""
g(x::Float64)::Float64
@ -22,9 +20,7 @@ Calculate `x^2 / (sqrt(x^2 + 1) + 1)`.
# Arguments
- `x::Float64`: function argument
"""
function g(x::Float64)::Float64
return x^2 / (sqrt(x^2 + one(Float64)) + one(Float64))
end
g(x::Float64)::Float64 = x^2 / (sqrt(x^2 + one(Float64)) + one(Float64))
for i::Int in 1:20
x::Float64 = 8.0^(-i)

12
l1/7.jl
View file

@ -10,9 +10,7 @@ Calculate `sin(x) + cos(3x)`.
# Arguments
- `x::Float64`: function argument
"""
function f(x::Float64)::Float64
return sin(x) + cos(Float64(3) * x)
end
f(x::Float64)::Float64 = sin(x) + cos(Float64(3) * x)
"""
fderivative(x::Float64)::Float64
@ -22,9 +20,7 @@ Calculate the derivative of `sin(x) + cos(3x)`, `cos(x) - 3sin(3x)`.
# Arguments
- `x::Float64`: function argument
"""
function fderivative(x::Float64)::Float64
return cos(x) - Float64(3) * sin(Float64(3) * x)
end
fderivative(x::Float64)::Float64 = cos(x) - Float64(3) * sin(Float64(3) * x)
"""
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
- `h::Float64`: value used in the approximation formula
"""
function derivative(f::Function, x0::Float64, h::Float64)::Float64
return (f(x0 + h) - f(x0)) / h
end
derivative(f::Function, x0::Float64, h::Float64)::Float64 = (f(x0 + h) - f(x0)) / h
x::Float64 = one(Float64)