blob: 1e7b15a9828704effaf3d1bb392d08df0bc33912 [file] [log] [blame]
Matthew Sloyanfbba3642020-10-15 13:53:27 +01001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include <cmath>
9
10namespace armnnUtils
11{
12
13/**
14 * Compare two floats and return true if their values are within a specified tolerance of each other.
15 * @param a
16 * @param b
17 * @param tolerancePercentage If not supplied default will be 1% tolerance (1.0f)
18 * @return true if the value of float b is within tolerancePercentage of the value for float a.
19 */
20inline bool within_percentage_tolerance(float a, float b, float tolerancePercent = 1.0f)
21{
22 float toleranceValue = std::fabs(a * (tolerancePercent / 100));
23 return std::fabs(a - b) <= toleranceValue;
24}
25
26} //namespace armnn
27