Vegetarianboy30

crappy program in c

Jan 19th, 2021
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.52 KB | None | 0 0
  1. /*  */
  2. #include <math.h>
  3.  
  4. #include "../interpreter.h"
  5.  
  6.  
  7. static double M_EValue = 2.7182818284590452354;   /* e */
  8. static double M_LOG2EValue = 1.4426950408889634074;   /* log_2 e */
  9. static double M_LOG10EValue = 0.43429448190325182765;  /* log_10 e */
  10. static double M_LN2Value = 0.69314718055994530942;  /* log_e 2 */
  11. static double M_LN10Value = 2.30258509299404568402;  /* log_e 10 */
  12. static double M_PIValue = 3.14159265358979323846;  /* pi */
  13. static double M_PI_2Value = 1.57079632679489661923;  /* pi/2 */
  14. static double M_PI_4Value = 0.78539816339744830962;  /* pi/4 */
  15. static double M_1_PIValue = 0.31830988618379067154;  /* 1/pi */
  16. static double M_2_PIValue = 0.63661977236758134308;  /* 2/pi */
  17. static double M_2_SQRTPIValue = 1.12837916709551257390;  /* 2/sqrt(pi) */
  18. static double M_SQRT2Value = 1.41421356237309504880;  /* sqrt(2) */
  19. static double M_SQRT1_2Value =  0.70710678118654752440;  /* 1/sqrt(2) */
  20.  
  21.  
  22. void MathSin(struct ParseState *Parser, struct Value *ReturnValue,
  23.     struct Value **Param, int NumArgs)
  24. {
  25.     ReturnValue->Val->FP = sin(Param[0]->Val->FP);
  26. }
  27.  
  28. void MathCos(struct ParseState *Parser, struct Value *ReturnValue,
  29.     struct Value **Param, int NumArgs)
  30. {
  31.     ReturnValue->Val->FP = cos(Param[0]->Val->FP);
  32. }
  33.  
  34. void MathTan(struct ParseState *Parser, struct Value *ReturnValue,
  35.     struct Value **Param, int NumArgs)
  36. {
  37.     ReturnValue->Val->FP = tan(Param[0]->Val->FP);
  38. }
  39.  
  40. void MathAsin(struct ParseState *Parser, struct Value *ReturnValue,
  41.     struct Value **Param, int NumArgs)
  42. {
  43.     ReturnValue->Val->FP = asin(Param[0]->Val->FP);
  44. }
  45.  
  46. void MathAcos(struct ParseState *Parser, struct Value *ReturnValue,
  47.     struct Value **Param, int NumArgs)
  48. {
  49.     ReturnValue->Val->FP = acos(Param[0]->Val->FP);
  50. }
  51.  
  52. void MathAtan(struct ParseState *Parser, struct Value *ReturnValue,
  53.     struct Value **Param, int NumArgs)
  54. {
  55.     ReturnValue->Val->FP = atan(Param[0]->Val->FP);
  56. }
  57.  
  58. void MathAtan2(struct ParseState *Parser, struct Value *ReturnValue,
  59.     struct Value **Param, int NumArgs)
  60. {
  61.     ReturnValue->Val->FP = atan2(Param[0]->Val->FP, Param[1]->Val->FP);
  62. }
  63.  
  64. void MathSinh(struct ParseState *Parser, struct Value *ReturnValue,
  65.     struct Value **Param, int NumArgs)
  66. {
  67.     ReturnValue->Val->FP = sinh(Param[0]->Val->FP);
  68. }
  69.  
  70. void MathCosh(struct ParseState *Parser, struct Value *ReturnValue,
  71.     struct Value **Param, int NumArgs)
  72. {
  73.     ReturnValue->Val->FP = cosh(Param[0]->Val->FP);
  74. }
  75.  
  76. void MathTanh(struct ParseState *Parser, struct Value *ReturnValue,
  77.     struct Value **Param, int NumArgs)
  78. {
  79.     ReturnValue->Val->FP = tanh(Param[0]->Val->FP);
  80. }
  81.  
  82. void MathExp(struct ParseState *Parser, struct Value *ReturnValue,
  83.     struct Value **Param, int NumArgs)
  84. {
  85.     ReturnValue->Val->FP = exp(Param[0]->Val->FP);
  86. }
  87.  
  88. void MathFabs(struct ParseState *Parser, struct Value *ReturnValue,
  89.     struct Value **Param, int NumArgs)
  90. {
  91.     ReturnValue->Val->FP = fabs(Param[0]->Val->FP);
  92. }
  93.  
  94. void MathFmod(struct ParseState *Parser, struct Value *ReturnValue,
  95.     struct Value **Param, int NumArgs)
  96. {
  97.     ReturnValue->Val->FP = fmod(Param[0]->Val->FP, Param[1]->Val->FP);
  98. }
  99.  
  100. void MathFrexp(struct ParseState *Parser, struct Value *ReturnValue,
  101.     struct Value **Param, int NumArgs)
  102. {
  103.     ReturnValue->Val->FP = frexp(Param[0]->Val->FP, Param[1]->Val->Pointer);
  104. }
  105.  
  106. void MathLdexp(struct ParseState *Parser, struct Value *ReturnValue,
  107.     struct Value **Param, int NumArgs)
  108. {
  109.     ReturnValue->Val->FP = ldexp(Param[0]->Val->FP, Param[1]->Val->Integer);
  110. }
  111.  
  112. void MathLog(struct ParseState *Parser, struct Value *ReturnValue,
  113.     struct Value **Param, int NumArgs)
  114. {
  115.     ReturnValue->Val->FP = log(Param[0]->Val->FP);
  116. }
  117.  
  118. void MathLog10(struct ParseState *Parser, struct Value *ReturnValue,
  119.     struct Value **Param, int NumArgs)
  120. {
  121.     ReturnValue->Val->FP = log10(Param[0]->Val->FP);
  122. }
  123.  
  124. void MathModf(struct ParseState *Parser, struct Value *ReturnValue,
  125.     struct Value **Param, int NumArgs)
  126. {
  127.     ReturnValue->Val->FP = modf(Param[0]->Val->FP, Param[0]->Val->Pointer);
  128. }
  129.  
  130. void MathPow(struct ParseState *Parser, struct Value *ReturnValue,
  131.     struct Value **Param, int NumArgs)
  132. {
  133.     ReturnValue->Val->FP = pow(Param[0]->Val->FP, Param[1]->Val->FP);
  134. }
  135.  
  136. void MathSqrt(struct ParseState *Parser, struct Value *ReturnValue,
  137.     struct Value **Param, int NumArgs)
  138. {
  139.     ReturnValue->Val->FP = sqrt(Param[0]->Val->FP);
  140. }
  141.  
  142. void MathRound(struct ParseState *Parser, struct Value *ReturnValue,
  143.     struct Value **Param, int NumArgs)
  144. {
  145.     /* this awkward definition of "round()" due to it being inconsistently
  146.      * declared in math.h */
  147.     ReturnValue->Val->FP = ceil(Param[0]->Val->FP - 0.5);
  148. }
  149.  
  150. void MathCeil(struct ParseState *Parser, struct Value *ReturnValue,
  151.     struct Value **Param, int NumArgs)
  152. {
  153.     ReturnValue->Val->FP = ceil(Param[0]->Val->FP);
  154. }
  155.  
  156. void MathFloor(struct ParseState *Parser, struct Value *ReturnValue,
  157.     struct Value **Param, int NumArgs)
  158. {
  159.     ReturnValue->Val->FP = floor(Param[0]->Val->FP);
  160. }
  161.  
  162. /* all math.h functions */
  163. struct LibraryFunction MathFunctions[] =
  164. {
  165.      {MathAcos, "float acos(float);"},
  166.      {MathAsin, "float asin(float);"},
  167.      {MathAtan, "float atan(float);"},
  168.      {MathAtan2, "float atan2(float, float);"},
  169.      {MathCeil, "float ceil(float);"},
  170.      {MathCos, "float cos(float);"},
  171.      {MathCosh, "float cosh(float);"},
  172.      {MathExp, "float exp(float);"},
  173.      {MathFabs, "float fabs(float);"},
  174.      {MathFloor, "float floor(float);"},
  175.      {MathFmod, "float fmod(float, float);"},
  176.      {MathFrexp, "float frexp(float, int *);"},
  177.      {MathLdexp, "float ldexp(float, int);"},
  178.      {MathLog, "float log(float);"},
  179.      {MathLog10, "float log10(float);"},
  180.      {MathModf, "float modf(float, float *);"},
  181.      {MathPow, "float pow(float,float);"},
  182.      {MathRound, "float round(float);"},
  183.      {MathSin, "float sin(float);"},
  184.      {MathSinh, "float sinh(float);"},
  185.      {MathSqrt, "float sqrt(float);"},
  186.      {MathTan,  "float tan(float);"},
  187.      {MathTanh, "float tanh(float);"},
  188.      {NULL,  NULL }
  189. };
  190.  
  191. /* creates various system-dependent definitions */
  192. void MathSetupFunc(Picoc *pc)
  193. {
  194.     VariableDefinePlatformVar(pc, NULL, "M_E", &pc->FPType,
  195.         (union AnyValue*)&M_EValue, false);
  196.     VariableDefinePlatformVar(pc, NULL, "M_LOG2E", &pc->FPType,
  197.         (union AnyValue*)&M_LOG2EValue, false);
  198.     VariableDefinePlatformVar(pc, NULL, "M_LOG10E", &pc->FPType,
  199.         (union AnyValue*)&M_LOG10EValue, false);
  200.     VariableDefinePlatformVar(pc, NULL, "M_LN2", &pc->FPType,
  201.         (union AnyValue*)&M_LN2Value, false);
  202.     VariableDefinePlatformVar(pc, NULL, "M_LN10", &pc->FPType,
  203.         (union AnyValue*)&M_LN10Value, false);
  204.     VariableDefinePlatformVar(pc, NULL, "M_PI", &pc->FPType,
  205.         (union AnyValue*)&M_PIValue, false);
  206.     VariableDefinePlatformVar(pc, NULL, "M_PI_2", &pc->FPType,
  207.         (union AnyValue*)&M_PI_2Value, false);
  208.     VariableDefinePlatformVar(pc, NULL, "M_PI_4", &pc->FPType,
  209.         (union AnyValue*)&M_PI_4Value, false);
  210.     VariableDefinePlatformVar(pc, NULL, "M_1_PI", &pc->FPType,
  211.         (union AnyValue*)&M_1_PIValue, false);
  212.     VariableDefinePlatformVar(pc, NULL, "M_2_PI", &pc->FPType,
  213.         (union AnyValue*)&M_2_PIValue, false);
  214.     VariableDefinePlatformVar(pc, NULL, "M_2_SQRTPI", &pc->FPType,
  215.         (union AnyValue*)&M_2_SQRTPIValue, false);
  216.     VariableDefinePlatformVar(pc, NULL, "M_SQRT2", &pc->FPType,
  217.         (union AnyValue*)&M_SQRT2Value, false);
  218.     VariableDefinePlatformVar(pc, NULL, "M_SQRT1_2", &pc->FPType,
  219.         (union AnyValue*)&M_SQRT1_2Value, false);
  220. }
Add Comment
Please, Sign In to add comment