exp, log, sin, cos, tan support
milankl opened this issue ยท 5 comments
Although the SoftPosit C-library does not have trigonometric functions implemented yet, we should consider a back and forth conversion as an intermediate work-around
sin(x::Posit16) = Posit16(sin(Float64(x)))
etc. Converting to Float32 should in theory work too as the dynamic range is slightly wider than for Posit32.
That's cheating ๐
I did it anyway. It turns out that correct rounding is actually super difficult with sin, cos etc.
julia> sin(ฯ)
1.2246467991473532e-16
julia> Posit8(sin(ฯ))
Posit8(0x01)
julia> Posit32(sin(ฯ))
Posit32(0x0001c699)
julia> sin(Posit8(1ฯ))
Posit8(0x01)
julia> sin(Posit32(1ฯ))
Posit32(0x00710b46)
which is not the fault of Posits (they actually want to to implement error-free rounding in the posit standard) but due to the underlying errors with floats ... Well, one has to keep that in mind.
I kept it simple and only defined exp,exp2,exp10,log2,log10,sin,cos,tan - anything else?
I think they should be fine to start with
Oh, there are expm1
and log1p
that are often used, too