math.in.h 24 KB

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