Fix zero-point calculation rounding error (#2326) @tensorflow/micro Use roundf to correctly round negative values. bug=fixes #2327
diff --git a/tensorflow/lite/micro/test_helpers.h b/tensorflow/lite/micro/test_helpers.h index 2a6204f..6315b9f 100644 --- a/tensorflow/lite/micro/test_helpers.h +++ b/tensorflow/lite/micro/test_helpers.h
@@ -1,4 +1,4 @@ -/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. +/* Copyright 2023 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ #define TENSORFLOW_LITE_MICRO_TEST_HELPERS_H_ #include <algorithm> +#include <cmath> #include <cstdint> #include <limits> #include <type_traits> @@ -325,7 +326,7 @@ template <typename T> inline int ZeroPointFromMinMax(const float min, const float max) { return static_cast<int>(std::numeric_limits<T>::min()) + - static_cast<int>(-min / ScaleFromMinMax<T>(min, max) + 0.5f); + static_cast<int>(roundf(-min / ScaleFromMinMax<T>(min, max))); } } // namespace testing