[FFmpeg-devel] [PATCH 10/10] Document how av_cmp_q() deal when one of the values to be compared is 0/0.

Stefano Sabatini stefano.sabatini-lala
Sun Oct 3 23:07:22 CEST 2010


On date Saturday 2010-10-02 21:56:49 +0200, Michael Niedermayer encoded:
> On Fri, Oct 01, 2010 at 09:16:55AM +0200, Tomas H?rdin wrote:
> > On Thu, 2010-09-30 at 23:58 +0200, Michael Niedermayer wrote:
> > > On Thu, Sep 30, 2010 at 09:45:41PM +0200, Stefano Sabatini wrote:
> > > > ---
> > > >  libavutil/rational.h |    4 ++++
> > > >  1 files changed, 4 insertions(+), 0 deletions(-)
> > > > 
> > > > diff --git a/libavutil/rational.h b/libavutil/rational.h
> > > > index 2dd0c2c..bd2e711 100644
> > > > --- a/libavutil/rational.h
> > > > +++ b/libavutil/rational.h
> > > > @@ -41,6 +41,10 @@ typedef struct AVRational{
> > > >  
> > > >  /**
> > > >   * Compare two rationals.
> > > > + * If one of the compared values is 0/0, the result of the comparison
> > > > + * is always 0, so you should do an explicit check for that case
> > > > + * rather than use this function.
> > > 
> > > is there any return value that would in any case avoid an additional check?
> > 
> > Perhaps AVERROR_INVALIDDATA?
> 
> I think that if we do detect NAN then the most sensible value to return would
> be INT_MIN because INT_MIN == -INT_MIN thus in some sense it is the best
> non zero element that has both + and -

Check attached patch. I have a slightly preference for the first patch
I sent, as I like the idea of having a special value which results
equal to all other rationals (0/0), also I fear that people may do
something of the kind:
if (av_cmp_q(...) < 0)

in which case returning -INT_MIN with 0/0 will fail. On the other hand
I have no strong objection, so if Michael prefer this form I won't
object.

Regards.
-- 
FFmpeg = Freak Fabulous Mean Prodigious Eretic Gigant



More information about the ffmpeg-devel mailing list