Skip to content

Commit ecf56f4

Browse files
authored
Fix zero-point calculation rounding error (#2326)
@tensorflow/micro Use roundf to correctly round negative values. bug=fixes #2327
1 parent 743e85c commit ecf56f4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tensorflow/lite/micro/test_helpers.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ limitations under the License.
1717
#define TENSORFLOW_LITE_MICRO_TEST_HELPERS_H_
1818

1919
#include <algorithm>
20+
#include <cmath>
2021
#include <cstdint>
2122
#include <limits>
2223
#include <type_traits>
@@ -325,7 +326,7 @@ inline float SymmetricScaleFromMinMax(const float min, const float max) {
325326
template <typename T>
326327
inline int ZeroPointFromMinMax(const float min, const float max) {
327328
return static_cast<int>(std::numeric_limits<T>::min()) +
328-
static_cast<int>(-min / ScaleFromMinMax<T>(min, max) + 0.5f);
329+
static_cast<int>(roundf(-min / ScaleFromMinMax<T>(min, max)));
329330
}
330331

331332
} // namespace testing

0 commit comments

Comments
 (0)