Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

>,<,>=,<= via signed(::Posit) #72

Merged
merged 7 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -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
8 changes: 2 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 0 additions & 5 deletions src/SoftPosit.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module SoftPosit

# import SoftPosit_jll
milankl marked this conversation as resolved.
Show resolved Hide resolved
# # 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

Expand Down
4 changes: 2 additions & 2 deletions src/comparisons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Base.:(<)(x::T,y::T) where {T<:AbstractPosit} = signed(x) < signed(y)
Base.:(<=)(x::T,y::T) where {T<:AbstractPosit} = signed(x) <= signed(y)
40 changes: 35 additions & 5 deletions test/comparisons.jl
Original file line number Diff line number Diff line change
@@ -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