Changeset 2056
- Timestamp:
- Nov 2, 2012, 11:45:02 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lol/math/half.h
r2054 r2056 121 121 static inline half min(half a, half b) { return a < b ? a : b; } 122 122 static inline half max(half a, half b) { return a > b ? a : b; } 123 static inline half fmod(half a, half b) { return (half)fmod((float)a, (float)b); } 123 static inline half fmod(half a, half b) 124 { 125 using std::fmod; 126 return (half)fmod((float)a, (float)b); 127 } 124 128 static inline half abs(half a) { return half::makebits(a.bits & 0x7fffu); } 125 129 -
trunk/src/lol/math/math.h
r1888 r2056 19 19 #include <cmath> 20 20 #include <cstdio> 21 #include <algorithm> 22 21 23 #include <stdint.h> 22 24 23 25 namespace lol 24 26 { 27 28 /* This is OUR namespace. Don't let Windows headers fuck with it. */ 29 #undef min 30 #undef max 31 32 /* There are many reasons for wanting single-word type names, the most 33 * important one being compilation speedups in our vector.h: we can hide 34 * some global methods in namespaces that contain the name of the type, 35 * but namespaces cannot have spaces in their names. */ 36 typedef long double ldouble; 25 37 26 38 /* Standard cmath functions */ … … 65 77 } 66 78 79 static inline float lerp(float const &a, float const &b, float const &x) 80 { 81 return a + (b - a) * x; 82 } 83 67 84 static inline double lerp(double const &a, double const &b, double const &x) 68 85 { 69 86 return a + (b - a) * x; 70 87 } 71 static inline float lerp(float const &a, float const &b, float const &x) 88 89 static inline ldouble lerp(ldouble const &a, ldouble const &b, ldouble const &x) 72 90 { 73 91 return a + (b - a) * x; … … 86 104 double lol_atan2(double, double); 87 105 106 /* C++ doesn't define abs() and fmod() for all types; we add these for 107 * convenience to avoid adding complexity to vector.h. */ 108 static inline int8_t abs(int8_t x) { return std::abs(x); } 109 static inline uint8_t abs(uint8_t x) { return x; } 110 static inline int16_t abs(int16_t x) { return std::abs(x); } 111 static inline uint16_t abs(uint16_t x) { return x; } 112 static inline int32_t abs(int32_t x) { return std::abs(x); } 113 static inline uint32_t abs(uint32_t x) { return x; } 114 static inline int64_t abs(int64_t x) { return std::abs(x); } 115 static inline uint64_t abs(uint64_t x) { return x; } 116 static inline float abs(float x) { return std::abs(x); } 117 static inline double abs(double x) { return std::abs(x); } 118 static inline ldouble abs(ldouble x) { return std::abs(x); } 119 120 static inline uint8_t fmod(uint8_t x, uint8_t y) { return x % y; } 121 static inline int8_t fmod(int8_t x, int8_t y) { return x % y; } 122 static inline uint16_t fmod(uint16_t x, uint16_t y) { return x % y; } 123 static inline int16_t fmod(int16_t x, int16_t y) { return x % y; } 124 static inline uint32_t fmod(uint32_t x, uint32_t y) { return x % y; } 125 static inline int32_t fmod(int32_t x, int32_t y) { return x % y; } 126 static inline uint64_t fmod(uint64_t x, uint64_t y) { return x % y; } 127 static inline int64_t fmod(int64_t x, int64_t y) { return x % y; } 128 static inline float fmod(float x, float y) { return std::fmod(x, y); } 129 static inline double fmod(double x, double y) { return std::fmod(x, y); } 130 static inline ldouble fmod(ldouble x, ldouble y) { return std::fmod(x, y); } 131 132 static inline uint8_t min(uint8_t x, uint8_t y) { return std::min(x, y); } 133 static inline int8_t min(int8_t x, int8_t y) { return std::min(x, y); } 134 static inline uint16_t min(uint16_t x, uint16_t y) { return std::min(x, y); } 135 static inline int16_t min(int16_t x, int16_t y) { return std::min(x, y); } 136 static inline uint32_t min(uint32_t x, uint32_t y) { return std::min(x, y); } 137 static inline int32_t min(int32_t x, int32_t y) { return std::min(x, y); } 138 static inline uint64_t min(uint64_t x, uint64_t y) { return std::min(x, y); } 139 static inline int64_t min(int64_t x, int64_t y) { return std::min(x, y); } 140 static inline float min(float x, float y) { return std::min(x, y); } 141 static inline double min(double x, double y) { return std::min(x, y); } 142 static inline ldouble min(ldouble x, ldouble y) { return std::min(x, y); } 143 144 static inline uint8_t max(uint8_t x, uint8_t y) { return std::max(x, y); } 145 static inline int8_t max(int8_t x, int8_t y) { return std::max(x, y); } 146 static inline uint16_t max(uint16_t x, uint16_t y) { return std::max(x, y); } 147 static inline int16_t max(int16_t x, int16_t y) { return std::max(x, y); } 148 static inline uint32_t max(uint32_t x, uint32_t y) { return std::max(x, y); } 149 static inline int32_t max(int32_t x, int32_t y) { return std::max(x, y); } 150 static inline uint64_t max(uint64_t x, uint64_t y) { return std::max(x, y); } 151 static inline int64_t max(int64_t x, int64_t y) { return std::max(x, y); } 152 static inline float max(float x, float y) { return std::max(x, y); } 153 static inline double max(double x, double y) { return std::max(x, y); } 154 static inline ldouble max(ldouble x, ldouble y) { return std::max(x, y); } 155 88 156 } /* namespace lol */ 89 157 -
trunk/src/lol/math/vector.h
r2054 r2056 19 19 #include <stdint.h> 20 20 #include <ostream> 21 #include <algorithm>22 21 23 22 #include "lol/math/math.h" … … 27 26 namespace lol 28 27 { 29 30 /* This is OUR namespace. Don't let Windows headers fuck with it. */31 #undef min32 #undef max33 28 34 29 /* Some compilers do not support const members in anonymous unions. So … … 40 35 #endif 41 36 42 /* Hack for compilation speedups: we can hide some of our global methods in43 * namespaces. We therefore want "long_double" to be a single-word name */44 typedef long double long_double;45 46 37 #define DECLARE_VECTOR_TYPEDEFS(tname, suffix) \ 47 38 template <typename T> struct tname; \ … … 49 40 typedef tname<float> suffix; \ 50 41 typedef tname<double> d##suffix; \ 51 typedef tname<l ong_double> f128##suffix; \42 typedef tname<ldouble> f128##suffix; \ 52 43 typedef tname<int8_t> i8##suffix; \ 53 44 typedef tname<uint8_t> u8##suffix; \ … … 1074 1065 inline tname<type> op(tname<type> const &a, tname<type> const &b) \ 1075 1066 { \ 1076 using std::op; \1067 using lol::op; \ 1077 1068 tname<type> ret; \ 1078 1069 for (size_t n = 0; n < sizeof(a) / sizeof(type); n++) \ … … 1084 1075 inline tname<type> op(tname<type> const &a, type const &b) \ 1085 1076 { \ 1086 using std::op; \1077 using lol::op; \ 1087 1078 tname<type> ret; \ 1088 1079 for (size_t n = 0; n < sizeof(a) / sizeof(type); n++) \ … … 1094 1085 inline tname<type> op(type const &a, tname<type> const &b) \ 1095 1086 { \ 1096 using std::op; \1087 using lol::op; \ 1097 1088 tname<type> ret; \ 1098 1089 for (size_t n = 0; n < sizeof(b) / sizeof(type); n++) \ … … 1228 1219 inline tname<type> abs(tname<type> const &a) \ 1229 1220 { \ 1230 using std::abs; \1231 1221 tname<type> ret; \ 1232 1222 for (size_t n = 0; n < sizeof(a) / sizeof(type); n++) \ 1233 ret[n] = abs(a[n]); \1223 ret[n] = lol::abs(a[n]); \ 1234 1224 return ret; \ 1235 1225 } … … 1361 1351 DECLARE_ALL_VECTOR_OPS(float) 1362 1352 DECLARE_ALL_VECTOR_OPS(double) 1363 DECLARE_ALL_VECTOR_OPS(l ong_double)1353 DECLARE_ALL_VECTOR_OPS(ldouble) 1364 1354 DECLARE_ALL_VECTOR_OPS(int8_t) 1365 1355 DECLARE_ALL_VECTOR_OPS(uint8_t) … … 1402 1392 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, float) 1403 1393 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, double) 1404 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, l ong_double)1394 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, ldouble) 1405 1395 1406 1396 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, int16_t) … … 1412 1402 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, float) 1413 1403 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, double) 1414 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, l ong_double)1404 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, ldouble) 1415 1405 1416 1406 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, uint16_t) … … 1421 1411 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, float) 1422 1412 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, double) 1423 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, l ong_double)1413 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, ldouble) 1424 1414 1425 1415 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, int32_t) … … 1429 1419 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, float) 1430 1420 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, double) 1431 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, l ong_double)1421 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, ldouble) 1432 1422 1433 1423 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, uint32_t) … … 1436 1426 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, float) 1437 1427 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, double) 1438 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, l ong_double)1428 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, ldouble) 1439 1429 1440 1430 DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, int64_t) … … 1442 1432 DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, float) 1443 1433 DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, double) 1444 DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, l ong_double)1434 DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, ldouble) 1445 1435 1446 1436 DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, uint64_t) 1447 1437 DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, float) 1448 1438 DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, double) 1449 DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, l ong_double)1439 DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, ldouble) 1450 1440 1451 1441 DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, float) 1452 1442 DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, double) 1453 DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, l ong_double)1443 DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, ldouble) 1454 1444 1455 1445 DECLARE_ALL_VECTOR_COERCE_OPS(float, double) 1456 DECLARE_ALL_VECTOR_COERCE_OPS(float, l ong_double)1457 1458 DECLARE_ALL_VECTOR_COERCE_OPS(double, l ong_double)1446 DECLARE_ALL_VECTOR_COERCE_OPS(float, ldouble) 1447 1448 DECLARE_ALL_VECTOR_COERCE_OPS(double, ldouble) 1459 1449 1460 1450 /* FIXME: vectors of "half" are deactivated for now, because they … … 1475 1465 DECLARE_ALL_VECTOR_COERCE_OPS(half, float) 1476 1466 DECLARE_ALL_VECTOR_COERCE_OPS(half, double) 1477 DECLARE_ALL_VECTOR_COERCE_OPS(half, l ong_double)1467 DECLARE_ALL_VECTOR_COERCE_OPS(half, ldouble) 1478 1468 #endif 1479 1469 … … 1494 1484 DECLARE_ALL_VECTOR_COERCE_OPS(float, real) 1495 1485 DECLARE_ALL_VECTOR_COERCE_OPS(double, real) 1496 DECLARE_ALL_VECTOR_COERCE_OPS(l ong_double, real)1486 DECLARE_ALL_VECTOR_COERCE_OPS(ldouble, real) 1497 1487 #endif 1498 1488 … … 1519 1509 ACTIVATE_COERCE_NAMESPACES_INNER(tlow, float) \ 1520 1510 ACTIVATE_COERCE_NAMESPACES_INNER(tlow, double) \ 1521 ACTIVATE_COERCE_NAMESPACES_INNER(tlow, l ong_double) \1511 ACTIVATE_COERCE_NAMESPACES_INNER(tlow, ldouble) \ 1522 1512 ACTIVATE_COERCE_NAMESPACES_INNER(tlow, real) 1523 1513 … … 1533 1523 ACTIVATE_COERCE_NAMESPACES(float) 1534 1524 ACTIVATE_COERCE_NAMESPACES(double) 1535 ACTIVATE_COERCE_NAMESPACES(l ong_double)1525 ACTIVATE_COERCE_NAMESPACES(ldouble) 1536 1526 ACTIVATE_COERCE_NAMESPACES(real) 1537 1527 -
trunk/test/math/poly.cpp
r1893 r2056 124 124 union { float f; uint32_t x; } s1 = { sinf(adjustf(u.f, 0)) }; 125 125 union { float f; uint32_t x; } s2 = { floatsin(adjustf(u.f, 0)) }; 126 int e = abs((int)(s1.x - s2.x));126 int e = lol::abs((int)(s1.x - s2.x)); 127 127 switch (e) 128 128 { … … 133 133 printf("sinf: "); 134 134 inspect(sinf(u.f)); 135 if ( fabs((double)s1.f - (double)s2.f) > 1e-10 * fabs(s1.f))135 if (lol::abs((double)s1.f - (double)s2.f) > 1e-10 * lol::abs(s1.f)) 136 136 printf("%15.13g %08x: %15.13g %15.13g %08x %08x\n", u.f, u.x, s1.f, s2.f, s1.x, s2.x); 137 137 case 0: -
trunk/tutorial/11_fractal.cpp
r1992 r2056 216 216 { 217 217 m_zoom_speed *= std::pow(2.0, -seconds * 5.0); 218 if ( abs(m_zoom_speed) < 1e-5 || m_drag)218 if (lol::abs(m_zoom_speed) < 1e-5 || m_drag) 219 219 m_zoom_speed = 0.0; 220 220 }
Note: See TracChangeset
for help on using the changeset viewer.