Open kimikage opened 4 years ago
During the discussion https://discourse.julialang.org/t/rfc-what-should-the-arithmetic-within-the-fixedpointnumbers-be/46697, some cases were mentioned where fixed-point types with bit widths that were not 8, 16 or 32 were used.
It's hard to support those types right now, but they imply that the way to distinguish between signed/unsigned according to the number of bits (i.e. x+y == 8sizeof(T)
/1+x+y == 8sizeof(T)
) is a bad idea.
Therefore, I am beginning to think that using two letters (i.e. UQxfy
/SNxfy
) is a better option.
Therefore, I am beginning to think that using two letters (i.e.
UQxfy
/SNxfy
) is a better option.
Personally, I think it declaring S and/or U is a good direction (instead of only implying it with the sum of x and y being 1 bit smaller than the intended width).
We use S in the comments of embedded c code to document signed. [S3, 4] [1, 15] [S31, 0]
WRT scaling fixed point numbers: some people interpret y as a binary/radix point, instead of strictly the number of fractional bits. The value of the binary point having a wider range. It can be negative or larger than the number of bits in the underlying type. This gives more scaling flexibility to the underlying bits being used.
BTW, Thanks for working on fixed point number support for Julia!
As noted in #199, unsigned
Fixed
and signedNormed
are mathematically definable, but we still have some preparations to implement them.Although those types are certainly not used often, but in fact, I occasionally use unsigned
Fixed
in private projects. In that case, I give those types redundant names.However, when we handle concrete
Fixed
/Normed
numbers, we often use the aliases (e.g.,Q0f7
,N0f8
). If we have the predetermined aliases for unsignedFixed
and signedNormed
, they can be used to make the future migration easier.See also #51
Candidates
unsigned
Fixed
UQxfy
(Unsigned Q)Qxfy
(x+y == 8sizeof(T)
)Uxfy
(Unsigned)Rxfy
(followingQ
)Fxfy
(Fixed)Xxfy
(fiXed)signed
Normed
SNxfy
(Signed N)Nxfy
(1+x+y == 8sizeof(T)
)Sxfy
(Signed. cf. #143)Mxfy
(norMed. followed byN
)Renaming
Nxfy
toUNxfy
is a consistent practice, but it defeats the purpose of making the migration easier.