Skip to content

Commit 5f94c31

Browse files
committed
fix [3452750] Issue 14634: SensorManager.getRotationMatrixFromVector gets NaN-Values [external] [DO NOT MERGE]
make sure to not pass negative numbers to sqrt(). Change-Id: Ia31f7ebb7b75c79b548e428c6084fa55031617d0 related-bug: 3452750
1 parent 241d8a8 commit 5f94c31

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

core/java/android/hardware/SensorManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,8 @@ public static void getRotationMatrixFromVector(float[] R, float[] rotationVector
19701970
if (rotationVector.length == 4) {
19711971
q0 = rotationVector[3];
19721972
} else {
1973-
q0 = (float)Math.sqrt(1 - q1*q1 - q2*q2 - q3*q3);
1973+
q0 = 1 - q1*q1 - q2*q2 - q3*q3;
1974+
q0 = (q0 > 0) ? (float)Math.sqrt(q0) : 0;
19741975
}
19751976

19761977
float sq_q1 = 2 * q1 * q1;

0 commit comments

Comments
 (0)