mathl.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /****************************************************************************/
  2. /* mathl.h v8.2.2 */
  3. /* */
  4. /* Copyright (c) 1997-2017 Texas Instruments Incorporated */
  5. /* http://www.ti.com/ */
  6. /* */
  7. /* Redistribution and use in source and binary forms, with or without */
  8. /* modification, are permitted provided that the following conditions */
  9. /* are met: */
  10. /* */
  11. /* Redistributions of source code must retain the above copyright */
  12. /* notice, this list of conditions and the following disclaimer. */
  13. /* */
  14. /* Redistributions in binary form must reproduce the above copyright */
  15. /* notice, this list of conditions and the following disclaimer in */
  16. /* the documentation and/or other materials provided with the */
  17. /* distribution. */
  18. /* */
  19. /* Neither the name of Texas Instruments Incorporated nor the names */
  20. /* of its contributors may be used to endorse or promote products */
  21. /* derived from this software without specific prior written */
  22. /* permission. */
  23. /* */
  24. /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
  25. /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
  26. /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
  27. /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
  28. /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
  29. /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
  30. /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
  31. /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
  32. /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  33. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
  34. /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  35. /* */
  36. /****************************************************************************/
  37. #ifndef __mathl__
  38. #define __mathl__
  39. #pragma diag_push
  40. #pragma CHECK_MISRA("-6.3") /* standard types required for standard headers */
  41. #pragma CHECK_MISRA("-19.1") /* #includes required for implementation */
  42. #pragma CHECK_MISRA("-19.7") /* macros required for implementation */
  43. #pragma CHECK_MISRA("-20.1") /* standard headers must define standard names */
  44. #pragma CHECK_MISRA("-20.2") /* standard headers must define standard names */
  45. #include <linkage.h>
  46. #ifdef __cplusplus
  47. //----------------------------------------------------------------------------
  48. // <cmathl> IS RECOMMENDED OVER <mathl.h>. <mathl.h> IS PROVIDED FOR
  49. // COMPATIBILITY WITH C AND THIS USAGE IS DEPRECATED IN C++
  50. //----------------------------------------------------------------------------
  51. extern "C" namespace std {
  52. #endif /* !__cplusplus */
  53. _CODE_ACCESS long double sqrtl (long double x);
  54. _CODE_ACCESS long double expl (long double x);
  55. _CODE_ACCESS long double logl (long double x);
  56. _CODE_ACCESS long double log10l(long double x);
  57. _CODE_ACCESS long double powl (long double x, long double y);
  58. _CODE_ACCESS long double sinl (long double x);
  59. _CODE_ACCESS long double cosl (long double x);
  60. _CODE_ACCESS long double tanl (long double x);
  61. _CODE_ACCESS long double asinl (long double x);
  62. _CODE_ACCESS long double acosl (long double x);
  63. _CODE_ACCESS long double atanl (long double x);
  64. _CODE_ACCESS long double atan2l(long double y, long double x);
  65. _CODE_ACCESS long double sinhl (long double x);
  66. _CODE_ACCESS long double coshl (long double x);
  67. _CODE_ACCESS long double tanhl (long double x);
  68. _IDECL long double ceill (long double x);
  69. _IDECL long double floorl(long double x);
  70. _CODE_ACCESS long double fabsl (long double x);
  71. _CODE_ACCESS long double ldexpl(long double x, int n);
  72. _CODE_ACCESS long double frexpl(long double x, int *_exp);
  73. _CODE_ACCESS long double modfl (long double x, long double *ip);
  74. _CODE_ACCESS long double fmodl (long double x, long double y);
  75. _CODE_ACCESS long double _roundl(long double x); /* round-to-nearest */
  76. _CODE_ACCESS long double _truncl(long double x); /* truncate towards 0 */
  77. /* ------------------------------------------------- */
  78. /* Routines below are an addition to ANSI math.h */
  79. /* Some (noted with "9x" in comment) will become ANSI*/
  80. /* once C9x is approved. */
  81. /* ------------------------------------------------- */
  82. #define HUGE_VALL ((long double)__INFINITY__)
  83. _CODE_ACCESS long double rsqrtl(long double x); /* 1/sqrtl(x) but *MUCH* faster*/
  84. _CODE_ACCESS long double exp2l (long double x); /*9x math equiv to powl(2.0 ,x) */
  85. _CODE_ACCESS long double exp10l(long double x); /* math equiv to powl(10.0,x) */
  86. _CODE_ACCESS long double log2l (long double x);/*9x math equiv to logl(x)/logl(2)*/
  87. _CODE_ACCESS long double powil (long double x, int i); /* == powl(x,(long double)i)*/
  88. _CODE_ACCESS long double cotl (long double x);
  89. _CODE_ACCESS long double acotl (long double x);
  90. _CODE_ACCESS long double acot2l(long double x, long double y);
  91. _CODE_ACCESS long double cothl (long double x);
  92. _CODE_ACCESS long double asinhl(long double x); /* 9x */
  93. _CODE_ACCESS long double acoshl(long double x); /* 9x */
  94. _CODE_ACCESS long double atanhl(long double x); /* 9x */
  95. _CODE_ACCESS long double acothl(long double x);
  96. _CODE_ACCESS long double log1pl(long double x);
  97. _CODE_ACCESS long double copysignl(long double x, long double y);
  98. _CODE_ACCESS long double hypotl(long double x, long double y);
  99. #ifndef __INLINE_ISINF__
  100. #define __INLINE_ISINF__ 0
  101. #endif
  102. #if __INLINE_ISINF__
  103. _IDECL int __isinfl(long double x);
  104. #else
  105. _CODE_ACCESS int __isinfl(long double x);
  106. #endif
  107. _IDECL int __isnanl(long double x);
  108. _IDECL int __isfinitel(long double x);
  109. _IDECL int __isnormall(long double x);
  110. _CODE_ACCESS int __fpclassifyl(long double x);
  111. #define isinf(x) (sizeof(x) == sizeof(double) ? __isinf(x) : \
  112. sizeof(x) == sizeof(float) ? __isinff(x) : __isinfl(x))
  113. #define isnan(x) (sizeof(x) == sizeof(double) ? __isnan(x) : \
  114. sizeof(x) == sizeof(float) ? __isnanf(x) : __isnanl(x))
  115. #define isfinite(x) (sizeof(x) == sizeof(double) ? __isfinite(x) : \
  116. sizeof(x) == sizeof(float) ? __isfinitef(x) : \
  117. __isfinitel(x))
  118. #define isnormal(x) (sizeof(x) == sizeof(double) ? __isnormal(x) : \
  119. sizeof(x) == sizeof(float) ? __isnormalf(x) : \
  120. __isnormall(x))
  121. #define fpclassify(x) (sizeof(x) == sizeof(double) ? __fpclassify(x) : \
  122. sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \
  123. __fpclassifyl(x))
  124. #pragma CHECK_MISRA("-19.4") /* macro expands to unparanthesized */
  125. #define roundl _roundl /* 9x round-to-nearest */
  126. #define truncl _truncl /* 9x truncate towards 0 */
  127. #ifdef _INLINE
  128. #pragma CHECK_MISRA("-5.7") /* identifier name reused */
  129. #pragma CHECK_MISRA("-8.5") /* definition of function in header file */
  130. #pragma CHECK_MISRA("-10.1") /* SDSCM00051481 */
  131. #pragma CHECK_MISRA("-10.2") /* SDSCM00051481 */
  132. #pragma CHECK_MISRA("-12.2") /* doesn't actually have side effects */
  133. #pragma CHECK_MISRA("-12.4") /* doesn't actually have side effects */
  134. #pragma CHECK_MISRA("-12.5") /* operands of && not primary expressions */
  135. #pragma CHECK_MISRA("-13.3") /* float exact equality comparison */
  136. #pragma CHECK_MISRA("-14.7") /* no single point of return */
  137. #pragma CHECK_MISRA("-14.9") /* if not followed by compound statement */
  138. /****************************************************************************/
  139. /* Inline versions of floorl, ceill, fmodl */
  140. /****************************************************************************/
  141. static __inline long double floorl(long double x)
  142. {
  143. long double y = 0;
  144. return (modfl(x, &y) < 0 ? y - 1 : y);
  145. }
  146. static __inline long double ceill(long double x)
  147. {
  148. long double y = 0;
  149. return (modfl(x, &y) > 0 ? y + 1 : y);
  150. }
  151. #if __INLINE_ISINF__
  152. #ifndef REAL_TO_REALNUM
  153. #error isinf can only be inlined in the compilation of the rts
  154. #endif
  155. static __inline int __isinfl(long double x)
  156. {
  157. realnum _x;
  158. REAL_TO_REALNUM(x, _x);
  159. return _x.exp == (REAL_EMAX + 1) && (_x.mantissa << 1) == 0;
  160. }
  161. #endif /* __INLINE_ISINF__ */
  162. static __inline int __isnanl(volatile long double x)
  163. {
  164. return x != x;
  165. }
  166. static __inline int __isfinitel(long double x)
  167. {
  168. return (!__isinfl(x) && !__isnanl(x));
  169. }
  170. static __inline int __isnormall(long double x)
  171. {
  172. return (__isfinitel(x) && (x != 0.0));
  173. }
  174. #endif /* defined(_INLINE) */
  175. #ifdef __cplusplus
  176. } /* extern "C" namespace std */
  177. #endif /* __cplusplus */
  178. #pragma diag_pop
  179. #endif /* __mathl__ */
  180. #pragma diag_push
  181. /* using declarations must occur outside header guard to support including both
  182. C and C++-wrapped version of header; see _CPP_STYLE_HEADER check */
  183. /* this code is for C++ mode only and thus also not relevant for MISRA */
  184. #pragma CHECK_MISRA("-19.15")
  185. #if defined(__cplusplus) && !defined(_CPP_STYLE_HEADER)
  186. using std::sqrtl;
  187. using std::expl ;
  188. using std::logl ;
  189. using std::log10l;
  190. using std::powl;
  191. using std::sinl;
  192. using std::cosl;
  193. using std::tanl;
  194. using std::asinl;
  195. using std::acosl;
  196. using std::atanl;
  197. using std::atan2l;
  198. using std::sinhl;
  199. using std::coshl;
  200. using std::tanhl;
  201. using std::ceill;
  202. using std::floorl;
  203. using std::fabsl;
  204. using std::ldexpl;
  205. using std::frexpl;
  206. using std::modfl;
  207. using std::fmodl;
  208. using std::log1pl;
  209. using std::copysignl;
  210. using std::hypotl;
  211. using std::rsqrtl; /* 1/sqrtl(x) but *MUCH* faster*/
  212. using std::exp2l; /*9x math equiv to powl(2.0 ,x) */
  213. using std::exp10l; /* math equiv to powl(10.0,x) */
  214. using std::log2l; /*9x math equiv to logl(x)/logl(2)*/
  215. using std::powil; /* == powl(x,(long double)i)*/
  216. using std::cotl;
  217. using std::acotl;
  218. using std::acot2l;
  219. using std::cothl;
  220. using std::asinhl; /* 9x */
  221. using std::acoshl; /* 9x */
  222. using std::atanhl; /* 9x */
  223. using std::acothl;
  224. #endif /* ! _CPP_STYLE_HEADER */
  225. #if defined(__cplusplus)
  226. using std::__isnanl;
  227. using std::__isinfl;
  228. using std::__isfinitel;
  229. using std::__isnormall;
  230. using std::__fpclassifyl;
  231. using std::_roundl; /* round-to-nearest */
  232. using std::_truncl; /* truncate towards 0 */
  233. #endif /* __cplusplus */
  234. #pragma diag_pop