X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fparanoidnumber.h;h=29e15d599dd73f3f14f4d6dc3be997dee02a33cc;hp=3a38286ae706d03bd9babe981cb02c235458bd8b;hb=6c0dfe752994312ee58d307b383948bfeb2d6e2e;hpb=b29310a04a51cd7d39d0858e2dec8a75c15cf097 diff --git a/src/paranoidnumber.h b/src/paranoidnumber.h index 3a38286..29e15d5 100644 --- a/src/paranoidnumber.h +++ b/src/paranoidnumber.h @@ -12,18 +12,18 @@ #include // it's going to be ok #include -#define PARANOID_DIGIT_T float // we could theoretically replace this with a template +#define PARANOID_DIGIT_T double // we could theoretically replace this with a template // but let's not do that... //#define PARANOID_CACHE_RESULTS //#define PARANOID_USE_ARENA -#define PARANOID_SIZE_LIMIT 10 +#define PARANOID_SIZE_LIMIT 4 // Define to compare all ops against double ops and check within epsilon -//#define PARANOID_COMPARE_EPSILON 1e- +//#define PARANOID_COMPARE_EPSILON 1e-6 #ifdef PARANOID_COMPARE_EPSILON #define CompareForSanity(...) ParanoidNumber::CompareForSanityEx(__func__, __FILE__, __LINE__, __VA_ARGS__) #endif @@ -93,6 +93,7 @@ namespace IPDF #endif #ifdef PARANOID_CACHE_RESULTS m_cached_result = value; + m_cache_valid = true; #endif } @@ -104,6 +105,7 @@ namespace IPDF #endif #ifdef PARANOID_CACHE_RESULTS m_cached_result = cpy.m_cached_result; + m_cache_valid = cpy.m_cache_valid; #endif for (int i = 0; i < NOP; ++i) { @@ -143,6 +145,8 @@ namespace IPDF // Like this one. It isn't const. double ToDouble() const {return (double)Digit();} + operator double() const {return ToDouble();} + // This one is probably const. bool Floating() const { @@ -265,6 +269,7 @@ namespace IPDF digit_t m_value; #ifdef PARANOID_CACHE_RESULTS digit_t m_cached_result; + bool m_cache_valid; #endif std::vector m_next[4]; #ifdef PARANOID_SIZE_LIMIT @@ -275,7 +280,7 @@ namespace IPDF class Arena { public: - Arena(int64_t block_size = 10000000); + Arena(int64_t block_size = 10000); ~Arena(); void * allocate(size_t bytes); @@ -308,7 +313,7 @@ template T ParanoidNumber::Convert() const { #ifdef PARANOID_CACHE_RESULTS - if (!isnan((float(m_cached_result)))) + if (m_cache_valid) return (T)m_cached_result; #endif T value(m_value); @@ -329,6 +334,8 @@ T ParanoidNumber::Convert() const + + } #endif //_PARANOIDNUMBER_H