-
-
Notifications
You must be signed in to change notification settings - Fork 346
Change AFix division #1722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Change AFix division #1722
Conversation
Also, there's not an obvious answer to what the semantics of AFix division should be. I think it's clear that the |
Right ^^
I agree. |
Such as in I haven't looked at any good examples of how this has been done elsewhere, and I don't have a good answer to how it should be done, but here are some of my thoughts on what might be a good default behavior of the Quotient Representable RangeSince we know the representable range of the dividend and the smallest nonzero value of the divisor, there's an obvious candidate for the representable range of the quotient. Division can produce some very large numbers over a very small part of its domain, unlike other operators. However, in most real-world uses of fixed-point division, the divisor probably never approaches zero too closely (i.e. no singularities). So, a careful user could use the There are certainly some applications where we don't want that entire range, but one could make the same argument about Quotient PrecisionObviously some sort of compromise has to be made since divisions can produce arbitrarily precise nonzero bits. In this PR, the number of bits of the quotient is the same as that of the dividend. A user who wants more precision can pad the dividend out (e.g. The conventional rules of significant figures, where the number of digits of a quotient is the minimum of the number of digits in the two operands, don't seem appropriate here, since one could imagine a division by a small integer, for example, where the result should still have many digits. (Of course, one could add trailing zeros to the integer to indicate that it is precisely an integer, but that seems unnecessary.) Some ideas that seem reasonable:
I'd love to hear others' thoughts on those possibilities. |
Yes
Right, i think the API should have started from that end instead of having a "/" operator.
Right, that make it very special. And make me think that there is no good compromise, excepted explicitly asking the user which range he want the result in. Just providing a "/" operator is too "handwavy".
Hmm, those could be additional function / operator, which internaly use the explicit division function (the one with with explicit range) So overall, no "/" operator, but instead one very explicit division function, and posibly other precooked alternative division function (which use the explicit division internaly) |
Context, Motivation & Description
The
AFix
/
operator appears to have not been changed since the original implementation ofAFix
, and I'm skeptical that it was ever used -- its range and exponent on the result didn't really make sense.. It includes a warning against its use. I have changed it to be suited to the use I need it for, but left the warning in place.I don't have time to write a unit test right now, but it might be in a followup PR if I can find the time. The best I can say about it is: it works in simulation as part of a codebase that I unfortunately cannot share.
Checklist