File: rtGetNaN.c

    1   /*
    2    * Academic License - for use in teaching, academic research, and meeting
    3    * course requirements at degree granting institutions only.  Not for
    4    * government, commercial, or other organizational use.
    5    *
    6    * rtGetNaN.c
    7    *
    8    * Code generation for function 'calculateTransformations'
    9    *
   10    */
   11   
   12   /*
   13    * Abstract:
   14    *       MATLAB for code generation function to initialize non-finite, NaN
   15    */
   16   #include "rtGetNaN.h"
   17   #define NumBitsPerChar                 8U
   18   
   19   /* Function: rtGetNaN ==================================================
   20    * Abstract:
   21    * Initialize rtNaN needed by the generated code.
   22    * NaN is initialized as non-signaling. Assumes IEEE.
   23    */
   24   real_T rtGetNaN(void)
   25   {
   26     size_t bitsPerReal = sizeof(real_T) * (NumBitsPerChar);
   27     real_T nan = 0.0;
   28     if (bitsPerReal == 32U) {
   29       nan = rtGetNaNF();
   30     } else {
   31       uint16_T one = 1U;
   32       enum {
   33         LittleEndian,
   34         BigEndian
   35       } machByteOrder = (*((uint8_T *) &one) == 1U) ? LittleEndian : BigEndian;
   36       switch (machByteOrder) {
   37        case LittleEndian:
   38         {
   39           union {
   40             LittleEndianIEEEDouble bitVal;
   41             real_T fltVal;
   42           } tmpVal;
   43   
   44           tmpVal.bitVal.words.wordH = 0xFFF80000U;
   45           tmpVal.bitVal.words.wordL = 0x00000000U;
   46           nan = tmpVal.fltVal;
   47           break;
   48         }
   49   
   50        case BigEndian:
   51         {
   52           union {
   53             BigEndianIEEEDouble bitVal;
   54             real_T fltVal;
   55           } tmpVal;
   56   
   57           tmpVal.bitVal.words.wordH = 0x7FFFFFFFU;
   58           tmpVal.bitVal.words.wordL = 0xFFFFFFFFU;
   59           nan = tmpVal.fltVal;
   60           break;
   61         }
   62       }
   63     }
   64   
   65     return nan;
   66   }
   67   
   68   /* Function: rtGetNaNF ==================================================
   69    * Abstract:
   70    * Initialize rtNaNF needed by the generated code.
   71    * NaN is initialized as non-signaling. Assumes IEEE.
   72    */
   73   real32_T rtGetNaNF(void)
   74   {
   75     IEEESingle nanF = { { 0 } };
   76   
   77     uint16_T one = 1U;
   78     enum {
   79       LittleEndian,
   80       BigEndian
   81     } machByteOrder = (*((uint8_T *) &one) == 1U) ? LittleEndian : BigEndian;
   82     switch (machByteOrder) {
   83      case LittleEndian:
   84       {
   85         nanF.wordL.wordLuint = 0xFFC00000U;
   86         break;
   87       }
   88   
   89      case BigEndian:
   90       {
   91         nanF.wordL.wordLuint = 0x7FFFFFFFU;
   92         break;
   93       }
   94     }
   95   
   96     return nanF.wordL.wordLreal;
   97   }
   98   
   99   /* End of code generation (rtGetNaN.c) */
  100