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