Skip to content

Commit 0279246

Browse files
committed
Utils: Fix a bug in the linear transformation code.
Fix a bug where an incorrect result would be computed if you used the linear transformation code to do a reverse transformation (from B's domain into A's domain) when the scaler fraction was negative. Change-Id: I8e5f109314d235a177ab41f65d3c4cd08cff78be Signed-off-by: John Grossman <johngro@google.com>
1 parent 92f5f58 commit 0279246

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libs/utils/LinearTransform.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static bool linear_transform_s64_to_s64(
114114
int64_t basis1,
115115
int32_t N,
116116
uint32_t D,
117+
bool invert_frac,
117118
int64_t basis2,
118119
int64_t* out) {
119120
uint64_t scaled, res;
@@ -137,8 +138,8 @@ static bool linear_transform_s64_to_s64(
137138
is_neg = !is_neg;
138139

139140
if (!scale_u64_to_u64(abs_val,
140-
ABS(N),
141-
D,
141+
invert_frac ? D : ABS(N),
142+
invert_frac ? ABS(N) : D,
142143
&scaled,
143144
is_neg))
144145
return false; // overflow/undeflow
@@ -191,6 +192,7 @@ bool LinearTransform::doForwardTransform(int64_t a_in, int64_t* b_out) const {
191192
a_zero,
192193
a_to_b_numer,
193194
a_to_b_denom,
195+
false,
194196
b_zero,
195197
b_out);
196198
}
@@ -201,8 +203,9 @@ bool LinearTransform::doReverseTransform(int64_t b_in, int64_t* a_out) const {
201203

202204
return linear_transform_s64_to_s64(b_in,
203205
b_zero,
204-
a_to_b_denom,
205206
a_to_b_numer,
207+
a_to_b_denom,
208+
true,
206209
a_zero,
207210
a_out);
208211
}

0 commit comments

Comments
 (0)