MathLibrary.h 7.1 KB

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