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 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" 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..97efcfa 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) diff --git a/test/comparisons.jl b/test/comparisons.jl index 4cc62a9..a20521a 100644 --- a/test/comparisons.jl +++ b/test/comparisons.jl @@ -1,10 +1,40 @@ @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 + + # NaR is the smaller than -maxpos for comparisons + @testset for T in (Posit8, Posit16, Posit16_1, Posit32) + @test floatmax(T) > notareal(T) + @test one(T) > notareal(T) + @test floatmin(T) > notareal(T) + @test zero(T) > notareal(T) + @test -floatmin(T) > notareal(T) + @test -one(T) > notareal(T) + @test -floatmax(T) > notareal(T) end end