#!/usr/bin/env julia # Jacek Poziemski 272389 """ macheps(T::Type{<: AbstractFloat})::T Calculate the machine epsilon iteratively for the given IEEE 754 floating point type. # Arguments - `T`: the floating point type """ function macheps(T::Type{<: AbstractFloat})::T one_T::T = one(T) ret::T = one_T while one_T + (ret / T(2)) > one_T ret /= T(2) end return ret end """ eta(T::Type{<: AbstractFloat})::T Calculate the eta number iteratively for the given IEEE 754 floating point type. # Arguments - `T`: the floating point type """ function eta(T::Type{<: AbstractFloat})::T ret::T = one(T) while ret / T(2) > zero(T) ret /= T(2) end return ret end """ max(T::Type{<: AbstractFloat})::T Calculate the largest possible value for the given IEEE 754 floating type. # Arguments - `T`: the floating point type """ function max(T::Type{<: AbstractFloat})::T ret::T = one(T) while isfinite(ret * T(2)) ret *= T(2) end x::T = ret / T(2) while isfinite(ret + x) ret += x x /= T(2) end return ret end for T::Type{<: AbstractFloat} in [Float16, Float32, Float64] println("me - macheps($T): $(macheps(T))") println("julia - eps($T): $(eps(T))") println() println("me - eta($T): $(eta(T))") println("julia - nextfloat($T(0.0)): $(nextfloat(T(0.0)))") println() println("me - max($T): $(max(T))") println("julia - floatmax($T): $(floatmax(T))") println() println("julia - floatmin($T): $(floatmin(T))") println() end