-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add a Rational Number type #164
Comments
Caveat: I didn’t check where this would be useful. Generally speaking, in my personal experience, it’s however easier to implement the rational number type by two regular integers. |
How do you understand the boundary between the signed integers? Advantage to store num and den as a single value? |
|
|
Is the rational type only for unsigned numbers or do we need a signed rational type too? |
Signed (which includes unsigned apart from very large values) |
If we really need such a field[1], I propose the following:
Restrictions:
Rationale:
[1] Not sure if we really need this data type given the smaple-accurate calculation method you specified the other day. |
I'd rather have We do need a way to specify the |
We always have the size field for the full element. There's really no need for three size fields as we can always calculate the third size from the other two. It would be a waste of space, a significant one if we used a rational element in something like a hypothetical I agree about default values. Leaving out |
OK my bad, I thought what you proposed was I agree with |
Great! |
I'm also agree with what @mbunkus proposed. Reason: [EBML-ID] [element size-field as VINT] [numerator: "normal" size-field as unsigend integer] [numerator value] [denominator value] |
Yes, given the limitation of the width of the numerator a regular unsigned 1-octet integer is easier for everyone. |
BTW we will probably need signed rational values. One way to encode the negative value (we should only allow one of the two values) could be to use the same encoding as the EBML-lacing in Matroska, see ietf-wg-cellar/matroska-specification#726 (comment) |
In my original proposal the denominator is a signed integer already. Not sure what you're missing there. Taking @hubblec4's suggestion into account, I revise my original proposal to:
Restrictions:
Rationale:
|
@mbunkus Out of curiosity: Is there a reason why you chose the denominator rather than the numerator? |
I actually explain my reasoning in the first bullet point of "Rationale". |
@mbunkus Indeed, I saw it. I was asking, because I’m not convinced. I actually did the contrary (back in the 1980s and 1990s) when I implemented a few compilers. My reasoning, back then (!), was about rounding errors and processor cycles. |
The rationals in media containers are somewhat unusual in that for most use cases their denominator remains constant. I don't know whether having one more bit to play with in the numerator actually makes any noticeable difference wrt. file sizes. On the other hand, I'm even less convinced that making the numerator signed instead of the denominator has any measurable difference wrt. to processing time, given that a) reading an unsigned integer requires fewer instructions & b) that this is a media format — any potential miniscule gains while parsing the container are dwarfed by the time required for decoding the content anyway. |
Still good to get IMO. The parser is in charge of rounding errors and actually could internally move the sign at the numerator if it wishes. |
That could be a reason, yes. Thank you! |
For me is that the best argument that the numerator should be an unsigned integer. And that's the reason why I want to speak about the third way for a signed rational number. Now we need only 1 bit to signal if a rational number is negative/signed or not.
The For example a rational number value: -"180/1" The word That was only some basis thoughts and I hope I'm not wasting your time. |
I did not check. I just added a reference to an existing (efficient) EBML-like encoding for signed values, so we don't forget about it. Looking at your proposal it seems easier to use than this (no need code needed for those not supporting EBML lacing in Matroska). |
Since some Matroska elements would be better as rational numbers we need a way to store them. I think a type would be better than using two
EBML Signed Integers
. The bits in the VDATA would be divided in half. The first part (signed) for the numerator, the second part (signed?) for the denominator.The text was updated successfully, but these errors were encountered: