Diffstat (limited to 'core/multimedia/opieplayer/libmad/fixed.c') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/fixed.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/core/multimedia/opieplayer/libmad/fixed.c b/core/multimedia/opieplayer/libmad/fixed.c index af1e87e..e71418a 100644 --- a/core/multimedia/opieplayer/libmad/fixed.c +++ b/core/multimedia/opieplayer/libmad/fixed.c | |||
@@ -2,3 +2,3 @@ | |||
2 | * libmad - MPEG audio decoder library | 2 | * libmad - MPEG audio decoder library |
3 | * Copyright (C) 2000-2001 Robert Leslie | 3 | * Copyright (C) 2000-2004 Underbit Technologies, Inc. |
4 | * | 4 | * |
@@ -37 +37,45 @@ mad_fixed_t mad_f_abs(mad_fixed_t x) | |||
37 | } | 37 | } |
38 | |||
39 | /* | ||
40 | * NAME:fixed->div() | ||
41 | * DESCRIPTION:perform division using fixed-point math | ||
42 | */ | ||
43 | mad_fixed_t mad_f_div(mad_fixed_t x, mad_fixed_t y) | ||
44 | { | ||
45 | mad_fixed_t q, r; | ||
46 | unsigned int bits; | ||
47 | |||
48 | q = mad_f_abs(x / y); | ||
49 | |||
50 | if (x < 0) { | ||
51 | x = -x; | ||
52 | y = -y; | ||
53 | } | ||
54 | |||
55 | r = x % y; | ||
56 | |||
57 | if (y < 0) { | ||
58 | x = -x; | ||
59 | y = -y; | ||
60 | } | ||
61 | |||
62 | if (q > mad_f_intpart(MAD_F_MAX) && | ||
63 | !(q == -mad_f_intpart(MAD_F_MIN) && r == 0 && (x < 0) != (y < 0))) | ||
64 | return 0; | ||
65 | |||
66 | for (bits = MAD_F_FRACBITS; bits && r; --bits) { | ||
67 | q <<= 1, r <<= 1; | ||
68 | if (r >= y) | ||
69 | r -= y, ++q; | ||
70 | } | ||
71 | |||
72 | /* round */ | ||
73 | if (2 * r >= y) | ||
74 | ++q; | ||
75 | |||
76 | /* fix sign */ | ||
77 | if ((x < 0) != (y < 0)) | ||
78 | q = -q; | ||
79 | |||
80 | return q << bits; | ||
81 | } | ||