From 80396ee0bbbc14953cfb30a18dc4e00672f06848 Mon Sep 17 00:00:00 2001 From: Milan Date: Fri, 30 Sep 2022 16:32:44 +0100 Subject: [PATCH 1/7] >,<,<=, >= via signed(::PositN) --- src/SoftPosit.jl | 5 ----- src/comparisons.jl | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/SoftPosit.jl b/src/SoftPosit.jl index ad5ce68..fc0a4ae 100644 --- a/src/SoftPosit.jl +++ b/src/SoftPosit.jl @@ -1,10 +1,5 @@ module SoftPosit - # import SoftPosit_jll - # # For compatibility with previous versions of SofPosit.jl which used the name - # # `SoftPositPath`. - # const SoftPositPath = SoftPosit_jll.softposit - export AbstractPosit, Posit8, Posit16, Posit32, Posit16_1, notareal diff --git a/src/comparisons.jl b/src/comparisons.jl index 3a02033..26f954a 100644 --- a/src/comparisons.jl +++ b/src/comparisons.jl @@ -5,5 +5,5 @@ Base.isfinite(x::AbstractPosit) = ~isnan(x) # finite if not NaR Base.iszero(x::AbstractPosit) = x == zero(x) # COMPARISONS via two's complement (- of uints) -Base.:(<)(x::T,y::T) where {T<:AbstractPosit} = -unsigned(x) > -unsigned(y) -Base.:(<=)(x::T,y::T) where {T<:AbstractPosit} = -unsigned(x) >= -unsigned(y) \ No newline at end of file +Base.:(<)(x::T,y::T) where {T<:AbstractPosit} = signed(x) < signed(y) +Base.:(<=)(x::T,y::T) where {T<:AbstractPosit} = signed(x) <= signed(y) \ No newline at end of file From df298251adba36e061420932ddf3c1a848a66744 Mon Sep 17 00:00:00 2001 From: Milan Date: Fri, 30 Sep 2022 16:32:49 +0100 Subject: [PATCH 2/7] tests added --- test/comparisons.jl | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/test/comparisons.jl b/test/comparisons.jl index 4cc62a9..096a66e 100644 --- a/test/comparisons.jl +++ b/test/comparisons.jl @@ -1,10 +1,29 @@ @testset "Comparison" begin - f0,f1,f2,f3 = -0.9,-1.0,0.0,1.0 + n = 100 + fs = randn(n) + sort!(fs) @testset for T in (Posit8, Posit16, Posit16_1, Posit32) - @test (f0 > f1) == (T(f0) > T(f1)) - @test (f2 >= f2) == (T(f2) >= T(f2)) - @test (f3 < f1) == (T(f3) < T(f3)) - @test T(f0) === T(f0) + for i in 1:n-1 + f1 = T(fs[i]) + f2 = T(fs[i+1]) + + f1 == f2 || @test f2 > f1 # only test when not equal + @test f2 >= f1 + + f1 == f2 || @test f1 < f2 # only test when not equal + @test f1 <= f1 + end + end + + fs = 10*rand(n) + @testset for T in (Posit8, Posit16, Posit16_1, Posit32) + for f in fs + p = T(f) + @test p > 0 + @test p >= 0 + @test -p < 0 + @test -p <= 0 + end end end From cb5507f4a1e281ce44c9f7900dfe4c4159cf6542 Mon Sep 17 00:00:00 2001 From: Milan Date: Fri, 30 Sep 2022 17:05:04 +0100 Subject: [PATCH 3/7] SoftPosit_jll dep removed --- Project.toml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index c2947e8..b476640 100644 --- a/Project.toml +++ b/Project.toml @@ -1,13 +1,9 @@ name = "SoftPosit" uuid = "0775deef-a35f-56d7-82da-cfc52f91364d" -version = "0.5.0" - -[deps] -SoftPosit_jll = "f9aa12f2-fb2a-5e38-99be-91dba0a1f972" +version = "0.5.1" [compat] -SoftPosit_jll = "0.4.1, 0.4.2" -julia = "1.6, 1.7" +julia = "1.6" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From cdf0ca95ecfb7afa87248285a78d8931bb037929 Mon Sep 17 00:00:00 2001 From: Milan Date: Fri, 30 Sep 2022 17:05:31 +0100 Subject: [PATCH 4/7] maxpos minpos added and exported --- src/SoftPosit.jl | 2 +- src/comparisons.jl | 2 +- src/constants.jl | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/SoftPosit.jl b/src/SoftPosit.jl index fc0a4ae..e9df179 100644 --- a/src/SoftPosit.jl +++ b/src/SoftPosit.jl @@ -1,7 +1,7 @@ module SoftPosit export AbstractPosit, Posit8, Posit16, Posit32, Posit16_1, - notareal + notareal,maxpos,minpos,minusone include("type_definitions.jl") include("comparisons.jl") diff --git a/src/comparisons.jl b/src/comparisons.jl index 26f954a..97efcfa 100644 --- a/src/comparisons.jl +++ b/src/comparisons.jl @@ -6,4 +6,4 @@ Base.iszero(x::AbstractPosit) = x == zero(x) # COMPARISONS via two's complement (- of uints) Base.:(<)(x::T,y::T) where {T<:AbstractPosit} = signed(x) < signed(y) -Base.:(<=)(x::T,y::T) where {T<:AbstractPosit} = signed(x) <= signed(y) \ No newline at end of file +Base.:(<=)(x::T,y::T) where {T<:AbstractPosit} = signed(x) <= signed(y) diff --git a/src/constants.jl b/src/constants.jl index 9275ebf..e38e8d7 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -8,6 +8,8 @@ Base.exponent_bits(::Type{Posit8}) = 2 Base.exponent_mask(::Type{Posit8}) = 0x03 Base.sign_mask(::Type{Posit8}) = 0x80 bitsize(::Type{Posit8}) = 8 +maxpos(::Type{Posit8}) = reinterpret(Posit8,0x7f) +minpos(::Type{Posit8}) = reinterpret(Posit8,0x01) # 16bit Posits, 1 or 2 exponent bits Base.one(::Type{T}) where {T<:PositAll16} = reinterpret(T,0x4000) @@ -21,6 +23,8 @@ Base.exponent_mask(::Type{Posit16}) = 0x0003 Base.exponent_mask(::Type{Posit16_1}) = 0x0001 Base.sign_mask(::Type{T}) where {T<:PositAll16} = 0x8000 bitsize(::Type{T}) where {T<:PositAll16} = 16 +maxpos(::Type{T}) where {T<:PositAll16} = reinterpret(T,0x7fff) +minpos(::Type{T}) where {T<:PositAll16} = reinterpret(T,0x0001) # 32bit Posits Base.one(::Type{Posit32}) = reinterpret(Posit32,0x4000_0000) @@ -32,6 +36,8 @@ Base.exponent_bits(::Type{Posit32}) = 2 Base.exponent_mask(::Type{Posit32}) = 0x0000_0003 Base.sign_mask(::Type{Posit32}) = 0x8000_0000 bitsize(::Type{Posit32}) = 32 +maxpos(::Type{Posit32}) = reinterpret(Posit32,0x7fff_ffff) +minpos(::Type{Posit32}) = reinterpret(Posit32,0x0000_0001) # define Not-a-Real (NaR) / complex infinity notareal(::Type{Posit8}) = reinterpret(Posit8,0x80) From c8aa7f0934d91b9a7750eb649e753e36912cb30c Mon Sep 17 00:00:00 2001 From: Milan Date: Fri, 30 Sep 2022 17:05:40 +0100 Subject: [PATCH 5/7] tests with NaR added --- test/comparisons.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/comparisons.jl b/test/comparisons.jl index 096a66e..4c37420 100644 --- a/test/comparisons.jl +++ b/test/comparisons.jl @@ -26,4 +26,15 @@ @test -p <= 0 end end + + # NaR is the smaller than -maxpos for comparisons + @testset for T in (Posit8, Posit16, Posit16_1, Posit32) + @test maxpos(T) > notareal(T) + @test one(T) > notareal(T) + @test minpos(T) > notareal(T) + @test zero(T) > notareal(T) + @test -minpos(T) > notareal(T) + @test minusone(T) > notareal(T) + @test -maxpos(T) > notareal(T) + end end From a08b921a63d24a566b5f839dc159437da750e5c8 Mon Sep 17 00:00:00 2001 From: Milan Date: Fri, 30 Sep 2022 17:06:44 +0100 Subject: [PATCH 6/7] gitignore Manifest.toml --- .gitignore | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 24f75e1..e6e3cdd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,26 @@ -/deps/* +.DS_Store + +# Files generated by invoking Julia with --code-coverage +*.jl.cov +*.jl.*.cov + +# Files generated by invoking Julia with --track-allocation +*.jl.mem + +# System-specific files and directories generated by the BinaryProvider and BinDeps packages +# They contain absolute paths specific to the host computer, and so should not be committed +deps/deps.jl +deps/build.log +deps/downloads/ +deps/usr/ +deps/src/ + +# Build artifacts for creating documentation generated by the Documenter package +docs/build/ +docs/site/ + +# File generated by Pkg, the package manager, based on a corresponding Project.toml +# It records a fixed state of all packages used by the project. As such, it should not be +# committed for packages, but should be committed for applications that require a static +# environment. +Manifest.toml \ No newline at end of file From 87e38860fa7f73f57ccfd26fa80de2401f409650 Mon Sep 17 00:00:00 2001 From: Milan Date: Fri, 30 Sep 2022 17:13:37 +0100 Subject: [PATCH 7/7] use floatmin, floatmax instead of maxpos, minpos --- src/SoftPosit.jl | 2 +- src/constants.jl | 6 ------ test/comparisons.jl | 10 +++++----- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/SoftPosit.jl b/src/SoftPosit.jl index e9df179..fc0a4ae 100644 --- a/src/SoftPosit.jl +++ b/src/SoftPosit.jl @@ -1,7 +1,7 @@ module SoftPosit export AbstractPosit, Posit8, Posit16, Posit32, Posit16_1, - notareal,maxpos,minpos,minusone + notareal include("type_definitions.jl") include("comparisons.jl") diff --git a/src/constants.jl b/src/constants.jl index e38e8d7..9275ebf 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -8,8 +8,6 @@ Base.exponent_bits(::Type{Posit8}) = 2 Base.exponent_mask(::Type{Posit8}) = 0x03 Base.sign_mask(::Type{Posit8}) = 0x80 bitsize(::Type{Posit8}) = 8 -maxpos(::Type{Posit8}) = reinterpret(Posit8,0x7f) -minpos(::Type{Posit8}) = reinterpret(Posit8,0x01) # 16bit Posits, 1 or 2 exponent bits Base.one(::Type{T}) where {T<:PositAll16} = reinterpret(T,0x4000) @@ -23,8 +21,6 @@ Base.exponent_mask(::Type{Posit16}) = 0x0003 Base.exponent_mask(::Type{Posit16_1}) = 0x0001 Base.sign_mask(::Type{T}) where {T<:PositAll16} = 0x8000 bitsize(::Type{T}) where {T<:PositAll16} = 16 -maxpos(::Type{T}) where {T<:PositAll16} = reinterpret(T,0x7fff) -minpos(::Type{T}) where {T<:PositAll16} = reinterpret(T,0x0001) # 32bit Posits Base.one(::Type{Posit32}) = reinterpret(Posit32,0x4000_0000) @@ -36,8 +32,6 @@ Base.exponent_bits(::Type{Posit32}) = 2 Base.exponent_mask(::Type{Posit32}) = 0x0000_0003 Base.sign_mask(::Type{Posit32}) = 0x8000_0000 bitsize(::Type{Posit32}) = 32 -maxpos(::Type{Posit32}) = reinterpret(Posit32,0x7fff_ffff) -minpos(::Type{Posit32}) = reinterpret(Posit32,0x0000_0001) # define Not-a-Real (NaR) / complex infinity notareal(::Type{Posit8}) = reinterpret(Posit8,0x80) diff --git a/test/comparisons.jl b/test/comparisons.jl index 4c37420..a20521a 100644 --- a/test/comparisons.jl +++ b/test/comparisons.jl @@ -29,12 +29,12 @@ # NaR is the smaller than -maxpos for comparisons @testset for T in (Posit8, Posit16, Posit16_1, Posit32) - @test maxpos(T) > notareal(T) + @test floatmax(T) > notareal(T) @test one(T) > notareal(T) - @test minpos(T) > notareal(T) + @test floatmin(T) > notareal(T) @test zero(T) > notareal(T) - @test -minpos(T) > notareal(T) - @test minusone(T) > notareal(T) - @test -maxpos(T) > notareal(T) + @test -floatmin(T) > notareal(T) + @test -one(T) > notareal(T) + @test -floatmax(T) > notareal(T) end end