4
0

math.in.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /* A GNU-like <math.h>.
  2. Copyright (C) 2002-2003, 2007-2010 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. #if __GNUC__ >= 3
  15. @PRAGMA_SYSTEM_HEADER@
  16. #endif
  17. /* The include_next requires a split double-inclusion guard. */
  18. #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MATH_H@
  19. #ifndef _GL_MATH_H
  20. #define _GL_MATH_H
  21. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  22. /* The definition of _GL_ARG_NONNULL is copied here. */
  23. /* The definition of _GL_WARN_ON_USE is copied here. */
  24. /* Helper macros to define a portability warning for the
  25. classification macro FUNC called with VALUE. POSIX declares the
  26. classification macros with an argument of real-floating (that is,
  27. one of float, double, or long double). */
  28. #define _GL_WARN_REAL_FLOATING_DECL(func) \
  29. static inline int \
  30. rpl_ ## func ## f (float f) \
  31. { \
  32. return func (f); \
  33. } \
  34. static inline int \
  35. rpl_ ## func ## d (double d) \
  36. { \
  37. return func (d); \
  38. } \
  39. static inline int \
  40. rpl_ ## func ## l (long double l) \
  41. { \
  42. return func (l); \
  43. } \
  44. _GL_WARN_ON_USE (rpl_ ## func ## f, #func " is unportable - " \
  45. "use gnulib module " #func " for portability"); \
  46. _GL_WARN_ON_USE (rpl_ ## func ## d, #func " is unportable - " \
  47. "use gnulib module " #func " for portability"); \
  48. _GL_WARN_ON_USE (rpl_ ## func ## l, #func " is unportable - " \
  49. "use gnulib module " #func " for portability")
  50. #define _GL_WARN_REAL_FLOATING_IMPL(func, value) \
  51. (sizeof (value) == sizeof (float) ? rpl_ ## func ## f (value) \
  52. : sizeof (value) == sizeof (double) ? rpl_ ## func ## d (value) \
  53. : rpl_ ## func ## l (value))
  54. /* POSIX allows platforms that don't support NAN. But all major
  55. machines in the past 15 years have supported something close to
  56. IEEE NaN, so we define this unconditionally. We also must define
  57. it on platforms like Solaris 10, where NAN is present but defined
  58. as a function pointer rather than a floating point constant. */
  59. #if !defined NAN || @REPLACE_NAN@
  60. # undef NAN
  61. /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
  62. # ifdef __DECC
  63. static float
  64. _NaN ()
  65. {
  66. static float zero = 0.0f;
  67. return zero / zero;
  68. }
  69. # define NAN (_NaN())
  70. # else
  71. # define NAN (0.0f / 0.0f)
  72. # endif
  73. #endif
  74. /* Solaris 10 defines HUGE_VAL, but as a function pointer rather
  75. than a floating point constant. */
  76. #if @REPLACE_HUGE_VAL@
  77. # undef HUGE_VAL
  78. # define HUGE_VAL (1.0 / 0.0)
  79. #endif
  80. /* Write x as
  81. x = mantissa * 2^exp
  82. where
  83. If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
  84. If x is zero: mantissa = x, exp = 0.
  85. If x is infinite or NaN: mantissa = x, exp unspecified.
  86. Store exp in *EXPPTR and return mantissa. */
  87. #if @GNULIB_FREXP@
  88. # if @REPLACE_FREXP@
  89. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  90. # define frexp rpl_frexp
  91. # endif
  92. _GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2)));
  93. _GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr));
  94. # else
  95. _GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr));
  96. # endif
  97. _GL_CXXALIASWARN (frexp);
  98. #elif defined GNULIB_POSIXCHECK
  99. # undef frexp
  100. /* Assume frexp is always declared. */
  101. _GL_WARN_ON_USE (frexp, "frexp is unportable - "
  102. "use gnulib module frexp for portability");
  103. #endif
  104. #if @GNULIB_LOGB@
  105. # if !@HAVE_DECL_LOGB@
  106. _GL_EXTERN_C double logb (double x);
  107. # endif
  108. #elif defined GNULIB_POSIXCHECK
  109. # undef logb
  110. # if HAVE_RAW_DECL_LOGB
  111. _GL_WARN_ON_USE (logb, "logb is unportable - "
  112. "use gnulib module logb for portability");
  113. # endif
  114. #endif
  115. #if @GNULIB_ACOSL@
  116. # if !@HAVE_ACOSL@ || !@HAVE_DECL_ACOSL@
  117. _GL_FUNCDECL_SYS (acosl, long double, (long double x));
  118. # endif
  119. _GL_CXXALIAS_SYS (acosl, long double, (long double x));
  120. _GL_CXXALIASWARN (acosl);
  121. #elif defined GNULIB_POSIXCHECK
  122. # undef acosl
  123. # if HAVE_RAW_DECL_ACOSL
  124. _GL_WARN_ON_USE (acosl, "acosl is unportable - "
  125. "use gnulib module mathl for portability");
  126. # endif
  127. #endif
  128. #if @GNULIB_ASINL@
  129. # if !@HAVE_ASINL@ || !@HAVE_DECL_ASINL@
  130. _GL_FUNCDECL_SYS (asinl, long double, (long double x));
  131. # endif
  132. _GL_CXXALIAS_SYS (asinl, long double, (long double x));
  133. _GL_CXXALIASWARN (asinl);
  134. #elif defined GNULIB_POSIXCHECK
  135. # undef asinl
  136. # if HAVE_RAW_DECL_ASINL
  137. _GL_WARN_ON_USE (asinl, "asinl is unportable - "
  138. "use gnulib module mathl for portability");
  139. # endif
  140. #endif
  141. #if @GNULIB_ATANL@
  142. # if !@HAVE_ATANL@ || !@HAVE_DECL_ATANL@
  143. _GL_FUNCDECL_SYS (atanl, long double, (long double x));
  144. # endif
  145. _GL_CXXALIAS_SYS (atanl, long double, (long double x));
  146. _GL_CXXALIASWARN (atanl);
  147. #elif defined GNULIB_POSIXCHECK
  148. # undef atanl
  149. # if HAVE_RAW_DECL_ATANL
  150. _GL_WARN_ON_USE (atanl, "atanl is unportable - "
  151. "use gnulib module mathl for portability");
  152. # endif
  153. #endif
  154. #if @GNULIB_CEILF@
  155. # if @REPLACE_CEILF@
  156. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  157. # define ceilf rpl_ceilf
  158. # endif
  159. _GL_FUNCDECL_RPL (ceilf, float, (float x));
  160. _GL_CXXALIAS_RPL (ceilf, float, (float x));
  161. # else
  162. # if !@HAVE_DECL_CEILF@
  163. _GL_FUNCDECL_SYS (ceilf, float, (float x));
  164. # endif
  165. _GL_CXXALIAS_SYS (ceilf, float, (float x));
  166. # endif
  167. _GL_CXXALIASWARN (ceilf);
  168. #elif defined GNULIB_POSIXCHECK
  169. # undef ceilf
  170. # if HAVE_RAW_DECL_CEILF
  171. _GL_WARN_ON_USE (ceilf, "ceilf is unportable - "
  172. "use gnulib module ceilf for portability");
  173. # endif
  174. #endif
  175. #if @GNULIB_CEILL@
  176. # if @REPLACE_CEILL@
  177. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  178. # define ceill rpl_ceill
  179. # endif
  180. _GL_FUNCDECL_RPL (ceill, long double, (long double x));
  181. _GL_CXXALIAS_RPL (ceill, long double, (long double x));
  182. # else
  183. # if !@HAVE_DECL_CEILL@
  184. _GL_FUNCDECL_SYS (ceill, long double, (long double x));
  185. # endif
  186. _GL_CXXALIAS_SYS (ceill, long double, (long double x));
  187. # endif
  188. _GL_CXXALIASWARN (ceill);
  189. #elif defined GNULIB_POSIXCHECK
  190. # undef ceill
  191. # if HAVE_RAW_DECL_CEILL
  192. _GL_WARN_ON_USE (ceill, "ceill is unportable - "
  193. "use gnulib module ceill for portability");
  194. # endif
  195. #endif
  196. #if @GNULIB_COSL@
  197. # if !@HAVE_COSL@ || !@HAVE_DECL_COSL@
  198. _GL_FUNCDECL_SYS (cosl, long double, (long double x));
  199. # endif
  200. _GL_CXXALIAS_SYS (cosl, long double, (long double x));
  201. _GL_CXXALIASWARN (cosl);
  202. #elif defined GNULIB_POSIXCHECK
  203. # undef cosl
  204. # if HAVE_RAW_DECL_COSL
  205. _GL_WARN_ON_USE (cosl, "cosl is unportable - "
  206. "use gnulib module mathl for portability");
  207. # endif
  208. #endif
  209. #if @GNULIB_EXPL@
  210. # if !@HAVE_EXPL@ || !@HAVE_DECL_EXPL@
  211. _GL_FUNCDECL_SYS (expl, long double, (long double x));
  212. # endif
  213. _GL_CXXALIAS_SYS (expl, long double, (long double x));
  214. _GL_CXXALIASWARN (expl);
  215. #elif defined GNULIB_POSIXCHECK
  216. # undef expl
  217. # if HAVE_RAW_DECL_EXPL
  218. _GL_WARN_ON_USE (expl, "expl is unportable - "
  219. "use gnulib module mathl for portability");
  220. # endif
  221. #endif
  222. #if @GNULIB_FLOORF@
  223. # if @REPLACE_FLOORF@
  224. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  225. # define floorf rpl_floorf
  226. # endif
  227. _GL_FUNCDECL_RPL (floorf, float, (float x));
  228. _GL_CXXALIAS_RPL (floorf, float, (float x));
  229. #else
  230. # if !@HAVE_DECL_FLOORF@
  231. _GL_FUNCDECL_SYS (floorf, float, (float x));
  232. # endif
  233. _GL_CXXALIAS_SYS (floorf, float, (float x));
  234. # endif
  235. _GL_CXXALIASWARN (floorf);
  236. #elif defined GNULIB_POSIXCHECK
  237. # undef floorf
  238. # if HAVE_RAW_DECL_FLOORF
  239. _GL_WARN_ON_USE (floorf, "floorf is unportable - "
  240. "use gnulib module floorf for portability");
  241. # endif
  242. #endif
  243. #if @GNULIB_FLOORL@
  244. # if @REPLACE_FLOORL@
  245. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  246. # define floorl rpl_floorl
  247. # endif
  248. _GL_FUNCDECL_RPL (floorl, long double, (long double x));
  249. _GL_CXXALIAS_RPL (floorl, long double, (long double x));
  250. # else
  251. # if !@HAVE_DECL_FLOORL@
  252. _GL_FUNCDECL_SYS (floorl, long double, (long double x));
  253. # endif
  254. _GL_CXXALIAS_SYS (floorl, long double, (long double x));
  255. # endif
  256. _GL_CXXALIASWARN (floorl);
  257. #elif defined GNULIB_POSIXCHECK
  258. # undef floorl
  259. # if HAVE_RAW_DECL_FLOORL
  260. _GL_WARN_ON_USE (floorl, "floorl is unportable - "
  261. "use gnulib module floorl for portability");
  262. # endif
  263. #endif
  264. /* Write x as
  265. x = mantissa * 2^exp
  266. where
  267. If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
  268. If x is zero: mantissa = x, exp = 0.
  269. If x is infinite or NaN: mantissa = x, exp unspecified.
  270. Store exp in *EXPPTR and return mantissa. */
  271. #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
  272. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  273. # define frexpl rpl_frexpl
  274. # endif
  275. _GL_FUNCDECL_RPL (frexpl, long double,
  276. (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
  277. _GL_CXXALIAS_RPL (frexpl, long double, (long double x, int *expptr));
  278. #else
  279. # if !@HAVE_DECL_FREXPL@
  280. _GL_FUNCDECL_SYS (frexpl, long double,
  281. (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
  282. # endif
  283. # if @GNULIB_FREXPL@
  284. _GL_CXXALIAS_SYS (frexpl, long double, (long double x, int *expptr));
  285. # endif
  286. #endif
  287. #if @GNULIB_FREXPL@ && !(@REPLACE_FREXPL@ && !@HAVE_DECL_FREXPL@)
  288. _GL_CXXALIASWARN (frexpl);
  289. #endif
  290. #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
  291. # undef frexpl
  292. # if HAVE_RAW_DECL_FREXPL
  293. _GL_WARN_ON_USE (frexpl, "frexpl is unportable - "
  294. "use gnulib module frexpl for portability");
  295. # endif
  296. #endif
  297. /* Return x * 2^exp. */
  298. #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
  299. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  300. # define ldexpl rpl_ldexpl
  301. # endif
  302. _GL_FUNCDECL_RPL (ldexpl, long double, (long double x, int exp));
  303. _GL_CXXALIAS_RPL (ldexpl, long double, (long double x, int exp));
  304. #else
  305. # if !@HAVE_DECL_LDEXPL@
  306. _GL_FUNCDECL_SYS (ldexpl, long double, (long double x, int exp));
  307. # endif
  308. # if @GNULIB_LDEXPL@
  309. _GL_CXXALIAS_SYS (ldexpl, long double, (long double x, int exp));
  310. # endif
  311. #endif
  312. #if @GNULIB_LDEXPL@
  313. _GL_CXXALIASWARN (ldexpl);
  314. #endif
  315. #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
  316. # undef ldexpl
  317. # if HAVE_RAW_DECL_LDEXPL
  318. _GL_WARN_ON_USE (ldexpl, "ldexpl is unportable - "
  319. "use gnulib module ldexpl for portability");
  320. # endif
  321. #endif
  322. #if @GNULIB_LOGL@
  323. # if !@HAVE_LOGL@ || !@HAVE_DECL_LOGL@
  324. _GL_FUNCDECL_SYS (logl, long double, (long double x));
  325. # endif
  326. _GL_CXXALIAS_SYS (logl, long double, (long double x));
  327. _GL_CXXALIASWARN (logl);
  328. #elif defined GNULIB_POSIXCHECK
  329. # undef logl
  330. # if HAVE_RAW_DECL_LOGL
  331. _GL_WARN_ON_USE (logl, "logl is unportable - "
  332. "use gnulib module mathl for portability");
  333. # endif
  334. #endif
  335. #if @GNULIB_ROUNDF@
  336. # if @REPLACE_ROUNDF@
  337. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  338. # undef roundf
  339. # define roundf rpl_roundf
  340. # endif
  341. _GL_FUNCDECL_RPL (roundf, float, (float x));
  342. _GL_CXXALIAS_RPL (roundf, float, (float x));
  343. # else
  344. # if !@HAVE_DECL_ROUNDF@
  345. _GL_FUNCDECL_SYS (roundf, float, (float x));
  346. # endif
  347. _GL_CXXALIAS_SYS (roundf, float, (float x));
  348. # endif
  349. _GL_CXXALIASWARN (roundf);
  350. #elif defined GNULIB_POSIXCHECK
  351. # undef roundf
  352. # if HAVE_RAW_DECL_ROUNDF
  353. _GL_WARN_ON_USE (roundf, "roundf is unportable - "
  354. "use gnulib module roundf for portability");
  355. # endif
  356. #endif
  357. #if @GNULIB_ROUND@
  358. # if @REPLACE_ROUND@
  359. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  360. # undef round
  361. # define round rpl_round
  362. # endif
  363. _GL_FUNCDECL_RPL (round, double, (double x));
  364. _GL_CXXALIAS_RPL (round, double, (double x));
  365. # else
  366. # if !@HAVE_DECL_ROUND@
  367. _GL_FUNCDECL_SYS (round, double, (double x));
  368. # endif
  369. _GL_CXXALIAS_SYS (round, double, (double x));
  370. # endif
  371. _GL_CXXALIASWARN (round);
  372. #elif defined GNULIB_POSIXCHECK
  373. # undef round
  374. # if HAVE_RAW_DECL_ROUND
  375. _GL_WARN_ON_USE (round, "round is unportable - "
  376. "use gnulib module round for portability");
  377. # endif
  378. #endif
  379. #if @GNULIB_ROUNDL@
  380. # if @REPLACE_ROUNDL@
  381. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  382. # undef roundl
  383. # define roundl rpl_roundl
  384. # endif
  385. _GL_FUNCDECL_RPL (roundl, long double, (long double x));
  386. _GL_CXXALIAS_RPL (roundl, long double, (long double x));
  387. # else
  388. # if !@HAVE_DECL_ROUNDL@
  389. _GL_FUNCDECL_SYS (roundl, long double, (long double x));
  390. # endif
  391. _GL_CXXALIAS_SYS (roundl, long double, (long double x));
  392. # endif
  393. _GL_CXXALIASWARN (roundl);
  394. #elif defined GNULIB_POSIXCHECK
  395. # undef roundl
  396. # if HAVE_RAW_DECL_ROUNDL
  397. _GL_WARN_ON_USE (roundl, "roundl is unportable - "
  398. "use gnulib module roundl for portability");
  399. # endif
  400. #endif
  401. #if @GNULIB_SINL@
  402. # if !@HAVE_SINL@ || !@HAVE_DECL_SINL@
  403. _GL_FUNCDECL_SYS (sinl, long double, (long double x));
  404. # endif
  405. _GL_CXXALIAS_SYS (sinl, long double, (long double x));
  406. _GL_CXXALIASWARN (sinl);
  407. #elif defined GNULIB_POSIXCHECK
  408. # undef sinl
  409. # if HAVE_RAW_DECL_SINL
  410. _GL_WARN_ON_USE (sinl, "sinl is unportable - "
  411. "use gnulib module mathl for portability");
  412. # endif
  413. #endif
  414. #if @GNULIB_SQRTL@
  415. # if !@HAVE_SQRTL@ || !@HAVE_DECL_SQRTL@
  416. _GL_FUNCDECL_SYS (sqrtl, long double, (long double x));
  417. # endif
  418. _GL_CXXALIAS_SYS (sqrtl, long double, (long double x));
  419. _GL_CXXALIASWARN (sqrtl);
  420. #elif defined GNULIB_POSIXCHECK
  421. # undef sqrtl
  422. # if HAVE_RAW_DECL_SQRTL
  423. _GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - "
  424. "use gnulib module mathl for portability");
  425. # endif
  426. #endif
  427. #if @GNULIB_TANL@
  428. # if !@HAVE_TANL@ || !@HAVE_DECL_TANL@
  429. _GL_FUNCDECL_SYS (tanl, long double, (long double x));
  430. # endif
  431. _GL_CXXALIAS_SYS (tanl, long double, (long double x));
  432. _GL_CXXALIASWARN (tanl);
  433. #elif defined GNULIB_POSIXCHECK
  434. # undef tanl
  435. # if HAVE_RAW_DECL_TANL
  436. _GL_WARN_ON_USE (tanl, "tanl is unportable - "
  437. "use gnulib module mathl for portability");
  438. # endif
  439. #endif
  440. #if @GNULIB_TRUNCF@
  441. # if !@HAVE_DECL_TRUNCF@
  442. _GL_FUNCDECL_SYS (truncf, float, (float x));
  443. # endif
  444. _GL_CXXALIAS_SYS (truncf, float, (float x));
  445. _GL_CXXALIASWARN (truncf);
  446. #elif defined GNULIB_POSIXCHECK
  447. # undef truncf
  448. # if HAVE_RAW_DECL_TRUNCF
  449. _GL_WARN_ON_USE (truncf, "truncf is unportable - "
  450. "use gnulib module truncf for portability");
  451. # endif
  452. #endif
  453. #if @GNULIB_TRUNC@
  454. # if !@HAVE_DECL_TRUNC@
  455. _GL_FUNCDECL_SYS (trunc, double, (double x));
  456. # endif
  457. _GL_CXXALIAS_SYS (trunc, double, (double x));
  458. _GL_CXXALIASWARN (trunc);
  459. #elif defined GNULIB_POSIXCHECK
  460. # undef trunc
  461. # if HAVE_RAW_DECL_TRUNC
  462. _GL_WARN_ON_USE (trunc, "trunc is unportable - "
  463. "use gnulib module trunc for portability");
  464. # endif
  465. #endif
  466. #if @GNULIB_TRUNCL@
  467. # if @REPLACE_TRUNCL@
  468. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  469. # undef truncl
  470. # define truncl rpl_truncl
  471. # endif
  472. _GL_FUNCDECL_RPL (truncl, long double, (long double x));
  473. _GL_CXXALIAS_RPL (truncl, long double, (long double x));
  474. # else
  475. # if !@HAVE_DECL_TRUNCL@
  476. _GL_FUNCDECL_SYS (truncl, long double, (long double x));
  477. # endif
  478. _GL_CXXALIAS_SYS (truncl, long double, (long double x));
  479. # endif
  480. _GL_CXXALIASWARN (truncl);
  481. #elif defined GNULIB_POSIXCHECK
  482. # undef truncl
  483. # if HAVE_RAW_DECL_TRUNCL
  484. _GL_WARN_ON_USE (truncl, "truncl is unportable - "
  485. "use gnulib module truncl for portability");
  486. # endif
  487. #endif
  488. #if @GNULIB_ISFINITE@
  489. # if @REPLACE_ISFINITE@
  490. _GL_EXTERN_C int gl_isfinitef (float x);
  491. _GL_EXTERN_C int gl_isfinited (double x);
  492. _GL_EXTERN_C int gl_isfinitel (long double x);
  493. # undef isfinite
  494. # define isfinite(x) \
  495. (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
  496. sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
  497. gl_isfinitef (x))
  498. # endif
  499. #elif defined GNULIB_POSIXCHECK
  500. # if defined isfinite
  501. _GL_WARN_REAL_FLOATING_DECL (isfinite);
  502. # undef isfinite
  503. # define isfinite(x) _GL_WARN_REAL_FLOATING_IMPL (isfinite, x)
  504. # endif
  505. #endif
  506. #if @GNULIB_ISINF@
  507. # if @REPLACE_ISINF@
  508. _GL_EXTERN_C int gl_isinff (float x);
  509. _GL_EXTERN_C int gl_isinfd (double x);
  510. _GL_EXTERN_C int gl_isinfl (long double x);
  511. # undef isinf
  512. # define isinf(x) \
  513. (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \
  514. sizeof (x) == sizeof (double) ? gl_isinfd (x) : \
  515. gl_isinff (x))
  516. # endif
  517. #elif defined GNULIB_POSIXCHECK
  518. # if defined isinf
  519. _GL_WARN_REAL_FLOATING_DECL (isinf);
  520. # undef isinf
  521. # define isinf(x) _GL_WARN_REAL_FLOATING_IMPL (isinf, x)
  522. # endif
  523. #endif
  524. #if @GNULIB_ISNANF@
  525. /* Test for NaN for 'float' numbers. */
  526. # if @HAVE_ISNANF@
  527. /* The original <math.h> included above provides a declaration of isnan macro
  528. or (older) isnanf function. */
  529. # if __GNUC__ >= 4
  530. /* GCC 4.0 and newer provides three built-ins for isnan. */
  531. # undef isnanf
  532. # define isnanf(x) __builtin_isnanf ((float)(x))
  533. # elif defined isnan
  534. # undef isnanf
  535. # define isnanf(x) isnan ((float)(x))
  536. # endif
  537. # else
  538. /* Test whether X is a NaN. */
  539. # undef isnanf
  540. # define isnanf rpl_isnanf
  541. _GL_EXTERN_C int isnanf (float x);
  542. # endif
  543. #endif
  544. #if @GNULIB_ISNAND@
  545. /* Test for NaN for 'double' numbers.
  546. This function is a gnulib extension, unlike isnan() which applied only
  547. to 'double' numbers earlier but now is a type-generic macro. */
  548. # if @HAVE_ISNAND@
  549. /* The original <math.h> included above provides a declaration of isnan macro. */
  550. # if __GNUC__ >= 4
  551. /* GCC 4.0 and newer provides three built-ins for isnan. */
  552. # undef isnand
  553. # define isnand(x) __builtin_isnan ((double)(x))
  554. # else
  555. # undef isnand
  556. # define isnand(x) isnan ((double)(x))
  557. # endif
  558. # else
  559. /* Test whether X is a NaN. */
  560. # undef isnand
  561. # define isnand rpl_isnand
  562. _GL_EXTERN_C int isnand (double x);
  563. # endif
  564. #endif
  565. #if @GNULIB_ISNANL@
  566. /* Test for NaN for 'long double' numbers. */
  567. # if @HAVE_ISNANL@
  568. /* The original <math.h> included above provides a declaration of isnan macro or (older) isnanl function. */
  569. # if __GNUC__ >= 4
  570. /* GCC 4.0 and newer provides three built-ins for isnan. */
  571. # undef isnanl
  572. # define isnanl(x) __builtin_isnanl ((long double)(x))
  573. # elif defined isnan
  574. # undef isnanl
  575. # define isnanl(x) isnan ((long double)(x))
  576. # endif
  577. # else
  578. /* Test whether X is a NaN. */
  579. # undef isnanl
  580. # define isnanl rpl_isnanl
  581. _GL_EXTERN_C int isnanl (long double x);
  582. # endif
  583. #endif
  584. /* This must come *after* the snippets for GNULIB_ISNANF and GNULIB_ISNANL! */
  585. #if @GNULIB_ISNAN@
  586. # if @REPLACE_ISNAN@
  587. /* We can't just use the isnanf macro (e.g.) as exposed by
  588. isnanf.h (e.g.) here, because those may end up being macros
  589. that recursively expand back to isnan. So use the gnulib
  590. replacements for them directly. */
  591. # if @HAVE_ISNANF@ && __GNUC__ >= 4
  592. # define gl_isnan_f(x) __builtin_isnan ((float)(x))
  593. # else
  594. _GL_EXTERN_C int rpl_isnanf (float x);
  595. # define gl_isnan_f(x) rpl_isnanf (x)
  596. # endif
  597. # if @HAVE_ISNAND@ && __GNUC__ >= 4
  598. # define gl_isnan_d(x) __builtin_isnan ((double)(x))
  599. # else
  600. _GL_EXTERN_C int rpl_isnand (double x);
  601. # define gl_isnan_d(x) rpl_isnand (x)
  602. # endif
  603. # if @HAVE_ISNANL@ && __GNUC__ >= 4
  604. # define gl_isnan_l(x) __builtin_isnan ((long double)(x))
  605. # else
  606. _GL_EXTERN_C int rpl_isnanl (long double x);
  607. # define gl_isnan_l(x) rpl_isnanl (x)
  608. # endif
  609. # undef isnan
  610. # define isnan(x) \
  611. (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
  612. sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
  613. gl_isnan_f (x))
  614. # endif
  615. #elif defined GNULIB_POSIXCHECK
  616. # if defined isnan
  617. _GL_WARN_REAL_FLOATING_DECL (isnan);
  618. # undef isnan
  619. # define isnan(x) _GL_WARN_REAL_FLOATING_IMPL (isnan, x)
  620. # endif
  621. #endif
  622. #if @GNULIB_SIGNBIT@
  623. # if @REPLACE_SIGNBIT_USING_GCC@
  624. # undef signbit
  625. /* GCC 4.0 and newer provides three built-ins for signbit. */
  626. # define signbit(x) \
  627. (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
  628. sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
  629. __builtin_signbitf (x))
  630. # endif
  631. # if @REPLACE_SIGNBIT@
  632. # undef signbit
  633. _GL_EXTERN_C int gl_signbitf (float arg);
  634. _GL_EXTERN_C int gl_signbitd (double arg);
  635. _GL_EXTERN_C int gl_signbitl (long double arg);
  636. # if __GNUC__ >= 2 && !__STRICT_ANSI__
  637. # if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
  638. # define gl_signbitf_OPTIMIZED_MACRO
  639. # define gl_signbitf(arg) \
  640. ({ union { float _value; \
  641. unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
  642. } _m; \
  643. _m._value = (arg); \
  644. (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \
  645. })
  646. # endif
  647. # if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd
  648. # define gl_signbitd_OPTIMIZED_MACRO
  649. # define gl_signbitd(arg) \
  650. ({ union { double _value; \
  651. unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
  652. } _m; \
  653. _m._value = (arg); \
  654. (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \
  655. })
  656. # endif
  657. # if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl
  658. # define gl_signbitl_OPTIMIZED_MACRO
  659. # define gl_signbitl(arg) \
  660. ({ union { long double _value; \
  661. unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
  662. } _m; \
  663. _m._value = (arg); \
  664. (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \
  665. })
  666. # endif
  667. # endif
  668. # define signbit(x) \
  669. (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
  670. sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
  671. gl_signbitf (x))
  672. # endif
  673. #elif defined GNULIB_POSIXCHECK
  674. # if defined signbit
  675. _GL_WARN_REAL_FLOATING_DECL (signbit);
  676. # undef signbit
  677. # define signbit(x) _GL_WARN_REAL_FLOATING_IMPL (signbit, x)
  678. # endif
  679. #endif
  680. #endif /* _GL_MATH_H */
  681. #endif /* _GL_MATH_H */