MathLibrary.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. public:
  20. static const LPCWSTR LibraryName;
  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 LibraryName; }
  24. bool IsAvailable() { Ensure(); return DelayLoadLibrary::IsAvailable(); }
  25. void Ensure();
  26. HMODULE GetHandle() const { return m_hModule; }
  27. double log2 (_In_ double x) { Assert(IsAvailable()); return m_pfnlog2 (x); }
  28. double log1p(_In_ double x) { Assert(IsAvailable()); return m_pfnlog1p(x); }
  29. double expm1(_In_ double x) { Assert(IsAvailable()); return m_pfnexpm1(x); }
  30. double acosh(_In_ double x) { Assert(IsAvailable()); return m_pfnacosh(x); }
  31. double asinh(_In_ double x) { Assert(IsAvailable()); return m_pfnasinh(x); }
  32. double atanh(_In_ double x) { Assert(IsAvailable()); return m_pfnatanh(x); }
  33. double trunc(_In_ double x) { Assert(IsAvailable()); return m_pfntrunc(x); }
  34. double cbrt (_In_ double x) { Assert(IsAvailable()); return m_pfncbrt (x); }
  35. };
  36. namespace Js {
  37. class Math /* TODO: Determine actual object */
  38. {
  39. public:
  40. class EntryInfo
  41. {
  42. public:
  43. static FunctionInfo Abs;
  44. static FunctionInfo Acos;
  45. static FunctionInfo Asin;
  46. static FunctionInfo Atan;
  47. static FunctionInfo Atan2;
  48. static FunctionInfo Ceil;
  49. static FunctionInfo Cos;
  50. static FunctionInfo Exp;
  51. static FunctionInfo Floor;
  52. static FunctionInfo Log;
  53. static FunctionInfo Max;
  54. static FunctionInfo Min;
  55. static FunctionInfo Pow;
  56. static FunctionInfo Random;
  57. static FunctionInfo Round;
  58. static FunctionInfo Sin;
  59. static FunctionInfo Sqrt;
  60. static FunctionInfo Tan;
  61. // ES6 additions
  62. static FunctionInfo Log10;
  63. static FunctionInfo Log2;
  64. static FunctionInfo Log1p;
  65. static FunctionInfo Expm1;
  66. static FunctionInfo Cosh;
  67. static FunctionInfo Sinh;
  68. static FunctionInfo Tanh;
  69. static FunctionInfo Acosh;
  70. static FunctionInfo Asinh;
  71. static FunctionInfo Atanh;
  72. static FunctionInfo Hypot;
  73. static FunctionInfo Trunc;
  74. static FunctionInfo Sign;
  75. static FunctionInfo Cbrt;
  76. static FunctionInfo Imul;
  77. static FunctionInfo Clz32;
  78. static FunctionInfo Fround;
  79. };
  80. static Var Abs(RecyclableObject* function, CallInfo callInfo, ...);
  81. static double Abs(double x);
  82. static Var Acos(RecyclableObject* function, CallInfo callInfo, ...);
  83. static double Acos(double x);
  84. static Var Asin(RecyclableObject* function, CallInfo callInfo, ...);
  85. static double Asin(double x);
  86. static Var Atan(RecyclableObject* function, CallInfo callInfo, ...);
  87. static double Atan(double x);
  88. static Var Atan2( RecyclableObject* function, CallInfo callInfo, ... );
  89. static double Atan2( double x, double y );
  90. static Var Ceil(RecyclableObject* function, CallInfo callInfo, ...);
  91. static Var Cos(RecyclableObject* function, CallInfo callInfo, ...);
  92. static double Cos(double x);
  93. static Var Exp(RecyclableObject* function, CallInfo callInfo, ...);
  94. static double Exp(double x);
  95. static Var Floor(RecyclableObject* function, CallInfo callInfo, ...);
  96. static Var Log(RecyclableObject* function, CallInfo callInfo, ...);
  97. static double Log(double x);
  98. static Var Max(RecyclableObject* function, CallInfo callInfo, ...);
  99. static Var Min(RecyclableObject* function, CallInfo callInfo, ...);
  100. static Var Pow( RecyclableObject* function, CallInfo callInfo, ... );
  101. static double Pow( double x, double y);
  102. static Var Random(RecyclableObject* function, CallInfo callInfo, ...);
  103. static Var Round(RecyclableObject* function, CallInfo callInfo, ...);
  104. static Var Sin(RecyclableObject* function, CallInfo callInfo, ...);
  105. static double Sin(double x);
  106. static Var Sqrt(RecyclableObject* function, CallInfo callInfo, ...);
  107. static Var Tan( RecyclableObject* function, CallInfo callInfo, ... );
  108. static double Tan( double x );
  109. // ES6 Additions
  110. static Var Log10(RecyclableObject* function, CallInfo callInfo, ...);
  111. static double Log10(double x);
  112. static Var Log2(RecyclableObject* function, CallInfo callInfo, ...);
  113. static double Log2(double x, ScriptContext* scriptContext);
  114. static Var Log1p( RecyclableObject* function, CallInfo callInfo, ... );
  115. static Var Expm1(RecyclableObject* function, CallInfo callInfo, ...);
  116. static Var Cosh(RecyclableObject* function, CallInfo callInfo, ...);
  117. static Var Sinh(RecyclableObject* function, CallInfo callInfo, ...);
  118. static Var Tanh(RecyclableObject* function, CallInfo callInfo, ...);
  119. static Var Acosh(RecyclableObject* function, CallInfo callInfo, ...);
  120. static Var Asinh(RecyclableObject* function, CallInfo callInfo, ...);
  121. static Var Atanh(RecyclableObject* function, CallInfo callInfo, ...);
  122. static Var Hypot(RecyclableObject* function, CallInfo callInfo, ...);
  123. static double HypotHelper(Arguments args, ScriptContext* scriptContext);
  124. static Var Trunc(RecyclableObject* function, CallInfo callInfo, ...);
  125. static Var Sign(RecyclableObject* function, CallInfo callInfo, ...);
  126. static Var Cbrt(RecyclableObject* function, CallInfo callInfo, ...);
  127. static Var Imul(RecyclableObject* function, CallInfo callInfo, ...);
  128. static Var Clz32(RecyclableObject* function, CallInfo callInfo, ...);
  129. static Var Fround(RecyclableObject* function, CallInfo callInfo, ...);
  130. static double NonZeroMin(double x1, double x2, double x3);
  131. static const double PI;
  132. static const double E;
  133. static const double LN10;
  134. static const double LN2;
  135. static const double LOG2E;
  136. static const double LOG10E;
  137. static const double SQRT1_2;
  138. static const double SQRT2;
  139. static const double EPSILON;
  140. static const double MAX_SAFE_INTEGER;
  141. static const double MIN_SAFE_INTEGER;
  142. private:
  143. static Var FloorDouble(double d, ScriptContext *scriptContext);
  144. };
  145. } // namespace Js