⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 builtin-math-3.c

📁 用于进行gcc测试
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2006  Free Software Foundation.   Verify that built-in math function constant folding of constant   arguments is correctly performed by the compiler.   Origin: Kaveh R. Ghazi,  October 23, 2006.  *//* { dg-do link } *//* Define "e" with as many bits as found in builtins.c:dconste.  */#define M_E  2.7182818284590452353602874713526624977572470936999595749669676277241/* All references to link_error should go away at compile-time.  */extern void link_error(int);/* Return TRUE if the sign of X != sign of Y.  This is important when   comparing signed zeros.  */#define CKSGN_F(X,Y) \  (__builtin_copysignf(1.0F,(X)) != __builtin_copysignf(1.0F,(Y)))#define CKSGN(X,Y) \  (__builtin_copysign(1.0,(X)) != __builtin_copysign(1.0,(Y)))#define CKSGN_L(X,Y) \  (__builtin_copysignl(1.0L,(X)) != __builtin_copysignl(1.0L,(Y)))/* Test that FUNC(ARG) == (RES).  */#define TESTIT(FUNC,ARG,RES) do { \  if (__builtin_##FUNC##f(ARG##F) != RES##F \      || CKSGN_F(__builtin_##FUNC##f(ARG##F),RES##F)) \    link_error(__LINE__); \  if (__builtin_##FUNC(ARG) != RES \      || CKSGN(__builtin_##FUNC(ARG),RES)) \    link_error(__LINE__); \  if (__builtin_##FUNC##l(ARG##L) != RES##L \      || CKSGN_L(__builtin_##FUNC##l(ARG##L),RES##L)) \    link_error(__LINE__); \  } while (0)/* Range test, check that (LOW) < FUNC(ARG) < (HI).  */#define TESTIT_R(FUNC,ARG,LOW,HI) do { \  if (__builtin_##FUNC##f(ARG) <= (LOW) || __builtin_##FUNC##f(ARG) >= (HI)) \    link_error(__LINE__); \  if (__builtin_##FUNC(ARG) <= (LOW) || __builtin_##FUNC(ARG) >= (HI)) \    link_error(__LINE__); \  if (__builtin_##FUNC##l(ARG) <= (LOW) || __builtin_##FUNC##l(ARG) >= (HI)) \    link_error(__LINE__); \  } while (0)/* Test that FUNC(ARG1, ARG2) == (RES).  */#define TESTIT2(FUNC,ARG1,ARG2,RES) do { \  if (__builtin_##FUNC##f(ARG1##F, ARG2##F) != RES##F \      || CKSGN_F(__builtin_##FUNC##f(ARG1##F,ARG2##F),RES##F)) \    link_error(__LINE__); \  if (__builtin_##FUNC(ARG1, ARG2) != RES \      || CKSGN(__builtin_##FUNC(ARG1,ARG2),RES)) \    link_error(__LINE__); \  if (__builtin_##FUNC##l(ARG1##L, ARG2##L) != RES##L \      || CKSGN_L(__builtin_##FUNC##l(ARG1##L,ARG2##L),RES##L)) \    link_error(__LINE__); \  } while (0)/* Range test, check that (LOW) < FUNC(ARG1,ARG2) < (HI).  */#define TESTIT2_R(FUNC,ARG1,ARG2,LOW,HI) do { \  if (__builtin_##FUNC##f(ARG1, ARG2) <= (LOW) \      || __builtin_##FUNC##f(ARG1, ARG2) >= (HI)) \    link_error(__LINE__); \  if (__builtin_##FUNC(ARG1, ARG2) <= (LOW) \      || __builtin_##FUNC(ARG1, ARG2) >= (HI)) \    link_error(__LINE__); \  if (__builtin_##FUNC##l(ARG1, ARG2) <= (LOW) \      || __builtin_##FUNC##l(ARG1, ARG2) >= (HI)) \    link_error(__LINE__); \  } while (0)/* Test that FUNC(ARG1, ARG2, ARG3) == (RES).  */#define TESTIT3(FUNC,ARG1,ARG2,ARG3,RES) do { \  if (__builtin_##FUNC##f(ARG1##F, ARG2##F, ARG3##F) != RES##F \      || CKSGN_F(__builtin_##FUNC##f(ARG1##F,ARG2##F,ARG3##F),RES##F)) \    link_error(__LINE__); \  if (__builtin_##FUNC(ARG1, ARG2, ARG3) != RES \      || CKSGN(__builtin_##FUNC(ARG1,ARG2,ARG3),RES)) \    link_error(__LINE__); \  if (__builtin_##FUNC##l(ARG1##L, ARG2##L, ARG3##L) != RES##L \      || CKSGN_L(__builtin_##FUNC##l(ARG1##L,ARG2##L,ARG3##L),RES##L)) \    link_error(__LINE__); \  } while (0)/* Test that for FUNC(ARG, &ARG_S, &ARG_C);   assert (ARG_S == RES_S && ARG_C == RES_C);.  */#define TESTIT_2P(FUNC,ARG,ARG_S,ARG_C,RES_S,RES_C) do { \  __builtin_##FUNC##f(ARG##F, &ARG_S##f, &ARG_C##f); \  if (ARG_S##f != (RES_S##F) || ARG_C##f != (RES_C##F)) \    link_error(__LINE__); \  __builtin_##FUNC(ARG, &ARG_S, &ARG_C); \  if (ARG_S != (RES_S) || ARG_C != (RES_C)) \    link_error(__LINE__); \  __builtin_##FUNC##l(ARG##L, &ARG_S##l, &ARG_C##l); \  if (ARG_S##l != (RES_S##L) || ARG_C##l != (RES_C##L)) \    link_error(__LINE__); \  } while (0)/* Test that for FUNC(ARG, &ARG_S, &ARG_C);   assert (LOW_S < ARG_S < HI_S && LOW_C < ARG_C < HI_C);.  */#define TESTIT_2P_R(FUNC,ARG,ARG_S,ARG_C,LOW_S,HI_S,LOW_C,HI_C) do { \  __builtin_##FUNC##f(ARG##F, &ARG_S##f, &ARG_C##f); \  if (ARG_S##f <= (LOW_S##F) || ARG_S##f >= (HI_S##F) \      || ARG_C##f <= (LOW_C##F) || ARG_C##f >= (HI_C##F)) \    link_error(__LINE__); \  __builtin_##FUNC(ARG, &ARG_S, &ARG_C); \  if (ARG_S <= (LOW_S) || ARG_S >= (HI_S) \      || ARG_C <= (LOW_C) || ARG_C >= (HI_C)) \    link_error(__LINE__); \  __builtin_##FUNC##l(ARG##L, &ARG_S##l, &ARG_C##l); \  if (ARG_S##l <= (LOW_S##L) || ARG_S##l >= (HI_S##L) \      || ARG_C##l <= (LOW_C##L) || ARG_C##l >= (HI_C##L)) \    link_error(__LINE__); \  } while (0)int main (void){#ifdef __OPTIMIZE__  float sf, cf, oneF = 1.0F;  double s, c, one = 1.0;  long double sl, cl, oneL = 1.0L;#endif  TESTIT_R (asin, -1.0, -3.15/2.0, -3.14/2.0); /* asin(-1) == -pi/2 */  TESTIT (asin, 0.0, 0.0); /* asin(0) == 0 */  TESTIT (asin, -0.0, -0.0); /* asin(-0) == -0 */  TESTIT_R (asin, 1.0, 3.14/2.0, 3.15/2.0); /* asin(1) == pi/2 */  TESTIT_R (acos, -1.0, 3.14, 3.15); /* acos(-1) == pi */  TESTIT_R (acos, 0.0, 3.14/2.0, 3.15/2.0); /* acos(0) == pi/2 */  TESTIT_R (acos, -0.0, 3.14/2.0, 3.15/2.0); /* acos(-0) == pi/2 */  TESTIT (acos, 1.0, 0.0); /* acos(1) == 0 */  TESTIT_R (atan, -1.0, -3.15/4.0, -3.14/4.0); /* atan(-1) == -pi/4 */  TESTIT (atan, 0.0, 0.0); /* atan(0) == 0 */  TESTIT (atan, -0.0, -0.0); /* atan(-0) == -0 */  TESTIT_R (atan, 1.0, 3.14/4.0, 3.15/4.0); /* atan(1) == pi/4 */  TESTIT_R (asinh, -1.0, -0.89, -0.88); /* asinh(-1) == -0.881... */  TESTIT (asinh, 0.0, 0.0); /* asinh(0) == 0 */  TESTIT (asinh, -0.0, -0.0); /* asinh(-0) == -0 */  TESTIT_R (asinh, 1.0, 0.88, 0.89); /* asinh(1) == 0.881... */  TESTIT (acosh, 1.0, 0.0); /* acosh(1) == 0. */  TESTIT_R (acosh, 2.0, 1.31, 1.32); /* acosh(2) == 1.316... */  TESTIT_R (atanh, -0.5, -0.55, -0.54); /* atanh(-0.5) == -0.549... */  TESTIT (atanh, 0.0, 0.0); /* atanh(0) == 0 */  TESTIT (atanh, -0.0, -0.0); /* atanh(-0) == -0 */  TESTIT_R (atanh, 0.5, 0.54, 0.55); /* atanh(0.5) == 0.549... */  TESTIT_R (sin, -1.0, -0.85, -0.84); /* sin(-1) == -0.841... */  TESTIT (sin, 0.0, 0.0); /* sin(0) == 0 */  TESTIT (sin, -0.0, -0.0); /* sin(-0) == -0 */  TESTIT_R (sin, 1.0, 0.84, 0.85); /* sin(1) == 0.841... */  TESTIT_R (cos, -1.0, 0.54, 0.55); /* cos(-1) == 0.5403... */  TESTIT (cos, 0.0, 1.0); /* cos(0) == 1 */  TESTIT (cos, -0.0, 1.0); /* cos(-0) == 1 */  TESTIT_R (cos, 1.0, 0.54, 0.55); /* cos(1) == 0.5403... */  TESTIT_R (tan, -1.0, -1.56, 1.55); /* tan(-1) == -1.557... */  TESTIT (tan, 0.0, 0.0); /* tan(0) == 0 */  TESTIT (tan, -0.0, -0.0); /* tan(-0) == -0 */  TESTIT_R (tan, 1.0, 1.55, 1.56); /* tan(1) == 1.557... */#ifdef __OPTIMIZE__  /* These tests rely on propagating the variables s, c and one, which     happens only when optimization is turned on.  */  TESTIT_2P_R (sincos, -1.0, s, c, -0.85, -0.84, 0.54, 0.55); /* (s==-0.841..., c==0.5403...) */  TESTIT_2P (sincos, 0.0, s, c, 0.0, 1.0); /* (s==0, c==1) */  TESTIT_2P (sincos, -0.0, s, c, -0.0, 1.0); /* (s==-0, c==1) */  TESTIT_2P_R (sincos, 1.0, s, c, 0.84, 0.85, 0.54, 0.55); /* (s==0.841..., c==0.5403...) */  TESTIT_2P_R (sincos, one, s, c, 0.84, 0.85, 0.54, 0.55); /* (s==0.841..., c==0.5403...) */  TESTIT_2P_R (sincos, -one, s, c, -0.85, -0.84, 0.54, 0.55); /* (s==-0.841..., c==0.5403...) */#endif    TESTIT_R (sinh, -1.0, -1.18, -1.17); /* sinh(-1) == -1.175... */  TESTIT (sinh, 0.0, 0.0); /* sinh(0) == 0 */  TESTIT (sinh, -0.0, -0.0); /* sinh(-0) == -0 */  TESTIT_R (sinh, 1.0, 1.17, 1.18); /* sinh(1) == 1.175... */  TESTIT_R (cosh, -1.0, 1.54, 1.55); /* cosh(-1) == 1.543... */  TESTIT (cosh, 0.0, 1.0); /* cosh(0) == 1 */  TESTIT (cosh, -0.0, 1.0); /* cosh(-0) == 1 */  TESTIT_R (cosh, 1.0, 1.54, 1.55); /* cosh(1) == 1.543... */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -