1/*
2 * File: look1_binlx.c
3 *
4 * Code generated for Simulink model 'EV3Control_sil_sil_ec'.
5 *
6 * Model version : 1.2
7 * Simulink Coder version : 9.0 (R2018b) 24-May-2018
8 * C/C++ source code generated on : Tue Oct 29 09:31:45 2019
9 */
10
11#include "rtwtypes.h"
12#include "look1_binlx.h"
13
14real_T look1_binlx(real_T u0, const real_T bp0[], const real_T table[], uint32_T
15 maxIndex)
16{
17 real_T frac;
18 uint32_T iRght;
19 uint32_T iLeft;
20 uint32_T bpIdx;
21
22 /* Column-major Lookup 1-D
23 Search method: 'binary'
24 Use previous index: 'off'
25 Interpolation method: 'Linear point-slope'
26 Extrapolation method: 'Linear'
27 Use last breakpoint for index at or above upper limit: 'off'
28 Remove protection against out-of-range input in generated code: 'off'
29 */
30 /* Prelookup - Index and Fraction
31 Index Search method: 'binary'
32 Extrapolation method: 'Linear'
33 Use previous index: 'off'
34 Use last breakpoint for index at or above upper limit: 'off'
35 Remove protection against out-of-range input in generated code: 'off'
36 */
37 if (u0 <= bp0[0U]) {
38 iLeft = 0U;
39 frac = (u0 - bp0[0U]) / (bp0[1U] - bp0[0U]);
40 } else if (u0 < bp0[maxIndex]) {
41 /* Binary Search */
42 bpIdx = maxIndex >> 1U;
43 iLeft = 0U;
44 iRght = maxIndex;
45 while (iRght - iLeft > 1U) {
46 if (u0 < bp0[bpIdx]) {
47 iRght = bpIdx;
48 } else {
49 iLeft = bpIdx;
50 }
51
52 bpIdx = (iRght + iLeft) >> 1U;
53 }
54
55 frac = (u0 - bp0[iLeft]) / (bp0[iLeft + 1U] - bp0[iLeft]);
56 } else {
57 iLeft = maxIndex - 1U;
58 frac = (u0 - bp0[maxIndex - 1U]) / (bp0[maxIndex] - bp0[maxIndex - 1U]);
59 }
60
61 /* Column-major Interpolation 1-D
62 Interpolation method: 'Linear point-slope'
63 Use last breakpoint for index at or above upper limit: 'off'
64 Overflow mode: 'wrapping'
65 */
66 return (table[iLeft + 1U] - table[iLeft]) * frac + table[iLeft];
67}
68
69/*
70 * File trailer for generated code.
71 *
72 * [EOF]
73 */
74