Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

111 righe
3.9 KiB

  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file qnan.h
  35. * @brief Some utilities for our dealings with qnans.
  36. *
  37. * @note Some loaders use qnans to mark invalid values tempoarily, also
  38. * Assimp explicitly enforces undefined normals to be set to qnan.
  39. * qnan utilities are available in standard libraries (C99 for example)
  40. * but last time I checked compiler coverage was so bad that I decided
  41. * to reinvent the wheel.
  42. */
  43. #ifndef AI_QNAN_H_INCLUDED
  44. #define AI_QNAN_H_INCLUDED
  45. // ---------------------------------------------------------------------------
  46. /** Data structure to represent the bit pattern of a 32 Bit
  47. * IEEE 754 floating-point number. */
  48. union _IEEESingle
  49. {
  50. float Float;
  51. struct
  52. {
  53. uint32_t Frac : 23;
  54. uint32_t Exp : 8;
  55. uint32_t Sign : 1;
  56. } IEEE;
  57. } ;
  58. // ---------------------------------------------------------------------------
  59. /** Check whether a given float is qNaN.
  60. * @param in Input value */
  61. AI_FORCE_INLINE bool is_qnan(float in)
  62. {
  63. // the straightforward solution does not work:
  64. // return (in != in);
  65. // compiler generates code like this
  66. // load <in> to <register-with-different-width>
  67. // compare <register-with-different-width> against <in>
  68. // FIXME: Use <float> stuff instead? I think fpclassify needs C99
  69. return (reinterpret_cast<_IEEESingle*>(&in)->IEEE.Exp == (1u << 8)-1 &&
  70. reinterpret_cast<_IEEESingle*>(&in)->IEEE.Frac);
  71. }
  72. // ---------------------------------------------------------------------------
  73. /** Check whether a float is NOT qNaN.
  74. * @param in Input value */
  75. AI_FORCE_INLINE bool is_not_qnan(float in)
  76. {
  77. return !is_qnan(in);
  78. }
  79. // ---------------------------------------------------------------------------
  80. /** @brief check whether a float is either NaN or (+/-) INF.
  81. *
  82. * Denorms return false, they're treated like normal values.
  83. * @param in Input value */
  84. AI_FORCE_INLINE bool is_special_float(float in)
  85. {
  86. return (reinterpret_cast<_IEEESingle*>(&in)->IEEE.Exp == (1u << 8)-1);
  87. }
  88. // ---------------------------------------------------------------------------
  89. /** @brief Get a fresh qnan. */
  90. AI_FORCE_INLINE float get_qnan()
  91. {
  92. return std::numeric_limits<float>::quiet_NaN();
  93. }
  94. #endif // !! AI_QNAN_H_INCLUDED