diff options
author | Mathias Agopian <mathias@google.com> | 2011-03-07 17:49:54 -0800 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2011-03-07 17:54:03 -0800 |
commit | 0eab8214986faf6e5ba1982b8b01c4f06d61b3c4 (patch) | |
tree | c43d1887ac6cf05baaf8814a58ddc019f9fecd3d /core/java/android/hardware/SensorManager.java | |
parent | c5f7f582a6b7632c34270a9d1edb04bc4b7e2640 (diff) | |
download | frameworks_base-0eab8214986faf6e5ba1982b8b01c4f06d61b3c4.zip frameworks_base-0eab8214986faf6e5ba1982b8b01c4f06d61b3c4.tar.gz frameworks_base-0eab8214986faf6e5ba1982b8b01c4f06d61b3c4.tar.bz2 |
fix [4026375] SensorManager quaternion functions can call sqrt with a negative number
Just make sure to clamp the argument to zero.
Bug: 4026375
Change-Id: I00c5f6c83659a290d5e1e191a1c8d25ec06834c2
Diffstat (limited to 'core/java/android/hardware/SensorManager.java')
-rw-r--r-- | core/java/android/hardware/SensorManager.java | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java index dd4096b..2111cce 100644 --- a/core/java/android/hardware/SensorManager.java +++ b/core/java/android/hardware/SensorManager.java @@ -2051,8 +2051,8 @@ public class SensorManager if (rv.length == 4) { Q[0] = rv[3]; } else { - //In this case, the w component of the quaternion is known to be a positive number - Q[0] = (float)Math.sqrt(1 - rv[0]*rv[0] - rv[1]*rv[1] - rv[2]*rv[2]); + Q[0] = 1 - rv[0]*rv[0] - rv[1]*rv[1] - rv[2]*rv[2]; + Q[0] = (Q[0] > 0) ? (float)Math.sqrt(Q[0]) : 0; } Q[1] = rv[0]; Q[2] = rv[1]; |