FloatConversion.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. //
  2. // FloatConversion.h
  3. // cocos2d_libs
  4. //
  5. // Created by 徐俊杰 on 2020/5/15.
  6. //
  7. #ifndef FloatConversion_h
  8. #define FloatConversion_h
  9. #include "rparticle/Macros/RParticleMacros.h"
  10. #include <algorithm>
  11. #include <cmath>
  12. #include <limits>
  13. #include <math.h>
  14. #if !UNITY_EXTERNAL_TOOL
  15. //#include "LogAssert.h"
  16. #endif
  17. #if defined(SN_TARGET_PS3)
  18. # include <ppu_intrinsics.h>
  19. #elif defined(__GNUC__) && defined(__ppc__)
  20. # include <ppc_intrinsics.h>
  21. #endif
  22. #ifndef kPI
  23. #define kPI 3.14159265358979323846264338327950288419716939937510F
  24. #endif
  25. NS_RRP_BEGIN
  26. const float kBiggestFloatSmallerThanOne = 0.99999994f;
  27. const double kBiggestDoubleSmallerThanOne = 0.99999999999999989;
  28. #if defined(_XBOX)
  29. #define __FSELF __fself
  30. #elif defined(SN_TARGET_PS3)
  31. #define __FSELF __fsels
  32. #endif
  33. inline float FloatMin(float a, float b)
  34. {
  35. #if defined(_XBOX) || defined(SN_TARGET_PS3)
  36. return __FSELF((a)-(b), b, a);
  37. #else
  38. return std::min(a, b);
  39. #endif
  40. }
  41. inline float FloatMax(float a, float b)
  42. {
  43. #if defined(_XBOX) || defined(SN_TARGET_PS3)
  44. return __FSELF((a)-(b), a, b);
  45. #else
  46. return std::max(a, b);
  47. #endif
  48. }
  49. inline float Abs (float v)
  50. {
  51. #if defined(__ppc__) && (defined(__MWERKS__) || defined(SN_TARGET_PS3))
  52. return __fabsf(v);
  53. #elif defined(_XBOX)
  54. return __fabs(v);
  55. #else
  56. return v < 0.0F ? -v : v;
  57. #endif
  58. }
  59. inline double Abs (double v)
  60. {
  61. return v < 0.0 ? -v : v;
  62. }
  63. inline int Abs (int v)
  64. {
  65. return v < 0 ? -v : v;
  66. }
  67. // Floor, ceil and round functions.
  68. //
  69. // When changing or implementing these functions, make sure the tests in MathTest.cpp
  70. // still pass.
  71. //
  72. // Floor: rounds to the largest integer smaller than or equal to the input parameter.
  73. // Ceil: rounds to the smallest integer larger than or equal to the input parameter.
  74. // Round: rounds to the nearest integer. Ties (0.5) are rounded up to the smallest integer
  75. // larger than or equal to the input parameter.
  76. // Chop/truncate: use a normal integer cast.
  77. //
  78. // Windows:
  79. // Casts are as fast as a straight fistp on an SSE equipped CPU. This is by far the most common
  80. // scenario and will result in the best code for most users. fistp will use the rounding mode set
  81. // in the control register (round to nearest by default), and needs fiddling to work properly.
  82. // This actually makes code that attempt to use fistp slower than a cast.
  83. // Unless we want round to nearest, in which case fistp should be the best choice, right? But
  84. // it is not. The default rounding mode is round to nearest, but in case of a tie (0.5), round to
  85. // nearest even is used. Thus 0.5 is rounded down to 0, 1.5 is rounded up to 2.
  86. // Conclusion - fistp is useless without stupid fiddling around that actually makes is slower than
  87. // an SSE cast.
  88. //
  89. // OS X Intel:
  90. // Needs investigating
  91. //
  92. // OS X PowerPC:
  93. // Needs investigating
  94. //
  95. // Xbox 360:
  96. // Needs investigating
  97. //
  98. // PS3:
  99. // Needs investigating
  100. //
  101. // iPhone:
  102. // Needs investigating
  103. //
  104. // Android:
  105. // Needs investigating
  106. inline int FloorfToInt (float f)
  107. {
  108. DebugAssertIf (f < INT_MIN || f > INT_MAX);
  109. return f >= 0 ? (int)f : (int)(f - kBiggestFloatSmallerThanOne);
  110. }
  111. inline UInt32 FloorfToIntPos (float f)
  112. {
  113. DebugAssertIf (f < 0 || f > UINT_MAX);
  114. return (UInt32)f;
  115. }
  116. inline float Floorf (float f)
  117. {
  118. // Use std::floor().
  119. // We are interested in reliable functions that do not lose precision.
  120. // Casting to int and back to float would not be helpful.
  121. return floor (f);
  122. }
  123. inline double Floord (double f)
  124. {
  125. // Use std::floor().
  126. // We are interested in reliable functions that do not lose precision.
  127. // Casting to int and back to float would not be helpful.
  128. return floor (f);
  129. }
  130. inline int CeilfToInt (float f)
  131. {
  132. DebugAssertIf (f < INT_MIN || f > INT_MAX);
  133. return f >= 0 ? (int)(f + kBiggestFloatSmallerThanOne) : (int)(f);
  134. }
  135. inline UInt32 CeilfToIntPos (float f)
  136. {
  137. DebugAssertIf (f < 0 || f > UINT_MAX);
  138. return (UInt32)(f + kBiggestFloatSmallerThanOne);
  139. }
  140. inline float Ceilf (float f)
  141. {
  142. // Use std::ceil().
  143. // We are interested in reliable functions that do not lose precision.
  144. // Casting to int and back to float would not be helpful.
  145. return ceil (f);
  146. }
  147. inline double Ceild (double f)
  148. {
  149. // Use std::ceil().
  150. // We are interested in reliable functions that do not lose precision.
  151. // Casting to int and back to float would not be helpful.
  152. return ceil (f);
  153. }
  154. inline int RoundfToInt (float f)
  155. {
  156. return FloorfToInt (f + 0.5F);
  157. }
  158. inline UInt32 RoundfToIntPos (float f)
  159. {
  160. return FloorfToIntPos (f + 0.5F);
  161. }
  162. inline float Roundf (float f)
  163. {
  164. return Floorf (f + 0.5F);
  165. }
  166. inline double Roundf (double f)
  167. {
  168. return Floord (f + 0.5);
  169. }
  170. /// Fast conversion of float [0...1] to 0 ... 65535
  171. inline int NormalizedToWord (float f)
  172. {
  173. f = FloatMax (f, 0.0F);
  174. f = FloatMin (f, 1.0F);
  175. return RoundfToIntPos (f * 65535.0f);
  176. }
  177. /// Fast conversion of float [0...1] to 0 ... 65535
  178. inline float WordToNormalized (int p)
  179. {
  180. AssertIf(p < 0 || p > 65535);
  181. return (float)p / 65535.0F;
  182. }
  183. /// Fast conversion of float [0...1] to 0 ... 255
  184. inline int NormalizedToByte (float f)
  185. {
  186. f = FloatMax (f, 0.0F);
  187. f = FloatMin (f, 1.0F);
  188. return RoundfToIntPos (f * 255.0f);
  189. }
  190. /// Fast conversion of float [0...1] to 0 ... 255
  191. inline float ByteToNormalized (int p)
  192. {
  193. AssertIf(p < 0 || p > 255);
  194. return (float)p / 255.0F;
  195. }
  196. // Returns float remainder for t / length
  197. inline float Repeat (float t, float length)
  198. {
  199. return t - Floorf (t / length) * length;
  200. }
  201. // Returns double remainder for t / length
  202. inline double RepeatD (double t, double length)
  203. {
  204. return t - floor (t / length) * length;
  205. }
  206. // Returns relative angle on the interval (-pi, pi]
  207. inline float DeltaAngleRad (float current, float target)
  208. {
  209. float delta = Repeat ((target - current), 2 * kPI);
  210. if (delta > kPI)
  211. delta -= 2 * kPI;
  212. return delta;
  213. }
  214. // Returns true if the distance between f0 and f1 is smaller than epsilon
  215. inline bool CompareApproximately (float f0, float f1, float epsilon = 0.000001F)
  216. {
  217. float dist = (f0 - f1);
  218. dist = Abs (dist);
  219. return dist < epsilon;
  220. }
  221. /// CopySignf () returns x with its sign changed to y's.
  222. inline float CopySignf (float x, float y)
  223. {
  224. union
  225. {
  226. float f;
  227. UInt32 i;
  228. } u, u0, u1;
  229. u0.f = x; u1.f = y;
  230. UInt32 a = u0.i;
  231. UInt32 b = u1.i;
  232. SInt32 mask = 1 << 31;
  233. UInt32 sign = b & mask;
  234. a &= ~mask;
  235. a |= sign;
  236. u.i = a;
  237. return u.f;
  238. }
  239. inline int CompareFloatRobustSignUtility (float A)
  240. {
  241. // The sign bit of a number is the high bit.
  242. union
  243. {
  244. float f;
  245. int i;
  246. } u;
  247. u.f = A;
  248. return (u.i) & 0x80000000;
  249. }
  250. inline bool CompareFloatRobust (float f0, float f1, int maxUlps = 10)
  251. {
  252. // After adjusting floats so their representations are lexicographically
  253. // ordered as twos-complement integers a very small positive number
  254. // will compare as 'close' to a very small negative number. If this is
  255. // not desireable, and if you are on a platform that supports
  256. // subnormals (which is the only place the problem can show up) then
  257. // you need this check.
  258. // The check for A == B is because zero and negative zero have different
  259. // signs but are equal to each other.
  260. if (CompareFloatRobustSignUtility(f0) != CompareFloatRobustSignUtility(f1))
  261. return f0 == f1;
  262. union
  263. {
  264. float f;
  265. int i;
  266. } u0, u1;
  267. u0.f = f0;
  268. u1.f = f1;
  269. int aInt = u0.i;
  270. // Make aInt lexicographically ordered as a twos-complement int
  271. if (aInt < 0)
  272. aInt = 0x80000000 - aInt;
  273. // Make bInt lexicographically ordered as a twos-complement int
  274. int bInt = u1.i;
  275. if (bInt < 0)
  276. bInt = 0x80000000 - bInt;
  277. // Now we can compare aInt and bInt to find out how far apart A and B
  278. // are.
  279. int intDiff = Abs (aInt - bInt);
  280. if (intDiff <= maxUlps)
  281. return true;
  282. return false;
  283. }
  284. // Returns the t^2
  285. template<class T>
  286. T Sqr (const T& t)
  287. {
  288. return t * t;
  289. }
  290. #define kDeg2Rad (2.0F * kPI / 360.0F)
  291. #define kRad2Deg (1.F / kDeg2Rad)
  292. inline float Deg2Rad (float deg)
  293. {
  294. // TODO : should be deg * kDeg2Rad, but can't be changed,
  295. // because it changes the order of operations and that affects a replay in some RegressionTests
  296. return deg / 360.0F * 2.0F * kPI;
  297. }
  298. inline float Rad2Deg (float rad)
  299. {
  300. // TODO : should be rad * kRad2Deg, but can't be changed,
  301. // because it changes the order of operations and that affects a replay in some RegressionTests
  302. return rad / 2.0F / kPI * 360.0F;
  303. }
  304. inline float Lerp (float from, float to, float t)
  305. {
  306. return to * t + from * (1.0F - t);
  307. }
  308. inline bool IsNAN (float value)
  309. {
  310. #if defined __APPLE_CC__
  311. return value != value;
  312. #elif _MSC_VER
  313. return _isnan(value) != 0;
  314. #else
  315. return std::isnan (value);
  316. #endif
  317. }
  318. inline bool IsNAN (double value)
  319. {
  320. #if defined __APPLE_CC__
  321. return value != value;
  322. #elif _MSC_VER
  323. return _isnan(value) != 0;
  324. #else
  325. return std::isnan (value);
  326. #endif
  327. }
  328. inline bool IsPlusInf(float value) { return value == std::numeric_limits<float>::infinity (); }
  329. inline bool IsMinusInf(float value) { return value == -std::numeric_limits<float>::infinity (); }
  330. inline bool IsFinite(const float& value)
  331. {
  332. // Returns false if value is NaN or +/- infinity
  333. UInt32 intval = *reinterpret_cast<const UInt32*>(&value);
  334. return (intval & 0x7f800000) != 0x7f800000;
  335. }
  336. inline bool IsFinite(const double& value)
  337. {
  338. // Returns false if value is NaN or +/- infinity
  339. UInt64 intval = *reinterpret_cast<const UInt64*>(&value);
  340. return (intval & 0x7ff0000000000000LL) != 0x7ff0000000000000LL;
  341. }
  342. inline float InvSqrt (float p) { return 1.0F / sqrt (p); }
  343. inline float Sqrt (float p) { return sqrt (p); }
  344. /// - Almost highest precision sqrt
  345. /// - Returns 0 if value is 0 or -1
  346. /// inline float FastSqrt (float value)
  347. /// - Almost highest precision inv sqrt
  348. /// - if value == 0 or -0 it returns 0.
  349. /// inline float FastInvSqrt (float value)
  350. /// - Low precision inv sqrt approximately
  351. /// - if value == 0 or -0 it returns nan or undefined
  352. /// inline float FastestInvSqrt (float value)
  353. #if defined(__ppc__) || defined(SN_TARGET_PS3)
  354. #if UNITY_WII
  355. // Copied from <CodeWarrior>\PowerPC_EABI_Support\MSL\MSL_C\PPC_EABI\Include\math_ppc_inlines.h
  356. // Requires hardware floating to be enabled
  357. // P.S I've also profiled with function below which uses fabs(x) == 0.0F, it's two times slower than this one
  358. inline float FastSqrt (float x)
  359. {
  360. static const double _half=.5f;
  361. static const double _three=3.0f;
  362. if(x > 0.0f)
  363. {
  364. double xd = (double)x;
  365. double guess = __frsqrte(xd); /* returns an approximation to */
  366. guess = _half*guess*(_three - guess*guess*xd); /* now have 12 sig bits */
  367. guess = _half*guess*(_three - guess*guess*xd); /* now have 24 sig bits */
  368. return (float)(xd * guess);
  369. }
  370. else if (x < 0.0)
  371. return NAN;
  372. else
  373. return x;
  374. }
  375. #else
  376. /// - Accurate to 1 bit precision
  377. /// - returns zero if x is zero
  378. inline float FastSqrt (float x)
  379. {
  380. const float half = 0.5;
  381. const float one = 1.0;
  382. float B, y0, y1;
  383. // This'll NaN if it hits frsqrte. Handle both +0.0 and -0.0
  384. if (fabs(x) == 0.0F)
  385. return x;
  386. B = x;
  387. #if defined(__GNUC__) && !defined(SN_TARGET_PS3)
  388. y0 = __frsqrtes(B);
  389. #else
  390. y0 = __frsqrte(B);
  391. #endif
  392. // First refinement step
  393. y1 = y0 + half*y0*(one - B*y0*y0);
  394. // Second refinement step -- copy the output of the last step to the input of this step
  395. y0 = y1;
  396. y1 = y0 + half*y0*(one - B*y0*y0);
  397. // Get sqrt(x) from x * 1/sqrt(x)
  398. return x * y1;
  399. }
  400. #endif
  401. /// - Accurate to 1 bit precision
  402. /// - returns zero if f is zero
  403. inline float FastInvSqrt( float f )
  404. {
  405. float result;
  406. float estimate, estimate2;
  407. float oneHalf = 0.5f;
  408. float one = oneHalf + oneHalf;
  409. //Calculate a 5 bit starting estimate for the reciprocal sqrt
  410. #if defined(__GNUC__) && !defined(SN_TARGET_PS3)
  411. estimate = estimate2 = __frsqrtes ( f );
  412. #else
  413. estimate = estimate2 = __frsqrte ( f );
  414. #endif
  415. //if you require less precision, you may reduce the number of loop iterations
  416. estimate = estimate + oneHalf * estimate * ( one - f * estimate * estimate );
  417. estimate = estimate + oneHalf * estimate * ( one - f * estimate * estimate );
  418. #if defined(__GNUC__) && !defined(SN_TARGET_PS3)
  419. result = __fsels( -f, estimate2, estimate );
  420. #else
  421. result = __fsel( -f, estimate2, estimate );
  422. #endif
  423. return result;
  424. }
  425. /// Fast inverse sqrt function
  426. inline float FastestInvSqrt (float value)
  427. {
  428. #if defined (__ppc__) && (defined (__MWERKS__) || defined(SN_TARGET_PS3))
  429. return (float)__frsqrte (value);
  430. #elif defined (__ppc__)
  431. return (float)__frsqrtes(value);
  432. #else
  433. return 1.0F / sqrtf (value);
  434. #endif
  435. }
  436. #else
  437. inline float FastSqrt (float value)
  438. {
  439. return sqrtf (value);
  440. }
  441. inline float FastInvSqrt( float f )
  442. {
  443. // The Newton iteration trick used in FastestInvSqrt is a bit faster on
  444. // Pentium4 / Windows, but lower precision. Doing two iterations is precise enough,
  445. // but actually a bit slower.
  446. if (fabs(f) == 0.0F)
  447. return f;
  448. return 1.0F / sqrtf (f);
  449. }
  450. inline float FastestInvSqrt( float f )
  451. {
  452. union
  453. {
  454. float f;
  455. int i;
  456. } u;
  457. float fhalf = 0.5f*f;
  458. u.f = f;
  459. int i = u.i;
  460. i = 0x5f3759df - (i>>1);
  461. u.i = i;
  462. f = u.f;
  463. f = f*(1.5f - fhalf*f*f);
  464. // f = f*(1.5f - fhalf*f*f); // uncommenting this would be two iterations
  465. return f;
  466. }
  467. #endif
  468. inline float SqrtImpl (float f)
  469. {
  470. #if UNITY_WII || UNITY_FLASH
  471. return FastSqrt (f);
  472. #else
  473. return sqrt (f);
  474. #endif
  475. }
  476. inline float Sin (float f)
  477. {
  478. return sinf (f);
  479. }
  480. inline float Pow (float f, float f2)
  481. {
  482. return powf (f, f2);
  483. }
  484. inline float Cos (float f)
  485. {
  486. return cosf (f);
  487. }
  488. inline float Sign (float f)
  489. {
  490. #if defined(_XBOX)
  491. return __fsel(f, 1.0f, -1.0f);
  492. #else
  493. if (f < 0.0F)
  494. return -1.0F;
  495. else
  496. return 1.0;
  497. #endif
  498. }
  499. #if UNITY_EDITOR
  500. class FloatToHalfConverter
  501. {
  502. public:
  503. FloatToHalfConverter();
  504. void Convert(const float& src, UInt16& dest)
  505. {
  506. UInt32 bits = *reinterpret_cast<const UInt32*>(&src);
  507. UInt8 index = UInt8(bits >> 23);
  508. UInt32 sign = bits & 0x80000000;
  509. UInt32 mantissa = bits & 0x007fffff;
  510. dest = (sign >> 16) | m_ExponentTable[index] | (mantissa >> m_MantissaShift[index]);
  511. }
  512. private:
  513. UInt16 m_ExponentTable[256];
  514. UInt8 m_MantissaShift[256];
  515. };
  516. extern FloatToHalfConverter g_FloatToHalf;
  517. #endif // UNITY_EDITOR
  518. #if UNITY_SUPPORTS_SSE
  519. #include "Runtime/Math/Simd/SimdMath.h"
  520. #define SSE_CONST4(name, val) static const ALIGN16 UInt32 name[4] = { (val), (val), (val), (val) }
  521. #define CONST_M128I(name) *(const __m128i *)&name
  522. static ALIGN16 UInt16 source[] = {0,0,0,0,0,0,0,0};
  523. static ALIGN16 float destination[] = {0.0,0.0,0.0,0.0};
  524. static void HalfToFloat(UInt16 src, float& dest)
  525. {
  526. SSE_CONST4(mask_nosign, 0x7fff);
  527. SSE_CONST4(smallest_normal, 0x0400);
  528. SSE_CONST4(infinity, 0x7c00);
  529. SSE_CONST4(expadjust_normal, (127 - 15) << 23);
  530. SSE_CONST4(magic_denorm, 113 << 23);
  531. source[0] = src;
  532. __m128i in = _mm_loadu_si128(reinterpret_cast<const __m128i*>(source));
  533. __m128i mnosign = CONST_M128I(mask_nosign);
  534. __m128i eadjust = CONST_M128I(expadjust_normal);
  535. __m128i smallest = CONST_M128I(smallest_normal);
  536. __m128i infty = CONST_M128I(infinity);
  537. __m128i expmant = _mm_and_si128(mnosign, in);
  538. __m128i justsign = _mm_xor_si128(in, expmant);
  539. __m128i b_notinfnan = _mm_cmpgt_epi32(infty, expmant);
  540. __m128i b_isdenorm = _mm_cmpgt_epi32(smallest, expmant);
  541. __m128i shifted = _mm_slli_epi32(expmant, 13);
  542. __m128i adj_infnan = _mm_andnot_si128(b_notinfnan, eadjust);
  543. __m128i adjusted = _mm_add_epi32(eadjust, shifted);
  544. __m128i den1 = _mm_add_epi32(shifted, CONST_M128I(magic_denorm));
  545. __m128i adjusted2 = _mm_add_epi32(adjusted, adj_infnan);
  546. __m128 den2 = _mm_sub_ps(_mm_castsi128_ps(den1), *(const __m128 *)&magic_denorm);
  547. __m128 adjusted3 = _mm_and_ps(den2, _mm_castsi128_ps(b_isdenorm));
  548. __m128 adjusted4 = _mm_andnot_ps(_mm_castsi128_ps(b_isdenorm), _mm_castsi128_ps(adjusted2));
  549. __m128 adjusted5 = _mm_or_ps(adjusted3, adjusted4);
  550. __m128i sign = _mm_slli_epi32(justsign, 16);
  551. __m128 out = _mm_or_ps(adjusted5, _mm_castsi128_ps(sign));
  552. _mm_storeu_ps(destination, out);
  553. dest = destination[0];
  554. #undef SSE_CONST4
  555. #undef CONST_M128I
  556. }
  557. #else
  558. static void HalfToFloat(UInt16 src, float& dest)
  559. {
  560. // Integer alias
  561. UInt32& bits = *reinterpret_cast<UInt32*>(&dest);
  562. // Based on Fabian Giesen's public domain half_to_float_fast3
  563. static const UInt32 magic = { 113 << 23 };
  564. const float& magicFloat = *reinterpret_cast<const float*>(&magic);
  565. static const UInt32 shiftedExp = 0x7c00 << 13; // exponent mask after shift
  566. // Mask out sign bit
  567. bits = src & 0x7fff;
  568. if (bits)
  569. {
  570. // Move exponent + mantissa to correct bits
  571. bits <<= 13;
  572. UInt32 exponent = bits & shiftedExp;
  573. if (exponent == 0)
  574. {
  575. // Handle denormal
  576. bits += magic;
  577. dest -= magicFloat;
  578. }
  579. else if (exponent == shiftedExp) // Inf/NaN
  580. bits += (255 - 31) << 23;
  581. else
  582. bits += (127 - 15) << 23;
  583. }
  584. // Copy sign bit
  585. bits |= (src & 0x8000) << 16;
  586. }
  587. #endif
  588. using std::cos;
  589. using std::pow;
  590. using std::atan2;
  591. using std::acos;
  592. using std::sin;
  593. using std::sqrt;
  594. using std::log;
  595. using std::exp;
  596. // On non-C99 platforms log2 is not available, so approximate it.
  597. #if UNITY_WIN || UNITY_XENON || UNITY_ANDROID || UNITY_FLASH || UNITY_WEBGL
  598. #define kNaturalLogarithm2 0.693147180559945309417
  599. #define Log2(x) (logf(x) / kNaturalLogarithm2)
  600. #else
  601. #define Log2(x) log2f(x)
  602. #endif
  603. NS_RRP_END
  604. #endif /* FloatConversion_h */