1 /*
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #include "stepwise.hpp"
18 
19 #include <cstddef>
20 #include <limits>
21 
22 namespace ec
23 {
24 float stepwise(const ec::StepwiseInfo& info, float input)
25 {
26     float value = info.output[0]; // if we are below the lowest
27                                   // point, we set the lowest value
28 
29     for (size_t ii = 1; ii < ec::maxStepwisePoints; ii++)
30     {
31 
32         if (info.reading[ii] == std::numeric_limits<float>::quiet_NaN())
33         {
34             break;
35         }
36         if (info.reading[ii] > input)
37         {
38             break;
39         }
40         value = info.output[ii];
41     }
42 
43     return value;
44 }
45 } // namespace ec