math.in.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /* A GNU-like <math.h>.
  2. Copyright (C) 2002-2003, 2007 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #ifndef _GL_MATH_H
  14. /* The include_next requires a split double-inclusion guard. */
  15. #@INCLUDE_NEXT@ @NEXT_MATH_H@
  16. #ifndef _GL_MATH_H
  17. #define _GL_MATH_H
  18. /* The definition of GL_LINK_WARNING is copied here. */
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /* Write x as
  23. x = mantissa * 2^exp
  24. where
  25. If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
  26. If x is zero: mantissa = x, exp = 0.
  27. If x is infinite or NaN: mantissa = x, exp unspecified.
  28. Store exp in *EXPPTR and return mantissa. */
  29. #if @GNULIB_FREXP@
  30. # if @REPLACE_FREXP@
  31. # define frexp rpl_frexp
  32. extern double frexp (double x, int *expptr);
  33. # endif
  34. #elif defined GNULIB_POSIXCHECK
  35. # undef frexp
  36. # define frexp(x,e) \
  37. (GL_LINK_WARNING ("frexp is unportable - " \
  38. "use gnulib module frexp for portability"), \
  39. frexp (x, e))
  40. #endif
  41. #if @GNULIB_MATHL@ || !@HAVE_DECL_ACOSL@
  42. extern long double acosl (long double x);
  43. #endif
  44. #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
  45. # undef acosl
  46. # define acosl(x) \
  47. (GL_LINK_WARNING ("acosl is unportable - " \
  48. "use gnulib module mathl for portability"), \
  49. acosl (x))
  50. #endif
  51. #if @GNULIB_MATHL@ || !@HAVE_DECL_ASINL@
  52. extern long double asinl (long double x);
  53. #endif
  54. #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
  55. # undef asinl
  56. # define asinl(x) \
  57. (GL_LINK_WARNING ("asinl is unportable - " \
  58. "use gnulib module mathl for portability"), \
  59. asinl (x))
  60. #endif
  61. #if @GNULIB_MATHL@ || !@HAVE_DECL_ATANL@
  62. extern long double atanl (long double x);
  63. #endif
  64. #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
  65. # undef atanl
  66. # define atanl(x) \
  67. (GL_LINK_WARNING ("atanl is unportable - " \
  68. "use gnulib module mathl for portability"), \
  69. atanl (x))
  70. #endif
  71. #if @GNULIB_CEILF@
  72. # if @REPLACE_CEILF@
  73. # define ceilf rpl_ceilf
  74. extern float ceilf (float x);
  75. # endif
  76. #elif defined GNULIB_POSIXCHECK
  77. # undef ceilf
  78. # define ceilf(x) \
  79. (GL_LINK_WARNING ("ceilf is unportable - " \
  80. "use gnulib module ceilf for portability"), \
  81. ceilf (x))
  82. #endif
  83. #if @GNULIB_CEILL@
  84. # if @REPLACE_CEILL@
  85. # define ceill rpl_ceill
  86. extern long double ceill (long double x);
  87. # endif
  88. #elif defined GNULIB_POSIXCHECK
  89. # undef ceill
  90. # define ceill(x) \
  91. (GL_LINK_WARNING ("ceill is unportable - " \
  92. "use gnulib module ceill for portability"), \
  93. ceill (x))
  94. #endif
  95. #if @GNULIB_MATHL@ || !@HAVE_DECL_COSL@
  96. extern long double cosl (long double x);
  97. #endif
  98. #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
  99. # undef cosl
  100. # define cosl(x) \
  101. (GL_LINK_WARNING ("cosl is unportable - " \
  102. "use gnulib module mathl for portability"), \
  103. cosl (x))
  104. #endif
  105. #if @GNULIB_MATHL@ || !@HAVE_DECL_EXPL@
  106. extern long double expl (long double x);
  107. #endif
  108. #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
  109. # undef expl
  110. # define expl(x) \
  111. (GL_LINK_WARNING ("expl is unportable - " \
  112. "use gnulib module mathl for portability"), \
  113. expl (x))
  114. #endif
  115. #if @GNULIB_FLOORF@
  116. # if @REPLACE_FLOORF@
  117. # define floorf rpl_floorf
  118. extern float floorf (float x);
  119. # endif
  120. #elif defined GNULIB_POSIXCHECK
  121. # undef floorf
  122. # define floorf(x) \
  123. (GL_LINK_WARNING ("floorf is unportable - " \
  124. "use gnulib module floorf for portability"), \
  125. floorf (x))
  126. #endif
  127. #if @GNULIB_FLOORL@
  128. # if @REPLACE_FLOORL@
  129. # define floorl rpl_floorl
  130. extern long double floorl (long double x);
  131. # endif
  132. #elif defined GNULIB_POSIXCHECK
  133. # undef floorl
  134. # define floorl(x) \
  135. (GL_LINK_WARNING ("floorl is unportable - " \
  136. "use gnulib module floorl for portability"), \
  137. floorl (x))
  138. #endif
  139. /* Write x as
  140. x = mantissa * 2^exp
  141. where
  142. If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
  143. If x is zero: mantissa = x, exp = 0.
  144. If x is infinite or NaN: mantissa = x, exp unspecified.
  145. Store exp in *EXPPTR and return mantissa. */
  146. #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
  147. # define frexpl rpl_frexpl
  148. #endif
  149. #if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
  150. extern long double frexpl (long double x, int *expptr);
  151. #endif
  152. #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
  153. # undef frexpl
  154. # define frexpl(x,e) \
  155. (GL_LINK_WARNING ("frexpl is unportable - " \
  156. "use gnulib module frexpl for portability"), \
  157. frexpl (x, e))
  158. #endif
  159. /* Return x * 2^exp. */
  160. #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
  161. # define ldexpl rpl_ldexpl
  162. #endif
  163. #if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@
  164. extern long double ldexpl (long double x, int exp);
  165. #endif
  166. #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
  167. # undef ldexpl
  168. # define ldexpl(x,e) \
  169. (GL_LINK_WARNING ("ldexpl is unportable - " \
  170. "use gnulib module ldexpl for portability"), \
  171. ldexpl (x, e))
  172. #endif
  173. #if @GNULIB_MATHL@ || !@HAVE_DECL_LOGL@
  174. extern long double logl (long double x);
  175. #endif
  176. #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
  177. # undef logl
  178. # define logl(x) \
  179. (GL_LINK_WARNING ("logl is unportable - " \
  180. "use gnulib module mathl for portability"), \
  181. logl (x))
  182. #endif
  183. #if @GNULIB_ROUNDF@
  184. # if @REPLACE_ROUNDF@
  185. # undef roundf
  186. # define roundf rpl_roundf
  187. extern float roundf (float x);
  188. # endif
  189. #elif defined GNULIB_POSIXCHECK
  190. # undef roundf
  191. # define roundf(x) \
  192. (GL_LINK_WARNING ("roundf is unportable - " \
  193. "use gnulib module roundf for portability"), \
  194. roundf (x))
  195. #endif
  196. #if @GNULIB_ROUND@
  197. # if @REPLACE_ROUND@
  198. # undef round
  199. # define round rpl_round
  200. extern double round (double x);
  201. # endif
  202. #elif defined GNULIB_POSIXCHECK
  203. # undef round
  204. # define round(x) \
  205. (GL_LINK_WARNING ("round is unportable - " \
  206. "use gnulib module round for portability"), \
  207. round (x))
  208. #endif
  209. #if @GNULIB_ROUNDL@
  210. # if @REPLACE_ROUNDL@
  211. # undef roundl
  212. # define roundl rpl_roundl
  213. extern long double roundl (long double x);
  214. # endif
  215. #elif defined GNULIB_POSIXCHECK
  216. # undef roundl
  217. # define roundl(x) \
  218. (GL_LINK_WARNING ("roundl is unportable - " \
  219. "use gnulib module roundl for portability"), \
  220. roundl (x))
  221. #endif
  222. #if @GNULIB_MATHL@ || !@HAVE_DECL_SINL@
  223. extern long double sinl (long double x);
  224. #endif
  225. #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
  226. # undef sinl
  227. # define sinl(x) \
  228. (GL_LINK_WARNING ("sinl is unportable - " \
  229. "use gnulib module mathl for portability"), \
  230. sinl (x))
  231. #endif
  232. #if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@
  233. extern long double sqrtl (long double x);
  234. #endif
  235. #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
  236. # undef sqrtl
  237. # define sqrtl(x) \
  238. (GL_LINK_WARNING ("sqrtl is unportable - " \
  239. "use gnulib module mathl for portability"), \
  240. sqrtl (x))
  241. #endif
  242. #if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@
  243. extern long double tanl (long double x);
  244. #endif
  245. #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
  246. # undef tanl
  247. # define tanl(x) \
  248. (GL_LINK_WARNING ("tanl is unportable - " \
  249. "use gnulib module mathl for portability"), \
  250. tanl (x))
  251. #endif
  252. #if @GNULIB_TRUNCF@
  253. # if !@HAVE_DECL_TRUNCF@
  254. # define truncf rpl_truncf
  255. extern float truncf (float x);
  256. # endif
  257. #elif defined GNULIB_POSIXCHECK
  258. # undef truncf
  259. # define truncf(x) \
  260. (GL_LINK_WARNING ("truncf is unportable - " \
  261. "use gnulib module truncf for portability"), \
  262. truncf (x))
  263. #endif
  264. #if @GNULIB_TRUNC@
  265. # if !@HAVE_DECL_TRUNC@
  266. # define trunc rpl_trunc
  267. extern double trunc (double x);
  268. # endif
  269. #elif defined GNULIB_POSIXCHECK
  270. # undef trunc
  271. # define trunc(x) \
  272. (GL_LINK_WARNING ("trunc is unportable - " \
  273. "use gnulib module trunc for portability"), \
  274. trunc (x))
  275. #endif
  276. #if @GNULIB_TRUNCL@
  277. # if !@HAVE_DECL_TRUNCL@
  278. # define truncl rpl_truncl
  279. extern long double truncl (long double x);
  280. # endif
  281. #elif defined GNULIB_POSIXCHECK
  282. # undef truncl
  283. # define truncl(x) \
  284. (GL_LINK_WARNING ("truncl is unportable - " \
  285. "use gnulib module truncl for portability"), \
  286. truncl (x))
  287. #endif
  288. #if @GNULIB_ISFINITE@
  289. # if @REPLACE_ISFINITE@
  290. extern int gl_isfinitef (float x);
  291. extern int gl_isfinited (double x);
  292. extern int gl_isfinitel (long double x);
  293. # undef isfinite
  294. # define isfinite(x) \
  295. (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
  296. sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
  297. gl_isfinitef (x))
  298. # endif
  299. #elif defined GNULIB_POSIXCHECK
  300. /* How to override a macro? */
  301. #endif
  302. #if @GNULIB_SIGNBIT@
  303. # if @REPLACE_SIGNBIT_USING_GCC@
  304. # undef signbit
  305. /* GCC 4.0 and newer provides three built-ins for signbit. */
  306. # define signbit(x) \
  307. (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
  308. sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
  309. __builtin_signbitf (x))
  310. # endif
  311. # if @REPLACE_SIGNBIT@
  312. # undef signbit
  313. extern int gl_signbitf (float arg);
  314. extern int gl_signbitd (double arg);
  315. extern int gl_signbitl (long double arg);
  316. # if __GNUC__ >= 2 && !__STRICT_ANSI__
  317. # if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
  318. # define gl_signbitf(arg) \
  319. ({ union { float _value; \
  320. unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
  321. } _m; \
  322. _m._value = (arg); \
  323. (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \
  324. })
  325. # endif
  326. # if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
  327. # define gl_signbitd(arg) \
  328. ({ union { double _value; \
  329. unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
  330. } _m; \
  331. _m._value = (arg); \
  332. (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \
  333. })
  334. # endif
  335. # if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
  336. # define gl_signbitl(arg) \
  337. ({ union { long double _value; \
  338. unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
  339. } _m; \
  340. _m._value = (arg); \
  341. (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \
  342. })
  343. # endif
  344. # endif
  345. # define signbit(x) \
  346. (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
  347. sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
  348. gl_signbitf (x))
  349. # endif
  350. #elif defined GNULIB_POSIXCHECK
  351. /* How to override a macro? */
  352. #endif
  353. #ifdef __cplusplus
  354. }
  355. #endif
  356. #endif /* _GL_MATH_H */
  357. #endif /* _GL_MATH_H */