70 template <
typename UIntegerType>
85 inline operator float()
const;
86 inline operator double()
const;
124 bool Write(std::ofstream& output)
const;
141 template <
typename IEEE>
145 template <
typename IEEE>
146 typename IEEE::FloatType
ConvertTo()
const;
148 template <
typename IEEE>
149 typename IEEE::UIntType
GetTrailing(int32_t normal, int32_t sigma)
const;
151 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 171 template <
typename UIntegerType>
177 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 178 mValue = (double)*
this;
182 template <
typename UIntegerType>
188 template <
typename UIntegerType>
191 ConvertFrom<IEEEBinary32>(number);
192 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 193 mValue = (double)*
this;
197 template <
typename UIntegerType>
200 ConvertFrom<IEEEBinary64>(number);
201 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 202 mValue = (double)*
this;
206 template <
typename UIntegerType>
229 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 230 mValue = (double)*
this;
234 template <
typename UIntegerType>
248 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 249 mValue = (double)*
this;
253 template <
typename UIntegerType>
276 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 277 mValue = (double)*
this;
281 template <
typename UIntegerType>
295 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 296 mValue = (double)*
this;
300 template <
typename UIntegerType>
inline 303 return ConvertTo<IEEEBinary32>();
306 template <
typename UIntegerType>
309 return ConvertTo<IEEEBinary64>();
312 template <
typename UIntegerType>
319 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 320 mValue = number.mValue;
325 template <
typename UIntegerType>
328 *
this = std::move(number);
331 template <
typename UIntegerType>
334 mSign = number.mSign;
338 number.mBiasedExponent = 0;
339 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 340 mValue = number.mValue;
345 template <
typename UIntegerType>
inline 351 template <
typename UIntegerType>
inline 357 template <
typename UIntegerType>
inline 363 template <
typename UIntegerType>
inline 369 template <
typename UIntegerType>
375 template <
typename UIntegerType>
381 template <
typename UIntegerType>
386 if (number.
mSign <= 0)
396 if (number.
mSign >= 0)
406 return number.
mSign > 0;
410 template <
typename UIntegerType>
416 template <
typename UIntegerType>
422 template <
typename UIntegerType>
428 template <
typename UIntegerType>
434 template <
typename UIntegerType>
439 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 440 result.mValue = (double)result;
445 template <
typename UIntegerType>
515 template <
typename UIntegerType>
585 template <
typename UIntegerType>
597 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 598 result.mValue = (double)result;
603 template <
typename UIntegerType>
611 template <
typename UIntegerType>
619 template <
typename UIntegerType>
627 template <
typename UIntegerType>
630 if (output.write((
char const*)&
mSign,
sizeof(
mSign)).bad())
644 template <
typename UIntegerType>
647 if (input.read((
char*)&
mSign,
sizeof(
mSign)).bad())
660 template <
typename UIntegerType>
668 template <
typename UIntegerType>
684 template <
typename UIntegerType>
710 result.
mSign = resultSign;
711 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 712 result.mValue = (double)result;
717 template <
typename UIntegerType>
743 result.
mSign = resultSign;
744 #if defined(GTE_BINARY_SCIENTIFIC_SHOW_DOUBLE) 745 result.mValue = (double)result;
750 template <
typename UIntegerType>
751 template <
typename IEEE>
757 typename IEEE::UIntType
s = x.GetSign();
758 typename IEEE::UIntType e = x.GetBiased();
759 typename IEEE::UIntType
t = x.GetTrailing();
773 int32_t diff = IEEE::NUM_TRAILING_BITS - last;
774 mSign = (s > 0 ? -1 : 1);
779 else if (e < IEEE::MAX_BIASED_EXPONENT)
785 int32_t diff = IEEE::NUM_TRAILING_BITS - last;
786 mSign = (s > 0 ? -1 : 1);
788 static_cast<int32_t
>(e)-IEEE::EXPONENT_BIAS - diff;
789 mUInteger = ((t | IEEE::SUP_TRAILING) >> last);
793 mSign = (s > 0 ? -1 : 1);
807 mSign = (s > 0 ? -1 : 1);
815 "quiet" :
"signaling") +
" NaN with payload " +
816 std::to_string(t & IEEE::NAN_PAYLOAD_MASK) +
".");
825 template <
typename UIntegerType>
826 template <
typename IEEE>
829 typename IEEE::UIntType
s = (
mSign < 0 ? 1 : 0);
830 typename IEEE::UIntType e,
t;
836 if (exponent < IEEE::MIN_EXPONENT)
838 if (exponent < IEEE::MIN_EXPONENT - 1
852 else if (exponent < IEEE::MIN_SUB_EXPONENT)
855 t = GetTrailing<IEEE>(0, IEEE::MIN_SUB_EXPONENT - exponent - 1);
856 if (t & IEEE::SUP_TRAILING)
868 else if (exponent <= IEEE::EXPONENT_BIAS)
870 e =
static_cast<uint32_t
>(exponent + IEEE::EXPONENT_BIAS);
871 t = GetTrailing<IEEE>(1, 0);
872 if (t & (IEEE::SUP_TRAILING << 1))
880 t &= ~IEEE::SUP_TRAILING;
885 e = IEEE::MAX_BIASED_EXPONENT;
900 template <
typename UIntegerType>
901 template <
typename IEEE>
905 int32_t
const numRequested = IEEE::NUM_SIGNIFICAND_BITS + normal;
909 uint64_t prefix =
mUInteger.GetPrefix(numRequested);
912 int32_t diff = numRequested - sigma;
913 int32_t roundBitIndex = 64 - diff;
925 if (prefix & (mask << 1))
953 uint64_t trailing = prefix >> (roundBitIndex + 1);
957 return static_cast<typename IEEE::UIntType
>(trailing);
965 template <
typename UIntegerType>
inline 968 return (number.
GetSign() >= 0 ? number : -number);
bool operator==(BSNumber const &number) const
static BSNumber AddIgnoreSign(BSNumber const &n0, BSNumber const &n1, int32_t resultSign)
bool operator>(BSNumber const &number) const
BSNumber operator+() const
GTE_IMPEXP int32_t GetTrailingBit(uint32_t value)
BSNumber & operator-=(BSNumber const &number)
void ConvertFrom(typename IEEE::FloatType number)
UIntegerType const & GetUInteger() const
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
bool operator!=(BSNumber const &number) const
static bool EqualIgnoreSign(BSNumber const &n0, BSNumber const &n1)
BSNumber operator-() const
friend class UnitTestBSNumber
int32_t GetExponent() const
bool operator<(BSNumber const &number) const
bool operator<=(BSNumber const &number) const
GLsizei const GLchar *const * string
#define LogError(message)
bool Write(std::ofstream &output) const
bool operator>=(BSNumber const &number) const
#define LogWarning(message)
BSNumber operator*(BSNumber const &number) const
IEEE::FloatType ConvertTo() const
int32_t GetBiasedExponent() const
BSNumber & operator=(BSNumber const &number)
GLenum GLenum GLenum input
bool Read(std::ifstream &input)
static bool LessThanIgnoreSign(BSNumber const &n0, BSNumber const &n1)
static BSNumber SubIgnoreSign(BSNumber const &n0, BSNumber const &n1, int32_t resultSign)
BSNumber & operator+=(BSNumber const &number)
IEEE::UIntType GetTrailing(int32_t normal, int32_t sigma) const
BSNumber & operator*=(BSNumber const &number)