cuttlefish: EmulatedFakeCamera2: fix -Wimplicit-int-float-conversion
IEEE754 single precision cannot precisely represent RAND_MAX.
error: implicit conversion from 'int' to 'float' changes value from
2147483647 to 2147483648 [-Werror,-Wimplicit-int-float-conversion]
For purposes of generating random uniforms, this does not matter. Add
explicit casts of RAND_MAX to float to fix.
Bug: 139945549
Test: lunch aosp_cf_x86_phone-userdebug && mm
Change-Id: I72fe9a4f0fa76a0df1552fffb16a793205272d78
Signed-off-by: Nick Desaulniers <[email protected]>
diff --git a/guest/hals/camera/EmulatedFakeCamera2.cpp b/guest/hals/camera/EmulatedFakeCamera2.cpp
index 63a5c1a..e292361 100644
--- a/guest/hals/camera/EmulatedFakeCamera2.cpp
+++ b/guest/hals/camera/EmulatedFakeCamera2.cpp
@@ -1441,12 +1441,12 @@
// To simulate some kind of real detection going on, we jitter the rectangles
// on each frame by a few pixels in each dimension.
for (size_t i = 0; i < numFaces * 4; i++) {
- rects[i] += (int32_t)(((float)rand() / RAND_MAX) * 6 - 3);
+ rects[i] += (int32_t)(((float)rand() / (float)RAND_MAX) * 6 - 3);
}
// The confidence scores (0-100) are similarly jittered.
uint8_t scores[numFaces] = {85, 95};
for (size_t i = 0; i < numFaces; i++) {
- scores[i] += (int32_t)(((float)rand() / RAND_MAX) * 10 - 5);
+ scores[i] += (int32_t)(((float)rand() / (float)RAND_MAX) * 10 - 5);
}
res = add_camera_metadata_entry(frame, ANDROID_STATISTICS_FACE_RECTANGLES,
@@ -1485,7 +1485,7 @@
};
// Jitter these a bit less than the rects
for (size_t i = 0; i < numFaces * 6; i++) {
- features[i] += (int32_t)(((float)rand() / RAND_MAX) * 4 - 2);
+ features[i] += (int32_t)(((float)rand() / (float)RAND_MAX) * 4 - 2);
}
// These are unique IDs that are used to identify each face while it's
// visible to the detector (if a face went away and came back, it'd get a