rt_nonfinite.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "rtGetNaN.h"
  2. #include "rtGetInf.h"
  3. #include <stddef.h>
  4. #include "rtwtypes.h"
  5. #include "rt_nonfinite.h"
  6. #define NumBitsPerChar 8U
  7. real_T rtInf;
  8. real_T rtMinusInf;
  9. real_T rtNaN;
  10. real32_T rtInfF;
  11. real32_T rtMinusInfF;
  12. real32_T rtNaNF;
  13. void rt_InitInfAndNaN(size_t realSize)
  14. {
  15. (void) (realSize);
  16. rtNaN = rtGetNaN();
  17. rtNaNF = rtGetNaNF();
  18. rtInf = rtGetInf();
  19. rtInfF = rtGetInfF();
  20. rtMinusInf = rtGetMinusInf();
  21. rtMinusInfF = rtGetMinusInfF();
  22. }
  23. boolean_T rtIsInf(real_T value)
  24. {
  25. return (boolean_T)((value==rtInf || value==rtMinusInf) ? 1U : 0U);
  26. }
  27. boolean_T rtIsInfF(real32_T value)
  28. {
  29. return (boolean_T)(((value)==rtInfF || (value)==rtMinusInfF) ? 1U : 0U);
  30. }
  31. boolean_T rtIsNaN(real_T value)
  32. {
  33. boolean_T result = (boolean_T) 0;
  34. size_t bitsPerReal = sizeof(real_T) * (NumBitsPerChar);
  35. if (bitsPerReal == 32U) {
  36. result = rtIsNaNF((real32_T)value);
  37. } else {
  38. union {
  39. LittleEndianIEEEDouble bitVal;
  40. real_T fltVal;
  41. } tmpVal;
  42. tmpVal.fltVal = value;
  43. result = (boolean_T)((tmpVal.bitVal.words.wordH & 0x7FF00000) == 0x7FF00000 &&
  44. ( (tmpVal.bitVal.words.wordH & 0x000FFFFF) != 0 ||
  45. (tmpVal.bitVal.words.wordL != 0) ));
  46. }
  47. return result;
  48. }
  49. boolean_T rtIsNaNF(real32_T value)
  50. {
  51. IEEESingle tmp;
  52. tmp.wordL.wordLreal = value;
  53. return (boolean_T)( (tmp.wordL.wordLuint & 0x7F800000) == 0x7F800000 &&
  54. (tmp.wordL.wordLuint & 0x007FFFFF) != 0 );
  55. }