1 | use libc::{c_double, c_int}; |
2 | use AVRational; |
3 | |
4 | #[inline (always)] |
5 | pub unsafe fn av_make_q(num: c_int, den: c_int) -> AVRational { |
6 | AVRational { num, den } |
7 | } |
8 | |
9 | #[inline (always)] |
10 | pub unsafe fn av_cmp_q(a: AVRational, b: AVRational) -> c_int { |
11 | let tmp: i64 = i64::from(a.num) * i64::from(b.den) - i64::from(b.num) * i64::from(a.den); |
12 | |
13 | if tmp != 0 { |
14 | (((tmp ^ i64::from(a.den) ^ i64::from(b.den)) >> 63) | 1) as c_int |
15 | } else if b.den != 0 && a.den != 0 { |
16 | 0 |
17 | } else if a.num != 0 && b.num != 0 { |
18 | ((i64::from(a.num) >> 31) - (i64::from(b.num) >> 31)) as c_int |
19 | } else { |
20 | c_int::min_value() |
21 | } |
22 | } |
23 | |
24 | #[inline (always)] |
25 | pub unsafe fn av_q2d(a: AVRational) -> c_double { |
26 | f64::from(a.num) / f64::from(a.den) |
27 | } |
28 | |
29 | #[inline (always)] |
30 | pub unsafe fn av_inv_q(q: AVRational) -> AVRational { |
31 | AVRational { |
32 | num: q.den, |
33 | den: q.num, |
34 | } |
35 | } |
36 | |