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