Skip to content

Commit 241d8a8

Browse files
committed
fix [4026375] SensorManager quaternion functions can call sqrt with a negative number [DO NOT MERGE]
Just make sure to clamp the argument to zero. Bug: 4026375 Change-Id: Idd3d4ef977e87c1b3f6b54371105c3152d7dc6b9
1 parent ff5a099 commit 241d8a8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

core/java/android/hardware/SensorManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,8 +2026,8 @@ public static void getQuaternionFromVector(float[] Q, float[] rv) {
20262026
if (rv.length == 4) {
20272027
Q[0] = rv[3];
20282028
} else {
2029-
//In this case, the w component of the quaternion is known to be a positive number
2030-
Q[0] = (float)Math.sqrt(1 - rv[0]*rv[0] - rv[1]*rv[1] - rv[2]*rv[2]);
2029+
Q[0] = 1 - rv[0]*rv[0] - rv[1]*rv[1] - rv[2]*rv[2];
2030+
Q[0] = (Q[0] > 0) ? (float)Math.sqrt(Q[0]) : 0;
20312031
}
20322032
Q[1] = rv[0];
20332033
Q[2] = rv[1];

0 commit comments

Comments
 (0)