Closed milankl closed 5 years ago
That's cheating :stuck_out_tongue:
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
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
etc. Converting to Float32 should in theory work too as the dynamic range is slightly wider than for Posit32.