meh / rust-ffmpeg-sys

moved to meh/rust-ffmpeg
145 stars 87 forks source link

Fix incorrect static inline function #91

Closed ldm0 closed 4 years ago

ldm0 commented 4 years ago
/**
 * Compare two rationals.
 *
 * @param a First rational
 * @param b Second rational
 *
 * @return One of the following values:
 *         - 0 if `a == b`
 *         - 1 if `a > b`
 *         - -1 if `a < b`
 *         - `INT_MIN` if one of the values is of the form `0 / 0`
 */
static inline int av_cmp_q(AVRational a, AVRational b){
    const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;

    if(tmp) return (int)((tmp ^ a.den ^ b.den)>>63)|1;
    else if(b.den && a.den) return 0;
    else if(a.num && b.num) return (a.num>>31) - (b.num>>31);
    else                    return INT_MIN;
}
kornelski commented 4 years ago

How is it incorrect? The current implementation seems to stimulate C implicit type conversion, which Rust won't do itself.

ldm0 commented 4 years ago

How is it incorrect? The current implementation seems to stimulate C implicit type conversion, which Rust won't do itself.

There is no need to do type conversion here I guess?

kornelski commented 4 years ago

I guess so