1/*
2 * File: rt_nonfinite.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/*
12 * Abstract:
13 * Function to initialize non-finites,
14 * (Inf, NaN and -Inf).
15 */
16#include "rt_nonfinite.h"
17#include "rtGetNaN.h"
18#include "rtGetInf.h"
19#define NumBitsPerChar 8U
20
21real_T rtInf;
22real_T rtMinusInf;
23real_T rtNaN;
24real32_T rtInfF;
25real32_T rtMinusInfF;
26real32_T rtNaNF;
27
28/*
29 * Initialize the rtInf, rtMinusInf, and rtNaN needed by the
30 * generated code. NaN is initialized as non-signaling. Assumes IEEE.
31 */
32void rt_InitInfAndNaN(size_t realSize)
33{
34 (void) (realSize);
35 rtNaN = rtGetNaN();
36 rtNaNF = rtGetNaNF();
37 rtInf = rtGetInf();
38 rtInfF = rtGetInfF();
39 rtMinusInf = rtGetMinusInf();
40 rtMinusInfF = rtGetMinusInfF();
41}
42
43/* Test if value is infinite */
44boolean_T rtIsInf(real_T value)
45{
46 return (boolean_T)((value==rtInf || value==rtMinusInf) ? 1U : 0U);
47}
48
49/* Test if single-precision value is infinite */
50boolean_T rtIsInfF(real32_T value)
51{
52 return (boolean_T)(((value)==rtInfF || (value)==rtMinusInfF) ? 1U : 0U);
53}
54
55/* Test if value is not a number */
56boolean_T rtIsNaN(real_T value)
57{
58 boolean_T result = (boolean_T) 0;
59 size_t bitsPerReal = sizeof(real_T) * (NumBitsPerChar);
60 if (bitsPerReal == 32U) {
61 result = rtIsNaNF((real32_T)value);
62 } else {
63 uint16_T one = 1U;
64 enum {
65 LittleEndian,
66 BigEndian
67 } machByteOrder = (*((uint8_T *) &one) == 1U) ? LittleEndian : BigEndian;
68 switch (machByteOrder) {
69 case LittleEndian:
70 {
71 union {
72 LittleEndianIEEEDouble bitVal;
73 real_T fltVal;
74 } tmpVal;
75
76 tmpVal.fltVal = value;
77 result = (boolean_T)((tmpVal.bitVal.words.wordH & 0x7FF00000) ==
78 0x7FF00000 &&
79 ( (tmpVal.bitVal.words.wordH & 0x000FFFFF) != 0 ||
80 (tmpVal.bitVal.words.wordL != 0) ));
81 break;
82 }
83
84 case BigEndian:
85 {
86 union {
87 BigEndianIEEEDouble bitVal;
88 real_T fltVal;
89 } tmpVal;
90
91 tmpVal.fltVal = value;
92 result = (boolean_T)((tmpVal.bitVal.words.wordH & 0x7FF00000) ==
93 0x7FF00000 &&
94 ( (tmpVal.bitVal.words.wordH & 0x000FFFFF) != 0 ||
95 (tmpVal.bitVal.words.wordL != 0) ));
96 break;
97 }
98 }
99 }
100
101 return result;
102}
103
104/* Test if single-precision value is not a number */
105boolean_T rtIsNaNF(real32_T value)
106{
107 IEEESingle tmp;
108 tmp.wordL.wordLreal = value;
109 return (boolean_T)( (tmp.wordL.wordLuint & 0x7F800000) == 0x7F800000 &&
110 (tmp.wordL.wordLuint & 0x007FFFFF) != 0 );
111}
112
113/*
114 * File trailer for generated code.
115 *
116 * [EOF]
117 */
118