mathcalls.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Prototype declarations for math functions; helper file for <math.h>.
  17. Copyright (C) 1996-2026 Free Software Foundation, Inc.
  18. This file is part of the GNU C Library.
  19. The GNU C Library is free software; you can redistribute it and/or
  20. modify it under the terms of the GNU Lesser General Public
  21. License as published by the Free Software Foundation; either
  22. version 2.1 of the License, or (at your option) any later version.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library; if not, see
  29. <https://www.gnu.org/licenses/>. */
  30. /* NOTE: Because of the special way this file is used by <math.h>, this
  31. file must NOT be protected from multiple inclusion as header files
  32. usually are.
  33. This file provides prototype declarations for the math functions.
  34. Most functions are declared using the macro:
  35. __MATHCALL (NAME,[_r], (ARGS...));
  36. This means there is a function `NAME' returning `double' and a function
  37. `NAMEf' returning `float'. Each place `_Mdouble_' appears in the
  38. prototype, that is actually `double' in the prototype for `NAME' and
  39. `float' in the prototype for `NAMEf'. Reentrant variant functions are
  40. called `NAME_r' and `NAMEf_r'.
  41. Functions returning other types like `int' are declared using the macro:
  42. __MATHDECL (TYPE, NAME,[_r], (ARGS...));
  43. This is just like __MATHCALL but for a function returning `TYPE'
  44. instead of `_Mdouble_'. In all of these cases, there is still
  45. both a `NAME' and a `NAMEf' that takes `float' arguments.
  46. Note that there must be no whitespace before the argument passed for
  47. NAME, to make token pasting work with -traditional. */
  48. #ifndef _MATH_H
  49. # error "Never include <bits/mathcalls.h> directly; include <math.h> instead."
  50. #endif
  51. /* Trigonometric functions. */
  52. /* Arc cosine of X. */
  53. __MATHCALL_VEC (acos,, (_Mdouble_ __x));
  54. /* Arc sine of X. */
  55. __MATHCALL_VEC (asin,, (_Mdouble_ __x));
  56. /* Arc tangent of X. */
  57. __MATHCALL_VEC (atan,, (_Mdouble_ __x));
  58. /* Arc tangent of Y/X. */
  59. __MATHCALL_VEC (atan2,, (_Mdouble_ __y, _Mdouble_ __x));
  60. /* Cosine of X. */
  61. __MATHCALL_VEC (cos,, (_Mdouble_ __x));
  62. /* Sine of X. */
  63. __MATHCALL_VEC (sin,, (_Mdouble_ __x));
  64. /* Tangent of X. */
  65. __MATHCALL_VEC (tan,, (_Mdouble_ __x));
  66. #if __GLIBC_USE (IEC_60559_FUNCS_EXT_C23)
  67. /* Arc cosine of X, divided by pi. */
  68. __MATHCALL (acospi,, (_Mdouble_ __x));
  69. __MATHCALL_VEC (acospi,, (_Mdouble_ __x));
  70. /* Arc sine of X, divided by pi. */
  71. __MATHCALL (asinpi,, (_Mdouble_ __x));
  72. __MATHCALL_VEC (asinpi,, (_Mdouble_ __x));
  73. /* Arc tangent of X, divided by pi. */
  74. __MATHCALL (atanpi,, (_Mdouble_ __x));
  75. __MATHCALL_VEC (atanpi,, (_Mdouble_ __x));
  76. /* Arc tangent of Y/X, divided by pi. */
  77. __MATHCALL (atan2pi,, (_Mdouble_ __y, _Mdouble_ __x));
  78. __MATHCALL_VEC (atan2pi,, (_Mdouble_ __y, _Mdouble_ __x));
  79. /* Cosine of pi * X. */
  80. __MATHCALL_VEC (cospi,, (_Mdouble_ __x));
  81. /* Sine of pi * X. */
  82. __MATHCALL_VEC (sinpi,, (_Mdouble_ __x));
  83. /* Tangent of pi * X. */
  84. __MATHCALL_VEC (tanpi,, (_Mdouble_ __x));
  85. #endif
  86. /* Hyperbolic functions. */
  87. /* Hyperbolic cosine of X. */
  88. __MATHCALL_VEC (cosh,, (_Mdouble_ __x));
  89. /* Hyperbolic sine of X. */
  90. __MATHCALL_VEC (sinh,, (_Mdouble_ __x));
  91. /* Hyperbolic tangent of X. */
  92. __MATHCALL_VEC (tanh,, (_Mdouble_ __x));
  93. #ifdef __USE_GNU
  94. /* Cosine and sine of X. */
  95. __MATHDECL_VEC (void,sincos,,
  96. (_Mdouble_ __x, _Mdouble_ *__sinx, _Mdouble_ *__cosx));
  97. #endif
  98. #if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
  99. /* Hyperbolic arc cosine of X. */
  100. __MATHCALL_VEC (acosh,, (_Mdouble_ __x));
  101. /* Hyperbolic arc sine of X. */
  102. __MATHCALL_VEC (asinh,, (_Mdouble_ __x));
  103. /* Hyperbolic arc tangent of X. */
  104. __MATHCALL_VEC (atanh,, (_Mdouble_ __x));
  105. #endif
  106. /* Exponential and logarithmic functions. */
  107. /* Exponential function of X. */
  108. __MATHCALL_VEC (exp,, (_Mdouble_ __x));
  109. /* Break VALUE into a normalized fraction and an integral power of 2. */
  110. __MATHCALL (frexp,, (_Mdouble_ __x, int *__exponent));
  111. /* X times (two to the EXP power). */
  112. __MATHCALL (ldexp,, (_Mdouble_ __x, int __exponent));
  113. /* Natural logarithm of X. */
  114. __MATHCALL_VEC (log,, (_Mdouble_ __x));
  115. /* Base-ten logarithm of X. */
  116. __MATHCALL_VEC (log10,, (_Mdouble_ __x));
  117. /* Break VALUE into integral and fractional parts. */
  118. __MATHCALL (modf,, (_Mdouble_ __x, _Mdouble_ *__iptr)) __nonnull ((2));
  119. #if __GLIBC_USE (IEC_60559_FUNCS_EXT_C23)
  120. /* Compute exponent to base ten. */
  121. __MATHCALL_VEC (exp10,, (_Mdouble_ __x));
  122. /* Return exp2(X) - 1. */
  123. __MATHCALL_VEC (exp2m1,, (_Mdouble_ __x));
  124. /* Return exp10(X) - 1. */
  125. __MATHCALL_VEC (exp10m1,, (_Mdouble_ __x));
  126. /* Return log2(1 + X). */
  127. __MATHCALL_VEC (log2p1,, (_Mdouble_ __x));
  128. /* Return log10(1 + X). */
  129. __MATHCALL_VEC (log10p1,, (_Mdouble_ __x));
  130. /* Return log(1 + X). */
  131. __MATHCALL_VEC (logp1,, (_Mdouble_ __x));
  132. #endif
  133. #if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
  134. /* Return exp(X) - 1. */
  135. __MATHCALL_VEC (expm1,, (_Mdouble_ __x));
  136. /* Return log(1 + X). */
  137. __MATHCALL_VEC (log1p,, (_Mdouble_ __x));
  138. /* Return the base 2 signed integral exponent of X. */
  139. __MATHCALL (logb,, (_Mdouble_ __x));
  140. #endif
  141. #ifdef __USE_ISOC99
  142. /* Compute base-2 exponential of X. */
  143. __MATHCALL_VEC (exp2,, (_Mdouble_ __x));
  144. /* Compute base-2 logarithm of X. */
  145. __MATHCALL_VEC (log2,, (_Mdouble_ __x));
  146. #endif
  147. /* Power functions. */
  148. /* Return X to the Y power. */
  149. __MATHCALL_VEC (pow,, (_Mdouble_ __x, _Mdouble_ __y));
  150. /* Return the square root of X. */
  151. __MATHCALL (sqrt,, (_Mdouble_ __x));
  152. #if defined __USE_XOPEN || defined __USE_ISOC99
  153. /* Return `sqrt(X*X + Y*Y)'. */
  154. __MATHCALL_VEC (hypot,, (_Mdouble_ __x, _Mdouble_ __y));
  155. #endif
  156. #if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
  157. /* Return the cube root of X. */
  158. __MATHCALL_VEC (cbrt,, (_Mdouble_ __x));
  159. #endif
  160. #if __GLIBC_USE (IEC_60559_FUNCS_EXT_C23)
  161. /* Return 1+X to the Y power. */
  162. __MATHCALL (compoundn,, (_Mdouble_ __x, long long int __y));
  163. /* Return X to the Y power. */
  164. __MATHCALL (pown,, (_Mdouble_ __x, long long int __y));
  165. /* Return X to the Y power. */
  166. __MATHCALL (powr,, (_Mdouble_ __x, _Mdouble_ __y));
  167. /* Return the Yth root of X. */
  168. __MATHCALL (rootn,, (_Mdouble_ __x, long long int __y));
  169. /* Return the reciprocal of the square root of X. */
  170. __MATHCALL_VEC (rsqrt,, (_Mdouble_ __x));
  171. #endif
  172. /* Nearest integer, absolute value, and remainder functions. */
  173. /* Smallest integral value not less than X. */
  174. __MATHCALLX (ceil,, (_Mdouble_ __x), (__const__));
  175. /* Absolute value of X. */
  176. __MATHCALLX (fabs,, (_Mdouble_ __x), (__const__));
  177. /* Largest integer not greater than X. */
  178. __MATHCALLX (floor,, (_Mdouble_ __x), (__const__));
  179. /* Floating-point modulo remainder of X/Y. */
  180. __MATHCALL (fmod,, (_Mdouble_ __x, _Mdouble_ __y));
  181. #ifdef __USE_MISC
  182. # if ((!defined __cplusplus \
  183. || __cplusplus < 201103L /* isinf conflicts with C++11. */ \
  184. || __MATH_DECLARING_DOUBLE == 0)) /* isinff or isinfl don't. */ \
  185. && !__MATH_DECLARING_FLOATN
  186. /* Return 0 if VALUE is finite or NaN, +1 if it
  187. is +Infinity, -1 if it is -Infinity. */
  188. __MATHDECL_ALIAS (int,isinf,, (_Mdouble_ __value), isinf)
  189. __attribute__ ((__const__));
  190. # endif
  191. # if !__MATH_DECLARING_FLOATN
  192. /* Return nonzero if VALUE is finite and not NaN. */
  193. __MATHDECL_ALIAS (int,finite,, (_Mdouble_ __value), finite)
  194. __attribute__ ((__const__));
  195. /* Return the remainder of X/Y. */
  196. __MATHCALL (drem,, (_Mdouble_ __x, _Mdouble_ __y));
  197. /* Return the fractional part of X after dividing out `ilogb (X)'. */
  198. __MATHCALL (significand,, (_Mdouble_ __x));
  199. # endif
  200. #endif /* Use misc. */
  201. #ifdef __USE_ISOC99
  202. /* Return X with its signed changed to Y's. */
  203. __MATHCALLX (copysign,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  204. #endif
  205. #ifdef __USE_ISOC99
  206. /* Return representation of qNaN for double type. */
  207. __MATHCALL (nan,, (const char *__tagb));
  208. #endif
  209. #if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
  210. # if ((!defined __cplusplus \
  211. || __cplusplus < 201103L /* isnan conflicts with C++11. */ \
  212. || __MATH_DECLARING_DOUBLE == 0)) /* isnanf or isnanl don't. */ \
  213. && !__MATH_DECLARING_FLOATN
  214. /* Return nonzero if VALUE is not a number. */
  215. __MATHDECL_ALIAS (int,isnan,, (_Mdouble_ __value), isnan)
  216. __attribute__ ((__const__));
  217. # endif
  218. #endif
  219. #if defined __USE_MISC || (defined __USE_XOPEN && __MATH_DECLARING_DOUBLE)
  220. /* Bessel functions. */
  221. __MATHCALL (j0,, (_Mdouble_));
  222. __MATHCALL (j1,, (_Mdouble_));
  223. __MATHCALL (jn,, (int, _Mdouble_));
  224. __MATHCALL (y0,, (_Mdouble_));
  225. __MATHCALL (y1,, (_Mdouble_));
  226. __MATHCALL (yn,, (int, _Mdouble_));
  227. #endif
  228. #if defined __USE_XOPEN || defined __USE_ISOC99
  229. /* Error and gamma functions. */
  230. __MATHCALL_VEC (erf,, (_Mdouble_));
  231. __MATHCALL_VEC (erfc,, (_Mdouble_));
  232. __MATHCALL (lgamma,, (_Mdouble_));
  233. #endif
  234. #ifdef __USE_ISOC99
  235. /* True gamma function. */
  236. __MATHCALL (tgamma,, (_Mdouble_));
  237. #endif
  238. #if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
  239. # if !__MATH_DECLARING_FLOATN
  240. /* Obsolete alias for `lgamma'. */
  241. __MATHCALL (gamma,, (_Mdouble_));
  242. # endif
  243. #endif
  244. #ifdef __USE_MISC
  245. /* Reentrant version of lgamma. This function uses the global variable
  246. `signgam'. The reentrant version instead takes a pointer and stores
  247. the value through it. */
  248. __MATHCALL (lgamma,_r, (_Mdouble_, int *__signgamp));
  249. #endif
  250. #if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
  251. /* Return the integer nearest X in the direction of the
  252. prevailing rounding mode. */
  253. __MATHCALL (rint,, (_Mdouble_ __x));
  254. /* Return X + epsilon if X < Y, X - epsilon if X > Y. */
  255. __MATHCALL (nextafter,, (_Mdouble_ __x, _Mdouble_ __y));
  256. # if defined __USE_ISOC99 && !defined __LDBL_COMPAT && !__MATH_DECLARING_FLOATN
  257. __MATHCALL (nexttoward,, (_Mdouble_ __x, long double __y));
  258. # endif
  259. # if __GLIBC_USE (IEC_60559_BFP_EXT_C23) || __MATH_DECLARING_FLOATN
  260. /* Return X - epsilon. */
  261. __MATHCALL (nextdown,, (_Mdouble_ __x));
  262. /* Return X + epsilon. */
  263. __MATHCALL (nextup,, (_Mdouble_ __x));
  264. # endif
  265. /* Return the remainder of integer division X / Y with infinite precision. */
  266. __MATHCALL (remainder,, (_Mdouble_ __x, _Mdouble_ __y));
  267. # ifdef __USE_ISOC99
  268. /* Return X times (2 to the Nth power). */
  269. __MATHCALL (scalbn,, (_Mdouble_ __x, int __n));
  270. # endif
  271. /* Return the binary exponent of X, which must be nonzero. */
  272. __MATHDECL (int,ilogb,, (_Mdouble_ __x));
  273. #endif
  274. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23) || __MATH_DECLARING_FLOATN
  275. /* Like ilogb, but returning long int. */
  276. __MATHDECL (long int, llogb,, (_Mdouble_ __x));
  277. #endif
  278. #ifdef __USE_ISOC99
  279. /* Return X times (2 to the Nth power). */
  280. __MATHCALL (scalbln,, (_Mdouble_ __x, long int __n));
  281. /* Round X to integral value in floating-point format using current
  282. rounding direction, but do not raise inexact exception. */
  283. __MATHCALL (nearbyint,, (_Mdouble_ __x));
  284. /* Round X to nearest integral value, rounding halfway cases away from
  285. zero. */
  286. __MATHCALLX (round,, (_Mdouble_ __x), (__const__));
  287. /* Round X to the integral value in floating-point format nearest but
  288. not larger in magnitude. */
  289. __MATHCALLX (trunc,, (_Mdouble_ __x), (__const__));
  290. /* Compute remainder of X and Y and put in *QUO a value with sign of x/y
  291. and magnitude congruent `mod 2^n' to the magnitude of the integral
  292. quotient x/y, with n >= 3. */
  293. __MATHCALL (remquo,, (_Mdouble_ __x, _Mdouble_ __y, int *__quo));
  294. /* Conversion functions. */
  295. /* Round X to nearest integral value according to current rounding
  296. direction. */
  297. __MATHDECL (long int,lrint,, (_Mdouble_ __x));
  298. __extension__
  299. __MATHDECL (long long int,llrint,, (_Mdouble_ __x));
  300. /* Round X to nearest integral value, rounding halfway cases away from
  301. zero. */
  302. __MATHDECL (long int,lround,, (_Mdouble_ __x));
  303. __extension__
  304. __MATHDECL (long long int,llround,, (_Mdouble_ __x));
  305. /* Return positive difference between X and Y. */
  306. __MATHCALL (fdim,, (_Mdouble_ __x, _Mdouble_ __y));
  307. # if !__MATH_DECLARING_FLOATN || defined __USE_GNU || !__GLIBC_USE (ISOC23)
  308. /* Return maximum numeric value from X and Y. */
  309. __MATHCALLX (fmax,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  310. /* Return minimum numeric value from X and Y. */
  311. __MATHCALLX (fmin,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  312. # endif
  313. /* Multiply-add function computed as a ternary operation. */
  314. __MATHCALL (fma,, (_Mdouble_ __x, _Mdouble_ __y, _Mdouble_ __z));
  315. #endif /* Use ISO C99. */
  316. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23) || __MATH_DECLARING_FLOATN
  317. /* Round X to nearest integer value, rounding halfway cases to even. */
  318. __MATHCALLX (roundeven,, (_Mdouble_ __x), (__const__));
  319. /* Round X to nearest signed integer value, not raising inexact, with
  320. control of rounding direction and width of result. */
  321. __MATHCALL (fromfp,, (_Mdouble_ __x, int __round, unsigned int __width));
  322. /* Round X to nearest unsigned integer value, not raising inexact,
  323. with control of rounding direction and width of result. */
  324. __MATHCALL (ufromfp,, (_Mdouble_ __x, int __round, unsigned int __width));
  325. /* Round X to nearest signed integer value, raising inexact for
  326. non-integers, with control of rounding direction and width of
  327. result. */
  328. __MATHCALL (fromfpx,, (_Mdouble_ __x, int __round, unsigned int __width));
  329. /* Round X to nearest unsigned integer value, raising inexact for
  330. non-integers, with control of rounding direction and width of
  331. result. */
  332. __MATHCALL (ufromfpx,, (_Mdouble_ __x, int __round, unsigned int __width));
  333. /* Canonicalize floating-point representation. */
  334. __MATHDECL_1 (int, canonicalize,, (_Mdouble_ *__cx, const _Mdouble_ *__x));
  335. #endif
  336. #if (__GLIBC_USE (IEC_60559_BFP_EXT) \
  337. || (__MATH_DECLARING_FLOATN \
  338. && (defined __USE_GNU || !__GLIBC_USE (ISOC23))))
  339. /* Return value with maximum magnitude. */
  340. __MATHCALLX (fmaxmag,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  341. /* Return value with minimum magnitude. */
  342. __MATHCALLX (fminmag,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  343. #endif
  344. #if __GLIBC_USE (ISOC23)
  345. /* Return maximum value from X and Y. */
  346. __MATHCALLX (fmaximum,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  347. /* Return minimum value from X and Y. */
  348. __MATHCALLX (fminimum,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  349. /* Return maximum numeric value from X and Y. */
  350. __MATHCALLX (fmaximum_num,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  351. /* Return minimum numeric value from X and Y. */
  352. __MATHCALLX (fminimum_num,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  353. /* Return value with maximum magnitude. */
  354. __MATHCALLX (fmaximum_mag,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  355. /* Return value with minimum magnitude. */
  356. __MATHCALLX (fminimum_mag,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  357. /* Return numeric value with maximum magnitude. */
  358. __MATHCALLX (fmaximum_mag_num,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  359. /* Return numeric value with minimum magnitude. */
  360. __MATHCALLX (fminimum_mag_num,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
  361. #endif
  362. #if __GLIBC_USE (IEC_60559_EXT) || __MATH_DECLARING_FLOATN
  363. /* Total order operation. */
  364. __MATHDECL_1 (int, totalorder,, (const _Mdouble_ *__x,
  365. const _Mdouble_ *__y))
  366. __attribute_pure__;
  367. /* Total order operation on absolute values. */
  368. __MATHDECL_1 (int, totalordermag,, (const _Mdouble_ *__x,
  369. const _Mdouble_ *__y))
  370. __attribute_pure__;
  371. /* Get NaN payload. */
  372. __MATHCALL (getpayload,, (const _Mdouble_ *__x));
  373. /* Set quiet NaN payload. */
  374. __MATHDECL_1 (int, setpayload,, (_Mdouble_ *__x, _Mdouble_ __payload));
  375. /* Set signaling NaN payload. */
  376. __MATHDECL_1 (int, setpayloadsig,, (_Mdouble_ *__x, _Mdouble_ __payload));
  377. #endif
  378. #if (defined __USE_MISC || (defined __USE_XOPEN_EXTENDED \
  379. && __MATH_DECLARING_DOUBLE \
  380. && !defined __USE_XOPEN2K8)) \
  381. && !__MATH_DECLARING_FLOATN
  382. /* Return X times (2 to the Nth power). */
  383. __MATHCALL (scalb,, (_Mdouble_ __x, _Mdouble_ __n));
  384. #endif