Add conversion operators for converting between SFixed and UFixed #93
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This will finally allow SFixed and UFixed to be converted to and from each other.
As simple as this implementation seems, it took quite a bit of thought to come up with it.
Early on I realised that I could implement the function by leveraging the 'scaling' cast operator to perform the scaling and then having a '1-to-1' operator that simply converts the internal representation of the same width by effectively leveraging the built-in integer cast operators, but the real problem was figuring out how to have those two cases coexist. Originally I went down the wrong track by trying to create a specialisation, and at one point I was considering using a template class and some specialisation, but then I suddenly realised that I could introduce a non-template cast operator to do the job of the non-scaling/direct operation and suddenly the rest just slotted into place.
It took me quite some time to actually commit this because I wanted to double check that I'd got the order of operations correct. As it happens, I had got it right first time, so I ended up wasting a lot of time creating the code to check when I could have committed it straight away, but at least I know for definite.
All in all I'm glad I put this particular issue off for a few years because my original attempt from 2018 was absolutely awful (I think perhaps I was following some bad advice I got from StackOverflow) and I feel that I've been able to pull off something much better than my original intended implementation.
Resolves #20