diff options
-rw-r--r-- | floatprops.h | 13 | ||||
-rw-r--r-- | test.cc | 1 | ||||
-rw-r--r-- | vec_builtin.h | 12 | ||||
-rw-r--r-- | vec_pseudo.h | 14 |
4 files changed, 22 insertions, 18 deletions
diff --git a/floatprops.h b/floatprops.h index c39c788..2a50c1a 100644 --- a/floatprops.h +++ b/floatprops.h @@ -11,7 +11,6 @@ #include <iostream> #include <limits> #include <sstream> -#include <typeinfo> @@ -38,7 +37,11 @@ namespace vecmathlib { typedef int8_t int_t; typedef uint8_t uint_t; + static char const* name() { return "fp8"; } + // Definitions that might come from numeric_limits<> instead: + static int min() { __builtin_unreachable(); } + static int max() { __builtin_unreachable(); } static int const digits = 4; static int epsilon() { __builtin_unreachable(); } static int const min_exponent = -6; @@ -94,7 +97,11 @@ namespace vecmathlib { typedef int16_t int_t; typedef uint16_t uint_t; + static char const* name() { return "fp16"; } + // Definitions that might come from numeric_limits<> instead: + static int min() { __builtin_unreachable(); } + static int max() { __builtin_unreachable(); } static int const digits = 11; static int epsilon() { __builtin_unreachable(); } static int const min_exponent = -14; @@ -150,6 +157,8 @@ namespace vecmathlib { typedef int32_t int_t; typedef uint32_t uint_t; + static char const* name() { return "float"; } + // Ensure the internal representation is what we expect static_assert(is_signed, "real_t is not signed"); static_assert(radix==2, "real_t is not binary"); @@ -222,6 +231,8 @@ namespace vecmathlib { typedef int64_t int_t; typedef uint64_t uint_t; + static char const* name() { return "double"; } + // Ensure the internal representation is what we expect static_assert(is_signed, "real_t is not signed"); static_assert(radix==2, "real_t is not binary"); @@ -7,7 +7,6 @@ #include <cstdlib> #include <iomanip> #include <iostream> -#include <typeinfo> using namespace std; diff --git a/vec_builtin.h b/vec_builtin.h index 3765604..519aa86 100644 --- a/vec_builtin.h +++ b/vec_builtin.h @@ -10,8 +10,8 @@ #include <algorithm> #include <cmath> #include <cstring> +#include <sstream> #include <string> -#include <typeinfo> @@ -311,12 +311,10 @@ namespace vecmathlib { static char const* name() { static std::string name_; - if (name_.length()==0) { - std::string base; - if (typeid(T) == typeid(float)) base = "float"; - else if (typeid(T) == typeid(double)) base = "double"; - else base = typeid(T).name(); - name_ = std::string("<builtin:") + std::to_string(N) + "*" + base + ">"; + if (name_.empty()) { + stringstream buf; + buf << "<builtin:" << N << "*" << FP::name() << ">"; + name_ = buf.str(); } return name_.c_str(); } diff --git a/vec_pseudo.h b/vec_pseudo.h index 074491f..31d9cbb 100644 --- a/vec_pseudo.h +++ b/vec_pseudo.h @@ -10,10 +10,10 @@ #include <algorithm> #include <cmath> #include <string> -#include <typeinfo> #include <sstream> + namespace vecmathlib { template<typename T, int N> struct boolpseudovec; @@ -378,14 +378,10 @@ namespace vecmathlib { static char const* name() { static std::string name_; - if (name_.length()==0) { - std::string base; - if (typeid(T) == typeid(float)) base = "float"; - else if (typeid(T) == typeid(double)) base = "double"; - else base = typeid(T).name(); - stringstream ss; - ss << "<libm:" << N << "*" << base << ">"; - name_ = ss.str(); + if (name_.empty()) { + stringstream buf; + buf << "<libm:" << N << "*" << FP::name() << ">"; + name_ = buf.str(); } return name_.c_str(); } |