1/*
2 * rt_nonfinite.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-finites,
24 * (Inf, NaN and -Inf).
25 */
26#include "rt_nonfinite.h"
27#include "rtGetNaN.h"
28#include "rtGetInf.h"
29#define NumBitsPerChar 8U
30
31extern "C" {
32 real_T rtInf;
33 real_T rtMinusInf;
34 real_T rtNaN;
35 real32_T rtInfF;
36 real32_T rtMinusInfF;
37 real32_T rtNaNF;
38}
39 extern "C"
40{
41 /*
42 * Initialize the rtInf, rtMinusInf, and rtNaN needed by the
43 * generated code. NaN is initialized as non-signaling. Assumes IEEE.
44 */
45 void rt_InitInfAndNaN(size_t realSize)
46 {
47 (void) (realSize);
48 rtNaN = rtGetNaN();
49 rtNaNF = rtGetNaNF();
50 rtInf = rtGetInf();
51 rtInfF = rtGetInfF();
52 rtMinusInf = rtGetMinusInf();
53 rtMinusInfF = rtGetMinusInfF();
54 }
55
56 /* Test if value is infinite */
57 boolean_T rtIsInf(real_T value)
58 {
59 return (boolean_T)((value==rtInf || value==rtMinusInf) ? 1U : 0U);
60 }
61
62 /* Test if single-precision value is infinite */
63 boolean_T rtIsInfF(real32_T value)
64 {
65 return (boolean_T)(((value)==rtInfF || (value)==rtMinusInfF) ? 1U : 0U);
66 }
67
68 /* Test if value is not a number */
69 boolean_T rtIsNaN(real_T value)
70 {
71 boolean_T result = (boolean_T) 0;
72 size_t bitsPerReal = sizeof(real_T) * (NumBitsPerChar);
73 if (bitsPerReal == 32U) {
74 result = rtIsNaNF((real32_T)value);
75 } else {
76 union {
77 LittleEndianIEEEDouble bitVal;
78 real_T fltVal;
79 } tmpVal;
80
81 tmpVal.fltVal = value;
82 result = (boolean_T)((tmpVal.bitVal.words.wordH & 0x7FF00000) ==
83 0x7FF00000 &&
84 ( (tmpVal.bitVal.words.wordH & 0x000FFFFF) != 0 ||
85 (tmpVal.bitVal.words.wordL != 0) ));
86 }
87
88 return result;
89 }
90
91 /* Test if single-precision value is not a number */
92 boolean_T rtIsNaNF(real32_T value)
93 {
94 IEEESingle tmp;
95 tmp.wordL.wordLreal = value;
96 return (boolean_T)( (tmp.wordL.wordLuint & 0x7F800000) == 0x7F800000 &&
97 (tmp.wordL.wordLuint & 0x007FFFFF) != 0 );
98 }
99}
100