鱼C论坛

 找回密码
 立即注册
查看: 1971|回复: 4

math的头文件里面的一些代码和它表示的含义

[复制链接]
发表于 2022-11-15 23:34:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
math的头文件里面的一些代码和它表示的含义
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-11-16 00:35:11 | 显示全部楼层
本帖最后由 jackz007 于 2022-11-16 01:13 编辑

          math.h 存在的目的不止是为了定义一些数学运算相关的宏,函数声明等,更加重要的目的是为了让 C 语言编译器具有最为广泛的适应性和可移植性,是为了使 C 语言编译器能适合在一切硬件(PC、单片机、手机、航天飞机。。。)、一切操作系统(DOS、Android、Windows、Linux。。。)、一切编译器(GCC、VC。。。)环境下都能正常工作,所以,里面有非常多的条件宏定义,极其复杂的针对性编译逻辑等等,除非你准备自己写编译器,否则,只要是在常见的系统下写程序,那就无需关心这个文件,只要利用教材上的知识写程序就不会有问题。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-11-17 15:58:43 | 显示全部楼层
本帖最后由 zhangjinxuan 于 2022-11-17 16:02 编辑

math 内有很多便于数学的函数,常用于数学计算,比如 pow,  sqrt, abs 这些很常用

源码?真的要看?那好吧:
  1. /*
  2. * math.h
  3. *
  4. * ANSI/POSIX + Microsoft compatible mathematical function prototypes,
  5. * associated macros, and manifest constant definitions.
  6. *
  7. * $Id: math.h,v 1e905d042bda 2017/11/28 17:33:30 keith $
  8. *
  9. * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
  10. * Copyright (C) 1997-2009, 2014-2016, MinGW.org Project.
  11. *
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a
  14. * copy of this software and associated documentation files (the "Software"),
  15. * to deal in the Software without restriction, including without limitation
  16. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17. * and/or sell copies of the Software, and to permit persons to whom the
  18. * Software is furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice, this permission notice, and the following
  21. * disclaimer shall be included in all copies or substantial portions of
  22. * the Software.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  25. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  27. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  29. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
  30. * DEALINGS IN THE SOFTWARE.
  31. *
  32. */
  33. #ifndef _MATH_H
  34. #define _MATH_H
  35. #pragma GCC system_header

  36. /* All the headers include this file.
  37. */
  38. #include <_mingw.h>

  39. /* Types for the _exception structure.
  40. */
  41. #define _DOMAIN         1        /* domain error in argument */
  42. #define _SING                2        /* singularity */
  43. #define _OVERFLOW        3        /* range overflow */
  44. #define _UNDERFLOW        4        /* range underflow */
  45. #define _TLOSS                5        /* total loss of precision */
  46. #define _PLOSS                6        /* partial loss of precision */

  47. #if ! defined __STRICT_ANSI__ && ! defined _NO_OLDNAMES
  48. /*
  49. * Exception types with non-ANSI names for compatibility.
  50. */
  51. #define DOMAIN                _DOMAIN
  52. #define SING                _SING
  53. #define OVERFLOW        _OVERFLOW
  54. #define UNDERFLOW        _UNDERFLOW
  55. #define TLOSS                _TLOSS
  56. #define PLOSS                _PLOSS

  57. #endif        /* !__STRICT_ANSI__ && !_NO_OLDNAMES */


  58. #if _POSIX_C_SOURCE || defined _USE_MATH_DEFINES
  59. /* Traditional/XOPEN math constants (double precison).  MSVC makes these
  60. * available, only if _USE_MATH_DEFINES is specified; POSIX does so also,
  61. * when _POSIX_C_SOURCE is defined and non-zero, (as will be the case by
  62. * default in MinGW, unless __STRICT_ANSI__ checking is in effect).
  63. */
  64. #define M_E                2.7182818284590452354
  65. #define M_LOG2E         1.4426950408889634074
  66. #define M_LOG10E        0.43429448190325182765
  67. #define M_LN2                0.69314718055994530942
  68. #define M_LN10                2.30258509299404568402
  69. #define M_PI                3.14159265358979323846
  70. #define M_PI_2                1.57079632679489661923
  71. #define M_PI_4                0.78539816339744830962
  72. #define M_1_PI                0.31830988618379067154
  73. #define M_2_PI                0.63661977236758134308
  74. #define M_2_SQRTPI        1.12837916709551257390
  75. #define M_SQRT2         1.41421356237309504880
  76. #define M_SQRT1_2        0.70710678118654752440
  77. #endif

  78. /* These are also defined in MinGW float.h; needed here as well,
  79. * to work around GCC build issues.
  80. *
  81. * FIXME: Since they're needed both in MinGW float.h and here,
  82. * they should be moved to a common "parts" header.
  83. */
  84. #if ! defined __STRICT_ANSI__ && ! defined __MINGW_FPCLASS_DEFINED
  85. #define __MINGW_FPCLASS_DEFINED  1

  86. /* IEEE 754 classication
  87. */
  88. #define _FPCLASS_SNAN        0x0001        /* Signaling "Not a Number" */
  89. #define _FPCLASS_QNAN        0x0002        /* Quiet "Not a Number" */
  90. #define _FPCLASS_NINF        0x0004        /* Negative Infinity */
  91. #define _FPCLASS_NN        0x0008        /* Negative Normal */
  92. #define _FPCLASS_ND        0x0010        /* Negative Denormal */
  93. #define _FPCLASS_NZ        0x0020        /* Negative Zero */
  94. #define _FPCLASS_PZ        0x0040        /* Positive Zero */
  95. #define _FPCLASS_PD        0x0080        /* Positive Denormal */
  96. #define _FPCLASS_PN        0x0100        /* Positive Normal */
  97. #define _FPCLASS_PINF        0x0200        /* Positive Infinity */

  98. #endif        /* !__STRICT_ANSI__ && !__MINGW_FPCLASS_DEFINED */

  99. #ifndef RC_INVOKED

  100. _BEGIN_C_DECLS

  101. /* HUGE_VAL is returned by strtod when the value would overflow the
  102. * representation of 'double'. There are other uses as well.
  103. *
  104. * __imp__HUGE is a pointer to the actual variable _HUGE in
  105. * MSVCRT.DLL. If we used _HUGE directly we would get a pointer
  106. * to a thunk function.
  107. *
  108. * NOTE: The CRTDLL version uses _HUGE_dll instead.
  109. */
  110. #if __MINGW_GNUC_PREREQ(3, 3)
  111. #define HUGE_VAL __builtin_huge_val()

  112. #else
  113. #ifndef __DECLSPEC_SUPPORTED

  114. #ifdef __MSVCRT__
  115. extern double      *_imp___HUGE;
  116. #define HUGE_VAL  (*_imp___HUGE)

  117. #else /* CRTDLL */
  118. extern double      *_imp___HUGE_dll;
  119. #define HUGE_VAL  (*_imp___HUGE_dll)
  120. #endif

  121. #else /* __DECLSPEC_SUPPORTED */

  122. #ifdef __MSVCRT__
  123. __MINGW_IMPORT double        _HUGE;
  124. #define HUGE_VAL        _HUGE

  125. #else /* CRTDLL */
  126. __MINGW_IMPORT double        _HUGE_dll;
  127. #define HUGE_VAL        _HUGE_dll
  128. #endif

  129. #endif /* __DECLSPEC_SUPPORTED */
  130. #endif /* __MINGW_GNUC_PREREQ(3, 3) */

  131. struct _exception
  132. {
  133.   int     type;
  134.   char   *name;
  135.   double  arg1;
  136.   double  arg2;
  137.   double  retval;
  138. };

  139. _CRTIMP double __cdecl sin (double);
  140. _CRTIMP double __cdecl cos (double);
  141. _CRTIMP double __cdecl tan (double);
  142. _CRTIMP double __cdecl sinh (double);
  143. _CRTIMP double __cdecl cosh (double);
  144. _CRTIMP double __cdecl tanh (double);
  145. _CRTIMP double __cdecl asin (double);
  146. _CRTIMP double __cdecl acos (double);
  147. _CRTIMP double __cdecl atan (double);
  148. _CRTIMP double __cdecl atan2 (double, double);
  149. _CRTIMP double __cdecl exp (double);
  150. _CRTIMP double __cdecl log (double);
  151. _CRTIMP double __cdecl log10 (double);
  152. _CRTIMP        double __cdecl pow (double, double);
  153. _CRTIMP double __cdecl sqrt (double);
  154. _CRTIMP double __cdecl ceil (double);
  155. _CRTIMP double __cdecl floor (double);
  156. _CRTIMP double __cdecl fabs (double);
  157. _CRTIMP double __cdecl ldexp (double, int);
  158. _CRTIMP double __cdecl frexp (double, int*);
  159. _CRTIMP double __cdecl modf (double, double*);
  160. _CRTIMP double __cdecl fmod (double, double);

  161. #if 0
  162. /* Excess precision when using a 64-bit mantissa for FPU math ops can
  163. * cause unexpected results with some of the MSVCRT math functions.  For
  164. * example, unless the function return value is stored (truncating to
  165. * 53-bit mantissa), calls to pow with both x and y as integral values
  166. * sometimes produce a non-integral result.
  167. *
  168. * One workaround is to reset the FPU env to 53-bit mantissa
  169. * by a call to fesetenv (FE_PC53_ENV).  Amother is to force storage
  170. * of the return value of individual math functions using wrappers.
  171. * NB, using these wrappers will disable builtin math functions and
  172. * hence disable the folding of function results at compile time when
  173. * arguments are constant.
  174. */
  175. #define __DEFINE_FLOAT_STORE_MATHFN_D1(fn1)        \
  176. static __inline__ double                        \
  177. __float_store_ ## fn1 (double x)                \
  178. {                                                \
  179.    __volatile__ double res = (fn1) (x);         \
  180.   return res;                                        \
  181. }

  182. #define __DEFINE_FLOAT_STORE_MATHFN_D2(fn2)        \
  183. static __inline__ double                        \
  184. __float_store_ ## fn2 (double x, double y)        \
  185. {                                                \
  186.   __volatile__ double res = (fn2) (x, y);        \
  187.   return res;                                        \
  188. }

  189. /* For example, here is how to force the result of the pow function
  190. * to be stored:
  191. */
  192. #undef pow
  193. /* Define the ___float_store_pow function and use it instead of pow().
  194. */
  195. __DEFINE_FLOAT_STORE_MATHFN_D2 (pow)
  196. #define pow __float_store_pow
  197. #endif

  198. #ifndef __STRICT_ANSI__

  199. struct _complex
  200. { /* Complex number (for _cabs).  This is the MS version; the
  201.    * ISO-C99 counterpart, _Complex, is an intrinsic type in GCC,
  202.    * and 'complex' is defined as a macro.  See <complex.h>
  203.    */
  204.   double  x;        /* Real part */
  205.   double  y;        /* Imaginary part */
  206. };

  207. _CRTIMP double __cdecl _cabs (struct _complex);

  208. _CRTIMP double __cdecl _hypot (double, double);
  209. _CRTIMP double __cdecl _j0 (double);
  210. _CRTIMP double __cdecl _j1 (double);
  211. _CRTIMP double __cdecl _jn (int, double);
  212. _CRTIMP double __cdecl _y0 (double);
  213. _CRTIMP double __cdecl _y1 (double);
  214. _CRTIMP double __cdecl _yn (int, double);
  215. _CRTIMP int __cdecl _matherr (struct _exception *);

  216. /* These are also declared in MinGW's <float.h>; we need them
  217. * here as well to work around GCC build issues.
  218. */
  219. /* BEGIN FLOAT.H COPY */
  220. /*
  221. * IEEE recommended functions
  222. */
  223. _CRTIMP double __cdecl _chgsign (double);
  224. _CRTIMP double __cdecl _copysign (double, double);
  225. _CRTIMP double __cdecl _logb (double);
  226. _CRTIMP double __cdecl _nextafter (double, double);
  227. _CRTIMP double __cdecl _scalb (double, long);

  228. _CRTIMP int __cdecl _finite (double);
  229. _CRTIMP int __cdecl _fpclass (double);
  230. _CRTIMP int __cdecl _isnan (double);

  231. /* END FLOAT.H COPY */


  232. #ifndef _NO_OLDNAMES
  233. /* Non-underscored versions of non-ANSI functions.
  234. * These reside in liboldnames.a.
  235. */
  236. _CRTIMP double __cdecl j0 (double);
  237. _CRTIMP double __cdecl j1 (double);
  238. _CRTIMP double __cdecl jn (int, double);
  239. _CRTIMP double __cdecl y0 (double);
  240. _CRTIMP double __cdecl y1 (double);
  241. _CRTIMP double __cdecl yn (int, double);

  242. _CRTIMP double __cdecl chgsign (double);
  243. /*
  244. * scalb() is a GCC built-in.
  245. * Exclude this _scalb() stub; the semantics are incompatible
  246. * with the built-in implementation.
  247. *
  248. _CRTIMP double __cdecl scalb (double, long);
  249. *
  250. */
  251. _CRTIMP int __cdecl finite (double);
  252. _CRTIMP int __cdecl fpclass (double);

  253. #define FP_SNAN    _FPCLASS_SNAN
  254. #define FP_QNAN    _FPCLASS_QNAN
  255. #define FP_NINF    _FPCLASS_NINF
  256. #define FP_PINF    _FPCLASS_PINF
  257. #define FP_NDENORM _FPCLASS_ND
  258. #define FP_PDENORM _FPCLASS_PD
  259. #define FP_NZERO   _FPCLASS_NZ
  260. #define FP_PZERO   _FPCLASS_PZ
  261. #define FP_NNORM   _FPCLASS_NN
  262. #define FP_PNORM   _FPCLASS_PN

  263. #endif        /* !_NO_OLDNAMES */

  264. #if _WIN32_WINNT >= _WIN32_WINNT_WINXP || __MSVCRT_VERSION__ >= __MSVCR70_DLL
  265. /*
  266. * This requires WinXP, or MSVCR70.DLL, or later.
  267. */
  268. _CRTIMP int __cdecl _set_SSE2_enable (int);

  269. #endif        /* >= WINXP || >= __MSVCR70_DLL */
  270. #endif        /* !__STRICT_ANSI__ */

  271. #if defined __cplusplus || defined _ISOC99_SOURCE

  272. # if __MINGW_GNUC_PREREQ(3, 3)
  273. #  define HUGE_VALF                __builtin_huge_valf()
  274. #  define HUGE_VALL                __builtin_huge_vall()
  275. #  define INFINITY                __builtin_inf()
  276. #  define NAN                        __builtin_nan("")
  277. # else
  278.    extern const float                __INFF;
  279.    extern const long double        __INFL;
  280.    extern const double                __QNAN;

  281. #  define HUGE_VALF                __INFF
  282. #  define HUGE_VALL                __INFL
  283. #  define INFINITY                  HUGE_VALF
  284. #  define NAN                        __QNAN

  285. # endif /* __MINGW_GNUC_PREREQ(3, 3) */

  286. /* Use the compiler's internal definition for FLT_EVAL_METHOD, if one
  287. * is available, to establish appropriate float_t and double_t typedefs;
  288. * in the case of GCC, this is specified as __FLT_EVAL_METHOD__, which
  289. * is expected to be assigned standardized values of 0, 1, or 2, (or
  290. * exceptionally, a value of -1, representing indeterminacy).
  291. */
  292. #if ! defined __FLT_EVAL_METHOD__ || __valueless(__FLT_EVAL_METHOD__) \
  293. || (__FLT_EVAL_METHOD__ - 0) < 0 || (__FLT_EVAL_METHOD__ - 0) > 1
  294. /* __FLT_EVAL_METHOD__ has not been defined, or it is defined with no
  295.   * value, or with a value of -1 (or less), or a value of 2 or more; in
  296.   * the specific case of a value of 2, this represents an explicit choice
  297.   * of the IX387 FPU configuration, while in each of the other cases, we
  298.   * implicitly fall back to this same default configuration.
  299.   *
  300.   * NOTE: this configuration is correct for X87 FPU computations, (for
  301.   * which __FLT_EVAL_METHOD__ is correctly specified as 2); however...
  302.   */
  303. # if defined __FLT_EVAL_METHOD__ && (__FLT_EVAL_METHOD__ - 0) != 2
  304.   /* ...due to a GCC bug, introduced in GCC-6 and persisting into later
  305.    * versions, it may be selected via __FLT_EVAL_METHOD__ == -1, for the
  306.    * case of the "-msse -mfpmath=sse" option combination.  In this case,
  307.    * it is (at best) an unsatisfactory compromise; to avoid it, you may
  308.    * prefer to adopt "-mfpmath=387", or "-msse2 -mfpmath=sse" instead.
  309.    */
  310. #  warning "Default FLT_EVAL_METHOD is inderminate; assuming X87 semantics."
  311. # endif
  312.   typedef long double float_t;
  313.   typedef long double double_t;

  314. #else
  315. /* __FLT_EVAL_METHOD__ must have been defined with an explicit value
  316.   * of either 0 or 1; select the corresponding SSE configuration which
  317.   * is applicable in each case.
  318.   */
  319. # if __FLT_EVAL_METHOD__ == 0
  320.    typedef float float_t;
  321.    typedef double double_t;

  322. # else /*  __FLT_EVAL_METHOD__ == 1 */
  323.    typedef double float_t;
  324.    typedef double double_t;
  325. # endif
  326. #endif

  327. /* 7.12.3.1
  328. * Return values for fpclassify.
  329. * These are based on Intel x87 fpu condition codes
  330. * in the high byte of status word and differ from
  331. * the return values for MS IEEE 754 extension _fpclass()
  332. */
  333. #define FP_NAN                0x0100
  334. #define FP_NORMAL        0x0400
  335. #define FP_INFINITE        (FP_NAN | FP_NORMAL)
  336. #define FP_ZERO                0x4000
  337. #define FP_SUBNORMAL        (FP_NORMAL | FP_ZERO)
  338. /* 0x0200 is signbit mask */

  339. /* We can't inline float or double, because we want to ensure
  340. * truncation to semantic type before classification; (a normal
  341. * long double value might become subnormal when converted to
  342. * double, and zero when converted to float.)
  343. */
  344. extern int __cdecl __fpclassifyf (float);
  345. extern int __cdecl __fpclassify (double);
  346. extern int __cdecl __fpclassifyl (long double);

  347. #ifndef __NO_INLINE__
  348. __CRT_INLINE int __cdecl __fpclassifyl (long double x){
  349.   unsigned short sw;
  350.   __asm__ ("fxam; fstsw %%ax;" : "=a" (sw): "t" (x));
  351.   return sw & (FP_NAN | FP_NORMAL | FP_ZERO );
  352. }
  353. #endif

  354. #define fpclassify(x) (sizeof (x) == sizeof (float) ? __fpclassifyf (x)          \
  355.                        : sizeof (x) == sizeof (double) ? __fpclassify (x) \
  356.                        : __fpclassifyl (x))

  357. /* 7.12.3.2 */
  358. #define isfinite(x) ((fpclassify(x) & FP_NAN) == 0)

  359. /* 7.12.3.3 */
  360. #define isinf(x) (fpclassify(x) == FP_INFINITE)

  361. /* 7.12.3.4 */
  362. /* We don't need to worry about truncation here:
  363. * a NaN stays a NaN.
  364. */
  365. extern int __cdecl __isnan (double);
  366. extern int __cdecl __isnanf (float);
  367. extern int __cdecl __isnanl (long double);
  368. #ifndef __NO_INLINE__
  369. __CRT_INLINE int __cdecl __isnan (double _x)
  370. {
  371.   unsigned short sw;
  372.   __asm__ ("fxam;"
  373.            "fstsw %%ax": "=a" (sw) : "t" (_x));
  374.   return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
  375.     == FP_NAN;
  376. }

  377. __CRT_INLINE int __cdecl __isnanf (float _x)
  378. {
  379.   unsigned short sw;
  380.   __asm__ ("fxam;"
  381.             "fstsw %%ax": "=a" (sw) : "t" (_x));
  382.   return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
  383.     == FP_NAN;
  384. }

  385. __CRT_INLINE int __cdecl __isnanl (long double _x)
  386. {
  387.   unsigned short sw;
  388.   __asm__ ("fxam;"
  389.             "fstsw %%ax": "=a" (sw) : "t" (_x));
  390.   return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
  391.     == FP_NAN;
  392. }
  393. #endif

  394. #define isnan(x) (sizeof (x) == sizeof (float) ? __isnanf (x)        \
  395.                   : sizeof (x) == sizeof (double) ? __isnan (x)        \
  396.                   : __isnanl (x))

  397. /* 7.12.3.5 */
  398. #define isnormal(x) (fpclassify(x) == FP_NORMAL)

  399. /* 7.12.3.6 The signbit macro */
  400. extern int __cdecl __signbit (double);
  401. extern int __cdecl __signbitf (float);
  402. extern int __cdecl __signbitl (long double);
  403. #ifndef __NO_INLINE__
  404. __CRT_INLINE int __cdecl __signbit (double x) {
  405.   unsigned short stw;
  406.   __asm__ ( "fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
  407.   return (stw & 0x0200) != 0;
  408. }

  409. __CRT_INLINE int __cdecl __signbitf (float x) {
  410.   unsigned short stw;
  411.   __asm__ ("fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
  412.   return (stw & 0x0200) != 0;
  413. }

  414. __CRT_INLINE int __cdecl __signbitl (long double x) {
  415.   unsigned short stw;
  416.   __asm__ ("fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
  417.   return (stw & 0x0200) != 0;
  418. }
  419. #endif

  420. #define signbit(x) (sizeof (x) == sizeof (float) ? __signbitf (x)        \
  421.                     : sizeof (x) == sizeof (double) ? __signbit (x)        \
  422.                     : __signbitl (x))

  423. /* 7.12.4 Trigonometric functions: double in C89
  424. */
  425. extern float __cdecl sinf (float);
  426. extern long double __cdecl sinl (long double);

  427. extern float __cdecl cosf (float);
  428. extern long double __cdecl cosl (long double);

  429. extern float __cdecl tanf (float);
  430. extern long double __cdecl tanl (long double);

  431. extern float __cdecl asinf (float);
  432. extern long double __cdecl asinl (long double);

  433. extern float __cdecl acosf (float);
  434. extern long double __cdecl acosl (long double);

  435. extern float __cdecl atanf (float);
  436. extern long double __cdecl atanl (long double);

  437. extern float __cdecl atan2f (float, float);
  438. extern long double __cdecl atan2l (long double, long double);

  439. /* 7.12.5 Hyperbolic functions: double in C89
  440. */
  441. extern float __cdecl sinhf (float);
  442. #ifndef __NO_INLINE__
  443. __CRT_INLINE float __cdecl sinhf (float x)
  444.   {return (float) sinh (x);}
  445. #endif
  446. extern long double __cdecl sinhl (long double);

  447. extern float __cdecl coshf (float);
  448. #ifndef __NO_INLINE__
  449. __CRT_INLINE float __cdecl coshf (float x)
  450.   {return (float) cosh (x);}
  451. #endif
  452. extern long double __cdecl coshl (long double);

  453. extern float __cdecl tanhf (float);
  454. #ifndef __NO_INLINE__
  455. __CRT_INLINE float __cdecl tanhf (float x)
  456.   {return (float) tanh (x);}
  457. #endif
  458. extern long double __cdecl tanhl (long double);

  459. /* Inverse hyperbolic trig functions  */
  460. /* 7.12.5.1 */
  461. extern double __cdecl acosh (double);
  462. extern float __cdecl acoshf (float);
  463. extern long double __cdecl acoshl (long double);

  464. /* 7.12.5.2 */
  465. extern double __cdecl asinh (double);
  466. extern float __cdecl asinhf (float);
  467. extern long double __cdecl asinhl (long double);

  468. /* 7.12.5.3 */
  469. extern double __cdecl atanh (double);
  470. extern float __cdecl atanhf  (float);
  471. extern long double __cdecl atanhl (long double);

  472. /* Exponentials and logarithms  */
  473. /* 7.12.6.1 Double in C89 */
  474. extern float __cdecl expf (float);
  475. #ifndef __NO_INLINE__
  476. __CRT_INLINE float __cdecl expf (float x)
  477.   {return (float) exp (x);}
  478. #endif
  479. extern long double __cdecl expl (long double);

  480. /* 7.12.6.2 */
  481. extern double __cdecl exp2(double);
  482. extern float __cdecl exp2f(float);
  483. extern long double __cdecl exp2l(long double);

  484. /* 7.12.6.3 The expm1 functions */
  485. /* TODO: These could be inlined */
  486. extern double __cdecl expm1(double);
  487. extern float __cdecl expm1f(float);
  488. extern long double __cdecl expm1l(long double);

  489. /* 7.12.6.4 Double in C89 */
  490. extern float __cdecl frexpf (float, int*);
  491. #ifndef __NO_INLINE__
  492. __CRT_INLINE float __cdecl frexpf (float x, int* expn)
  493.   {return (float) frexp (x, expn);}
  494. #endif
  495. extern long double __cdecl frexpl (long double, int*);

  496. /* 7.12.6.5 */
  497. #define FP_ILOGB0 ((int)0x80000000)
  498. #define FP_ILOGBNAN ((int)0x80000000)
  499. extern int __cdecl ilogb (double);
  500. extern int __cdecl ilogbf (float);
  501. extern int __cdecl ilogbl (long double);

  502. /* 7.12.6.6  Double in C89 */
  503. extern float __cdecl ldexpf (float, int);
  504. #ifndef __NO_INLINE__
  505. __CRT_INLINE float __cdecl ldexpf (float x, int expn)
  506.   {return (float) ldexp (x, expn);}
  507. #endif
  508. extern long double __cdecl ldexpl (long double, int);

  509. /* 7.12.6.7 Double in C89 */
  510. extern float __cdecl logf (float);
  511. extern long double __cdecl logl (long double);

  512. /* 7.12.6.8 Double in C89 */
  513. extern float __cdecl log10f (float);
  514. extern long double __cdecl log10l (long double);

  515. /* 7.12.6.9 */
  516. extern double __cdecl log1p(double);
  517. extern float __cdecl log1pf(float);
  518. extern long double __cdecl log1pl(long double);

  519. /* 7.12.6.10 */
  520. extern double __cdecl log2 (double);
  521. extern float __cdecl log2f (float);
  522. extern long double __cdecl log2l (long double);

  523. /* 7.12.6.11 */
  524. extern double __cdecl logb (double);
  525. extern float __cdecl logbf (float);
  526. extern long double __cdecl logbl (long double);

  527. /* Inline versions.  GCC-4.0+ can do a better fast-math optimization
  528. * with __builtins.
  529. */
  530. #ifndef __NO_INLINE__
  531. #if !(__MINGW_GNUC_PREREQ (4, 0) && defined __FAST_MATH__ )
  532. __CRT_INLINE double __cdecl logb (double x)
  533. {
  534.   double res;
  535.   __asm__ ("fxtract\n\t"
  536.        "fstp        %%st" : "=t" (res) : "0" (x));
  537.   return res;
  538. }

  539. __CRT_INLINE float __cdecl logbf (float x)
  540. {
  541.   float res;
  542.   __asm__ ("fxtract\n\t"
  543.        "fstp        %%st" : "=t" (res) : "0" (x));
  544.   return res;
  545. }

  546. __CRT_INLINE long double __cdecl logbl (long double x)
  547. {
  548.   long double res;
  549.   __asm__ ("fxtract\n\t"
  550.        "fstp        %%st" : "=t" (res) : "0" (x));
  551.   return res;
  552. }
  553. #endif /* !__FAST_MATH__ || !__MINGW_GNUC_PREREQ (4, 0) */
  554. #endif /* !__NO_INLINE__ */

  555. /* 7.12.6.12  Double in C89 */
  556. extern float __cdecl modff (float, float*);
  557. extern long double __cdecl modfl (long double, long double*);

  558. /* 7.12.6.13 */
  559. extern double __cdecl scalbn (double, int);
  560. extern float __cdecl scalbnf (float, int);
  561. extern long double __cdecl scalbnl (long double, int);

  562. extern double __cdecl scalbln (double, long);
  563. extern float __cdecl scalblnf (float, long);
  564. extern long double __cdecl scalblnl (long double, long);

  565. /* 7.12.7.1 */
  566. /* Implementations adapted from Cephes versions */
  567. extern double __cdecl cbrt (double);
  568. extern float __cdecl cbrtf (float);
  569. extern long double __cdecl cbrtl (long double);

  570. /* 7.12.7.2 The fabs functions: Double in C89 */
  571. extern  float __cdecl fabsf (float x);
  572. extern long double __cdecl fabsl (long double x);

  573. /* 7.12.7.3  */
  574. extern double __cdecl hypot (double, double); /* in libmoldname.a */
  575. extern float __cdecl hypotf (float, float);
  576. extern long double __cdecl hypotl (long double, long double);

  577. /* 7.12.7.4 The pow functions. Double in C89 */
  578. extern float __cdecl powf (float, float);
  579. extern long double __cdecl powl (long double, long double);

  580. /* 7.12.7.5 The sqrt functions. Double in C89. */
  581. extern float __cdecl sqrtf (float);
  582. extern long double __cdecl sqrtl (long double);

  583. /* 7.12.8.1 The erf functions  */
  584. extern double __cdecl erf (double);
  585. extern float __cdecl erff (float);
  586. extern long double __cdecl erfl (long double);

  587. /* 7.12.8.2 The erfc functions  */
  588. extern double __cdecl erfc (double);
  589. extern float __cdecl erfcf (float);
  590. extern long double __cdecl erfcl (long double);

  591. /* 7.12.8.3 The lgamma functions */
  592. extern double __cdecl lgamma (double);
  593. extern float __cdecl lgammaf (float);
  594. extern long double __cdecl lgammal (long double);

  595. /* 7.12.8.4 The tgamma functions */
  596. extern double __cdecl tgamma (double);
  597. extern float __cdecl tgammaf (float);
  598. extern long double __cdecl tgammal (long double);

  599. /* 7.12.9.1 Double in C89 */
  600. extern float __cdecl ceilf (float);
  601. extern long double __cdecl ceill (long double);

  602. /* 7.12.9.2 Double in C89 */
  603. extern float __cdecl floorf (float);
  604. extern long double __cdecl floorl (long double);

  605. /* 7.12.9.3 */
  606. extern double __cdecl nearbyint ( double);
  607. extern float __cdecl nearbyintf (float);
  608. extern long double __cdecl nearbyintl (long double);

  609. /* 7.12.9.4 */
  610. /* round, using fpu control word settings */
  611. extern double __cdecl rint (double);
  612. extern float __cdecl rintf (float);
  613. extern long double __cdecl rintl (long double);

  614. /* 7.12.9.5 */
  615. extern long __cdecl lrint (double);
  616. extern long __cdecl lrintf (float);
  617. extern long __cdecl lrintl (long double);

  618. extern long long __cdecl llrint (double);
  619. extern long long __cdecl llrintf (float);
  620. extern long long __cdecl llrintl (long double);

  621. /* Inline versions of above.
  622. * GCC 4.0+ can do a better fast-math job with __builtins.
  623. */
  624. #ifndef __NO_INLINE__
  625. #if !(__MINGW_GNUC_PREREQ (4, 0) && defined __FAST_MATH__ )
  626. __CRT_INLINE double __cdecl rint (double x)
  627. {
  628.   double retval;
  629.   __asm__ ("frndint;": "=t" (retval) : "0" (x));
  630.   return retval;
  631. }

  632. __CRT_INLINE float __cdecl rintf (float x)
  633. {
  634.   float retval;
  635.   __asm__ ("frndint;" : "=t" (retval) : "0" (x) );
  636.   return retval;
  637. }

  638. __CRT_INLINE long double __cdecl rintl (long double x)
  639. {
  640.   long double retval;
  641.   __asm__ ("frndint;" : "=t" (retval) : "0" (x) );
  642.   return retval;
  643. }

  644. __CRT_INLINE long __cdecl lrint (double x)
  645. {
  646.   long retval;
  647.   __asm__ __volatile__
  648.     ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
  649.   return retval;
  650. }

  651. __CRT_INLINE long __cdecl lrintf (float x)
  652. {
  653.   long retval;
  654.   __asm__ __volatile__
  655.     ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
  656.   return retval;
  657. }

  658. __CRT_INLINE long __cdecl lrintl (long double x)
  659. {
  660.   long retval;
  661.   __asm__ __volatile__
  662.     ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
  663.   return retval;
  664. }

  665. __CRT_INLINE long long __cdecl llrint (double x)
  666. {
  667.   long long retval;
  668.   __asm__ __volatile__
  669.     ("fistpll %0"  : "=m" (retval) : "t" (x) : "st");
  670.   return retval;
  671. }

  672. __CRT_INLINE long long __cdecl llrintf (float x)
  673. {
  674.   long long retval;
  675.   __asm__ __volatile__
  676.     ("fistpll %0"  : "=m" (retval) : "t" (x) : "st");
  677.   return retval;
  678. }

  679. __CRT_INLINE long long __cdecl llrintl (long double x)
  680. {
  681.   long long retval;
  682.   __asm__ __volatile__
  683.     ("fistpll %0"  : "=m" (retval) : "t" (x) : "st");
  684.   return retval;
  685. }
  686. #endif        /* !__FAST_MATH__ || !__MINGW_GNUC_PREREQ (4,0) */
  687. #endif        /* !__NO_INLINE__ */

  688. /* 7.12.9.6 */
  689. /* round away from zero, regardless of fpu control word settings */
  690. extern double __cdecl round (double);
  691. extern float __cdecl roundf (float);
  692. extern long double __cdecl roundl (long double);

  693. /* 7.12.9.7  */
  694. extern long __cdecl lround (double);
  695. extern long __cdecl lroundf (float);
  696. extern long __cdecl lroundl (long double);

  697. extern long long __cdecl llround (double);
  698. extern long long __cdecl llroundf (float);
  699. extern long long __cdecl llroundl (long double);

  700. /* 7.12.9.8 */
  701. /* round towards zero, regardless of fpu control word settings */
  702. extern double __cdecl trunc (double);
  703. extern float __cdecl truncf (float);
  704. extern long double __cdecl truncl (long double);

  705. /* 7.12.10.1 Double in C89 */
  706. extern float __cdecl fmodf (float, float);
  707. extern long double __cdecl fmodl (long double, long double);

  708. /* 7.12.10.2 */
  709. extern double __cdecl remainder (double, double);
  710. extern float __cdecl remainderf (float, float);
  711. extern long double __cdecl remainderl (long double, long double);

  712. /* 7.12.10.3 */
  713. extern double __cdecl remquo(double, double, int *);
  714. extern float __cdecl remquof(float, float, int *);
  715. extern long double __cdecl remquol(long double, long double, int *);

  716. /* 7.12.11.1 */
  717. extern double __cdecl copysign (double, double); /* in libmoldname.a */
  718. extern float __cdecl copysignf (float, float);
  719. extern long double __cdecl copysignl (long double, long double);

  720. /* 7.12.11.2 Return a NaN */
  721. extern double __cdecl nan(const char *tagp);
  722. extern float __cdecl nanf(const char *tagp);
  723. extern long double __cdecl nanl(const char *tagp);

  724. #ifndef __STRICT_ANSI__
  725. #define _nan()   nan("")
  726. #define _nanf()  nanf("")
  727. #define _nanl()  nanl("")
  728. #endif

  729. /* 7.12.11.3 */
  730. extern double __cdecl nextafter (double, double); /* in libmoldname.a */
  731. extern float __cdecl nextafterf (float, float);
  732. extern long double __cdecl nextafterl (long double, long double);

  733. /* 7.12.11.4 The nexttoward functions */
  734. extern double __cdecl nexttoward (double,  long double);
  735. extern float __cdecl nexttowardf (float,  long double);
  736. extern long double __cdecl nexttowardl (long double, long double);

  737. /* 7.12.12.1 */
  738. /*  x > y ? (x - y) : 0.0  */
  739. extern double __cdecl fdim (double x, double y);
  740. extern float __cdecl fdimf (float x, float y);
  741. extern long double __cdecl fdiml (long double x, long double y);

  742. /* fmax and fmin.
  743.    NaN arguments are treated as missing data: if one argument is a NaN
  744.    and the other numeric, then these functions choose the numeric
  745.    value. */

  746. /* 7.12.12.2 */
  747. extern double __cdecl fmax  (double, double);
  748. extern float __cdecl fmaxf (float, float);
  749. extern long double __cdecl fmaxl (long double, long double);

  750. /* 7.12.12.3 */
  751. extern double __cdecl fmin (double, double);
  752. extern float __cdecl fminf (float, float);
  753. extern long double __cdecl fminl (long double, long double);

  754. /* 7.12.13.1 */
  755. /* return x * y + z as a ternary op */
  756. extern double __cdecl fma (double, double, double);
  757. extern float __cdecl fmaf (float, float, float);
  758. extern long double __cdecl fmal (long double, long double, long double);


  759. /* 7.12.14
  760. * With these functions, comparisons involving quiet NaNs set the FP
  761. * condition code to "unordered".  The IEEE floating-point spec
  762. * dictates that the result of floating-point comparisons should be
  763. * false whenever a NaN is involved, with the exception of the != op,
  764. * which always returns true: yes, (NaN != NaN) is true).
  765. */
  766. #if __GNUC__ >= 3

  767. #define isgreater(x, y) __builtin_isgreater(x, y)
  768. #define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
  769. #define isless(x, y) __builtin_isless(x, y)
  770. #define islessequal(x, y) __builtin_islessequal(x, y)
  771. #define islessgreater(x, y) __builtin_islessgreater(x, y)
  772. #define isunordered(x, y) __builtin_isunordered(x, y)

  773. #else        /* __GNUC__ < 3 */
  774. /*  helper  */
  775. extern int  __cdecl __fp_unordered_compare (long double, long double);
  776. #ifndef __NO_INLINE__
  777. __CRT_INLINE int  __cdecl
  778. __fp_unordered_compare (long double x, long double y){
  779.   unsigned short retval;
  780.   __asm__ ("fucom %%st(1);"
  781.            "fnstsw;": "=a" (retval) : "t" (x), "u" (y));
  782.   return retval;
  783. }
  784. #endif        /* !__NO_INLINE__ */

  785. #define isgreater(x, y)       ((__fp_unordered_compare(x, y) & 0x4500) == 0)
  786. #define isless(x, y)          ((__fp_unordered_compare(y, x) & 0x4500) == 0)
  787. #define isgreaterequal(x, y)  ((__fp_unordered_compare(x, y) & FP_INFINITE) == 0)
  788. #define islessequal(x, y)     ((__fp_unordered_compare(y, x) & FP_INFINITE) == 0)
  789. #define islessgreater(x, y)   ((__fp_unordered_compare(x, y) & FP_SUBNORMAL) == 0)
  790. #define isunordered(x, y)     ((__fp_unordered_compare(x, y) & 0x4500) == 0x4500)

  791. #endif        /* __GNUC__ < 3 */
  792. #endif        /* __cplusplus || _ISOC99_SOURCE */

  793. _END_C_DECLS

  794. #endif        /* ! RC_INVOKED */
  795. #endif        /* !_MATH_H: $RCSfile: math.h,v $: end of file */
复制代码


还有啊,它的含义我怎么知道?我又不是这个编译器的开发人员,含义这个问题真的很难,我无法解答,这种代码估计只有大学生才能看懂吧,不过你就可能是大学生,啊这……我小学。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-11-17 15:59:36 | 显示全部楼层
zhangjinxuan 发表于 2022-11-17 15:58
math 内有很多便于数学的函数,常用于数学计算,比如 pow,  sqrt, abs 这些很常用

源码?真的要看?那好 ...

这个是我Windows10 Dev-c++ 的math库源码,可能会与你用的 Unix 有所差异,仅供参考
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-11-18 08:58:32 | 显示全部楼层
楼主在吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-29 00:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表