Comparison
Closed this issue · 7 comments
pevnak commented
Is this a correct behavior?
julia> Posit8(1.f0) > 0
false
julia> Posit8(1.f0) < 0
true
milankl commented
Haha, no, of course not. I've just created pr #72 which should address these and add more meaningful tests for comparisons. Now we use
Base.:(<)(x::T,y::T) where {T<:AbstractPosit} = signed(x) < signed(y)
which works between -maxpos and maxpos simply by reinterpreting the posit bits as signed integer. 0b1111_1111
is -1 in Int8, so we essentially map posits as if we numerated them, starting at 0 and positive 1,2,3,4,... for positive posits and negative -1,-2,-3,... for negative posits.
milankl commented
How's comparison with NaR defined for posit arithmetic?
milankl commented
Quick check
julia> Posit8(0x81)
Posit8(-1.6777216e7)
julia> Posit8(0x81) > notareal(Posit8)
true
julia> Posit8(-1f0) > notareal(Posit8)
true
julia> Posit8(0f0) > notareal(Posit8)
true
julia> Posit8(1f0) > notareal(Posit8)
true
julia> Posit8(0x7f)
Posit8(1.6777216e7)
julia> Posit8(0x7f) > notareal(Posit8)
true
looks good 👍🏼
pevnak commented
Great. I have discovered it during teaching. It was a bit hiccup.
milankl commented
Ha, sorry for that, but I hope an example how the open source hivemind works.