diff options
author | Erik Schnetter <schnetter@gmail.com> | 2013-03-21 21:55:31 -0400 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2013-03-21 21:55:31 -0400 |
commit | b1d2de5c21180748ba9ce25dd650b85cfa807fa8 (patch) | |
tree | 1d4503d121ab7be8c9d614d678489b852b002e4e /floatprops.h | |
parent | 30e0b1ccfe1dc82f89c68d7ef9cf8fc1212458f5 (diff) | |
download | vecmathlib-b1d2de5c21180748ba9ce25dd650b85cfa807fa8.zip vecmathlib-b1d2de5c21180748ba9ce25dd650b85cfa807fa8.tar.gz |
Correct rounding and conversion functions
Diffstat (limited to 'floatprops.h')
-rw-r--r-- | floatprops.h | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/floatprops.h b/floatprops.h index 2a50c1a..99deebf 100644 --- a/floatprops.h +++ b/floatprops.h @@ -83,7 +83,7 @@ namespace vecmathlib { return res; } - // Convert values + // Convert values (truncate) static real_t convert_float(int_t x) { __builtin_unreachable(); } static int_t convert_int(real_t x) { __builtin_unreachable(); } }; @@ -143,7 +143,7 @@ namespace vecmathlib { return res; } - // Convert values + // Convert values (truncate) static real_t convert_float(int_t x) { __builtin_unreachable(); } static int_t convert_int(real_t x) { __builtin_unreachable(); } }; @@ -204,22 +204,9 @@ namespace vecmathlib { return res; } - // Convert values + // Convert values (truncate) static real_t convert_float(int_t x) { return real_t(x); } - static int_t convert_int(real_t x) - { - static_assert(sizeof std::lrint(x) >= sizeof(int_t), - "lrint() has wrong return type"); - long res = std::lrint(x); - if (sizeof std::lrint(x) > sizeof(int_t)) { - if (res < std::numeric_limits<int_t>::min() || - res > std::numeric_limits<int_t>::max()) - { - return std::numeric_limits<int_t>::min(); - } - } - return res; - } + static int_t convert_int(real_t x) { return int_t(x); } }; @@ -278,22 +265,9 @@ namespace vecmathlib { return res; } - // Convert values + // Convert values (truncate) static real_t convert_float(int_t x) { return real_t(x); } - static int_t convert_int(real_t x) - { - static_assert(sizeof std::lrint(x) >= sizeof(int_t), - "lrint() has wrong return type"); - long res = std::lrint(x); - if (sizeof std::lrint(x) > sizeof(int_t)) { - if (res < std::numeric_limits<int_t>::min() || - res > std::numeric_limits<int_t>::max()) - { - return std::numeric_limits<int_t>::min(); - } - } - return res; - } + static int_t convert_int(real_t x) { return int_t(x); } }; |