MathLibrary.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. class UCrtC99MathApis : protected DelayLoadLibrary
  7. {
  8. private:
  9. typedef double (__cdecl FNMathFn)(double);
  10. typedef FNMathFn* PFNMathFn;
  11. PFNMathFn m_pfnlog2;
  12. PFNMathFn m_pfnlog1p;
  13. PFNMathFn m_pfnexpm1;
  14. PFNMathFn m_pfnacosh;
  15. PFNMathFn m_pfnasinh;
  16. PFNMathFn m_pfnatanh;
  17. PFNMathFn m_pfntrunc;
  18. PFNMathFn m_pfncbrt;
  19. void Ensure();
  20. public:
  21. UCrtC99MathApis() : m_pfnlog2(nullptr), m_pfnlog1p(nullptr), m_pfnexpm1(nullptr), m_pfnacosh(nullptr), m_pfnasinh(nullptr), m_pfnatanh(nullptr), m_pfntrunc(nullptr), m_pfncbrt(nullptr) { }
  22. virtual ~UCrtC99MathApis() { }
  23. virtual LPCWSTR GetLibraryName() const override { return CH_WSTR("api-ms-win-crt-math-l1-1-0.dll"); }
  24. bool IsAvailable() { Ensure(); return DelayLoadLibrary::IsAvailable(); }
  25. double log2 (_In_ double x) { Assert(IsAvailable()); return m_pfnlog2 (x); }
  26. double log1p(_In_ double x) { Assert(IsAvailable()); return m_pfnlog1p(x); }
  27. double expm1(_In_ double x) { Assert(IsAvailable()); return m_pfnexpm1(x); }
  28. double acosh(_In_ double x) { Assert(IsAvailable()); return m_pfnacosh(x); }
  29. double asinh(_In_ double x) { Assert(IsAvailable()); return m_pfnasinh(x); }
  30. double atanh(_In_ double x) { Assert(IsAvailable()); return m_pfnatanh(x); }
  31. double trunc(_In_ double x) { Assert(IsAvailable()); return m_pfntrunc(x); }
  32. double cbrt (_In_ double x) { Assert(IsAvailable()); return m_pfncbrt (x); }
  33. };
  34. namespace Js {
  35. class Math /* TODO: Determine actual object */
  36. {
  37. public:
  38. class EntryInfo
  39. {
  40. public:
  41. static FunctionInfo Abs;
  42. static FunctionInfo Acos;
  43. static FunctionInfo Asin;
  44. static FunctionInfo Atan;
  45. static FunctionInfo Atan2;
  46. static FunctionInfo Ceil;
  47. static FunctionInfo Cos;
  48. static FunctionInfo Exp;
  49. static FunctionInfo Floor;
  50. static FunctionInfo Log;
  51. static FunctionInfo Max;
  52. static FunctionInfo Min;
  53. static FunctionInfo Pow;
  54. static FunctionInfo Random;
  55. static FunctionInfo Round;
  56. static FunctionInfo Sin;
  57. static FunctionInfo Sqrt;
  58. static FunctionInfo Tan;
  59. // ES6 additions
  60. static FunctionInfo Log10;
  61. static FunctionInfo Log2;
  62. static FunctionInfo Log1p;
  63. static FunctionInfo Expm1;
  64. static FunctionInfo Cosh;
  65. static FunctionInfo Sinh;
  66. static FunctionInfo Tanh;
  67. static FunctionInfo Acosh;
  68. static FunctionInfo Asinh;
  69. static FunctionInfo Atanh;
  70. static FunctionInfo Hypot;
  71. static FunctionInfo Trunc;
  72. static FunctionInfo Sign;
  73. static FunctionInfo Cbrt;
  74. static FunctionInfo Imul;
  75. static FunctionInfo Clz32;
  76. static FunctionInfo Fround;
  77. };
  78. static Var Abs(RecyclableObject* function, CallInfo callInfo, ...);
  79. static double Abs(double x);
  80. static Var Acos(RecyclableObject* function, CallInfo callInfo, ...);
  81. static double Acos(double x);
  82. static Var Asin(RecyclableObject* function, CallInfo callInfo, ...);
  83. static double Asin(double x);
  84. static Var Atan(RecyclableObject* function, CallInfo callInfo, ...);
  85. static double Atan(double x);
  86. static Var Atan2( RecyclableObject* function, CallInfo callInfo, ... );
  87. static double Atan2( double x, double y );
  88. static Var Ceil(RecyclableObject* function, CallInfo callInfo, ...);
  89. static Var Cos(RecyclableObject* function, CallInfo callInfo, ...);
  90. static double Cos(double x);
  91. static Var Exp(RecyclableObject* function, CallInfo callInfo, ...);
  92. static double Exp(double x);
  93. static Var Floor(RecyclableObject* function, CallInfo callInfo, ...);
  94. static Var Log(RecyclableObject* function, CallInfo callInfo, ...);
  95. static double Log(double x);
  96. static Var Max(RecyclableObject* function, CallInfo callInfo, ...);
  97. static Var Min(RecyclableObject* function, CallInfo callInfo, ...);
  98. static Var Pow( RecyclableObject* function, CallInfo callInfo, ... );
  99. static double Pow( double x, double y);
  100. static Var Random(RecyclableObject* function, CallInfo callInfo, ...);
  101. static Var Round(RecyclableObject* function, CallInfo callInfo, ...);
  102. static Var Sin(RecyclableObject* function, CallInfo callInfo, ...);
  103. static double Sin(double x);
  104. static Var Sqrt(RecyclableObject* function, CallInfo callInfo, ...);
  105. static Var Tan( RecyclableObject* function, CallInfo callInfo, ... );
  106. static double Tan( double x );
  107. // ES6 Additions
  108. static Var Log10(RecyclableObject* function, CallInfo callInfo, ...);
  109. static double Log10(double x);
  110. static Var Log2(RecyclableObject* function, CallInfo callInfo, ...);
  111. static double Log2(double x, ScriptContext* scriptContext);
  112. static Var Log1p( RecyclableObject* function, CallInfo callInfo, ... );
  113. static Var Expm1(RecyclableObject* function, CallInfo callInfo, ...);
  114. static Var Cosh(RecyclableObject* function, CallInfo callInfo, ...);
  115. static Var Sinh(RecyclableObject* function, CallInfo callInfo, ...);
  116. static Var Tanh(RecyclableObject* function, CallInfo callInfo, ...);
  117. static Var Acosh(RecyclableObject* function, CallInfo callInfo, ...);
  118. static Var Asinh(RecyclableObject* function, CallInfo callInfo, ...);
  119. static Var Atanh(RecyclableObject* function, CallInfo callInfo, ...);
  120. static Var Hypot(RecyclableObject* function, CallInfo callInfo, ...);
  121. static double HypotHelper(Arguments args, ScriptContext* scriptContext);
  122. static Var Trunc(RecyclableObject* function, CallInfo callInfo, ...);
  123. static Var Sign(RecyclableObject* function, CallInfo callInfo, ...);
  124. static Var Cbrt(RecyclableObject* function, CallInfo callInfo, ...);
  125. static Var Imul(RecyclableObject* function, CallInfo callInfo, ...);
  126. static Var Clz32(RecyclableObject* function, CallInfo callInfo, ...);
  127. static Var Fround(RecyclableObject* function, CallInfo callInfo, ...);
  128. static double NonZeroMin(double x1, double x2, double x3);
  129. static const double PI;
  130. static const double E;
  131. static const double LN10;
  132. static const double LN2;
  133. static const double LOG2E;
  134. static const double LOG10E;
  135. static const double SQRT1_2;
  136. static const double SQRT2;
  137. static const double EPSILON;
  138. static const double MAX_SAFE_INTEGER;
  139. static const double MIN_SAFE_INTEGER;
  140. private:
  141. static Var Math::FloorDouble(double d, ScriptContext *scriptContext);
  142. };
  143. } // namespace Js