1 | /* |
2 | * rtGetNaN.c |
3 | * |
4 | * Classroom License -- for classroom instructional use only. Not for |
5 | * government, commercial, academic research, or other organizational use. |
6 | * |
7 | * Code generation for model "RaspberryMagmanControl". |
8 | * |
9 | * Model version : 1.38 |
10 | * Simulink Coder version : 8.11 (R2016b) 25-Aug-2016 |
11 | * C source code generated on : Thu Dec 22 16:38:00 2016 |
12 | * |
13 | * Target selection: ert.tlc |
14 | * Note: GRT includes extra infrastructure and instrumentation for prototyping |
15 | * Embedded hardware selection: ARM Compatible->ARM Cortex |
16 | * Code generation objectives: Unspecified |
17 | * Validation result: Not run |
18 | */ |
19 | |
20 | /* |
21 | * Abstract: |
22 | * Function to initialize non-finite, NaN |
23 | */ |
24 | #include "rtGetNaN.h" |
25 | #define NumBitsPerChar 8U |
26 | |
27 | /* |
28 | * Initialize rtNaN needed by the generated code. |
29 | * NaN is initialized as non-signaling. Assumes IEEE. |
30 | */ |
31 | real_T rtGetNaN(void) |
32 | { |
33 | size_t bitsPerReal = sizeof(real_T) * (NumBitsPerChar); |
34 | real_T nan = 0.0; |
35 | if (bitsPerReal == 32U) { |
36 | nan = rtGetNaNF(); |
37 | } else { |
38 | uint16_T one = 1U; |
39 | enum { |
40 | LittleEndian, |
41 | BigEndian |
42 | } machByteOrder = (*((uint8_T *) &one) == 1U) ? LittleEndian : BigEndian; |
43 | switch (machByteOrder) { |
44 | case LittleEndian: |
45 | { |
46 | union { |
47 | LittleEndianIEEEDouble bitVal; |
48 | real_T fltVal; |
49 | } tmpVal; |
50 | |
51 | tmpVal.bitVal.words.wordH = 0xFFF80000U; |
52 | tmpVal.bitVal.words.wordL = 0x00000000U; |
53 | nan = tmpVal.fltVal; |
54 | break; |
55 | } |
56 | |
57 | case BigEndian: |
58 | { |
59 | union { |
60 | BigEndianIEEEDouble bitVal; |
61 | real_T fltVal; |
62 | } tmpVal; |
63 | |
64 | tmpVal.bitVal.words.wordH = 0x7FFFFFFFU; |
65 | tmpVal.bitVal.words.wordL = 0xFFFFFFFFU; |
66 | nan = tmpVal.fltVal; |
67 | break; |
68 | } |
69 | } |
70 | } |
71 | |
72 | return nan; |
73 | } |
74 | |
75 | /* |
76 | * Initialize rtNaNF needed by the generated code. |
77 | * NaN is initialized as non-signaling. Assumes IEEE. |
78 | */ |
79 | real32_T rtGetNaNF(void) |
80 | { |
81 | IEEESingle nanF = { { 0 } }; |
82 | |
83 | uint16_T one = 1U; |
84 | enum { |
85 | LittleEndian, |
86 | BigEndian |
87 | } machByteOrder = (*((uint8_T *) &one) == 1U) ? LittleEndian : BigEndian; |
88 | switch (machByteOrder) { |
89 | case LittleEndian: |
90 | { |
91 | nanF.wordL.wordLuint = 0xFFC00000U; |
92 | break; |
93 | } |
94 | |
95 | case BigEndian: |
96 | { |
97 | nanF.wordL.wordLuint = 0x7FFFFFFFU; |
98 | break; |
99 | } |
100 | } |
101 | |
102 | return nanF.wordL.wordLreal; |
103 | } |
104 |