OSDN Git Service

fix [3452750] Issue 14634: SensorManager.getRotationMatrixFromVector gets NaN-Values...
authorMathias Agopian <mathias@google.com>
Tue, 15 Feb 2011 00:34:07 +0000 (16:34 -0800)
committerMathias Agopian <mathias@google.com>
Tue, 8 Mar 2011 01:58:56 +0000 (17:58 -0800)
make sure to not pass negative numbers to sqrt().

Change-Id: Ia31f7ebb7b75c79b548e428c6084fa55031617d0
related-bug: 3452750

core/java/android/hardware/SensorManager.java

index cc82170..b1a9349 100644 (file)
@@ -1970,7 +1970,8 @@ public class SensorManager
         if (rotationVector.length == 4) {
             q0 = rotationVector[3];
         } else {
-            q0 = (float)Math.sqrt(1 - q1*q1 - q2*q2 - q3*q3);
+            q0 = 1 - q1*q1 - q2*q2 - q3*q3;
+            q0 = (q0 > 0) ? (float)Math.sqrt(q0) : 0;
         }
 
         float sq_q1 = 2 * q1 * q1;