milankl/SoftPosit.jl

Comparison

Closed this issue · 7 comments

Is this a correct behavior?

julia> Posit8(1.f0) > 0
false

julia> Posit8(1.f0) < 0
true

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.

How's comparison with NaR defined for posit arithmetic?

image

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 👍🏼

The fix from #72 should be released soon as v0.5.1

@pevnak thanks for spotting this.

Great. I have discovered it during teaching. It was a bit hiccup.

Ha, sorry for that, but I hope an example how the open source hivemind works.