1 | /* |
2 | * rt_nonfinite.c |
3 | * |
4 | * Code generation for model "BMS". |
5 | * |
6 | * Model version : 1.15 |
7 | * Simulink Coder version : 9.2 (R2019b) 18-Jul-2019 |
8 | * C source code generated on : Thu Aug 20 14:49:14 2020 |
9 | * |
10 | * Target selection: grt.tlc |
11 | * Note: GRT includes extra infrastructure and instrumentation for prototyping |
12 | * Embedded hardware selection: Intel->x86-64 (Windows64) |
13 | * Code generation objectives: Unspecified |
14 | * Validation result: Not run |
15 | */ |
16 | |
17 | /* |
18 | * Abstract: |
19 | * Function to initialize non-finites, |
20 | * (Inf, NaN and -Inf). |
21 | */ |
22 | #include "rt_nonfinite.h" |
23 | #include "rtGetNaN.h" |
24 | #include "rtGetInf.h" |
25 | #define NumBitsPerChar 8U |
26 | |
27 | real_T rtInf; |
28 | real_T rtMinusInf; |
29 | real_T rtNaN; |
30 | real32_T rtInfF; |
31 | real32_T rtMinusInfF; |
32 | real32_T rtNaNF; |
33 | |
34 | /* |
35 | * Initialize the rtInf, rtMinusInf, and rtNaN needed by the |
36 | * generated code. NaN is initialized as non-signaling. Assumes IEEE. |
37 | */ |
38 | void rt_InitInfAndNaN(size_t realSize) |
39 | { |
40 | (void) (realSize); |
41 | rtNaN = rtGetNaN(); |
42 | rtNaNF = rtGetNaNF(); |
43 | rtInf = rtGetInf(); |
44 | rtInfF = rtGetInfF(); |
45 | rtMinusInf = rtGetMinusInf(); |
46 | rtMinusInfF = rtGetMinusInfF(); |
47 | } |
48 | |
49 | /* Test if value is infinite */ |
50 | boolean_T rtIsInf(real_T value) |
51 | { |
52 | return (boolean_T)((value==rtInf || value==rtMinusInf) ? 1U : 0U); |
53 | } |
54 | |
55 | /* Test if single-precision value is infinite */ |
56 | boolean_T rtIsInfF(real32_T value) |
57 | { |
58 | return (boolean_T)(((value)==rtInfF || (value)==rtMinusInfF) ? 1U : 0U); |
59 | } |
60 | |
61 | /* Test if value is not a number */ |
62 | boolean_T rtIsNaN(real_T value) |
63 | { |
64 | boolean_T result = (boolean_T) 0; |
65 | size_t bitsPerReal = sizeof(real_T) * (NumBitsPerChar); |
66 | if (bitsPerReal == 32U) { |
67 | result = rtIsNaNF((real32_T)value); |
68 | } else { |
69 | union { |
70 | LittleEndianIEEEDouble bitVal; |
71 | real_T fltVal; |
72 | } tmpVal; |
73 | |
74 | tmpVal.fltVal = value; |
75 | result = (boolean_T)((tmpVal.bitVal.words.wordH & 0x7FF00000) == 0x7FF00000 && |
76 | ( (tmpVal.bitVal.words.wordH & 0x000FFFFF) != 0 || |
77 | (tmpVal.bitVal.words.wordL != 0) )); |
78 | } |
79 | |
80 | return result; |
81 | } |
82 | |
83 | /* Test if single-precision value is not a number */ |
84 | boolean_T rtIsNaNF(real32_T value) |
85 | { |
86 | IEEESingle tmp; |
87 | tmp.wordL.wordLreal = value; |
88 | return (boolean_T)( (tmp.wordL.wordLuint & 0x7F800000) == 0x7F800000 && |
89 | (tmp.wordL.wordLuint & 0x007FFFFF) != 0 ); |
90 | } |
91 |