From 8516a022e6e502c2724fd918b28b8673ee78377c Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Fri, 8 Nov 2024 12:29:30 +0100 Subject: [PATCH] I hate this stupid fucking language --- l1/2.jl | 4 +--- l1/6.jl | 8 ++------ l1/7.jl | 12 +++--------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/l1/2.jl b/l1/2.jl index 2d7024b..657278f 100755 --- a/l1/2.jl +++ b/l1/2.jl @@ -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))") diff --git a/l1/6.jl b/l1/6.jl index 5868513..22d3069 100755 --- a/l1/6.jl +++ b/l1/6.jl @@ -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) diff --git a/l1/7.jl b/l1/7.jl index a6bcbfb..697de7b 100755 --- a/l1/7.jl +++ b/l1/7.jl @@ -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)