19 return sizeof(value) * 8 - 1 - LargeIntegerCLZHelper<T>::clz(value);
22 template<
typename CharT,
typename B,
unsigned int F> std::basic_ostream<CharT>&
operator<<(std::basic_ostream<CharT>&
os,
FixedPoint<B, F> x)
noexcept {
23 const auto uppercase = ((
os.flags() & std::ios_base::uppercase) != 0);
24 const auto showpoint = ((
os.flags() & std::ios_base::showpoint) != 0);
25 const auto adjustfield = (
os.flags() & std::ios_base::adjustfield);
26 const auto width =
os.width();
27 const auto&
ctype = std::use_facet<std::ctype<CharT>>(
os.getloc());
28 const auto&
numpunct = std::use_facet<std::numpunct<CharT>>(
os.getloc());
30 auto floatfield = (
os.flags() & std::ios_base::floatfield);
52 using BufferType = std::array<CharT, worstCaseConstantSize + worstCaseDigitCount * 2 + worstCaseSuffixSize>;
56 auto end = buffer.begin();
59 typename BufferType::iterator
internalPad = buffer.end();
73 assert(value.exponent == 0);
75 while(value.raw / 10 >= value.divisor) {
79 while(value.raw < value.divisor) {
94 value.raw = -value.raw;
96 }
else if(
os.flags() & std::ios_base::showpos) {
103 case std::ios_base::fixed | std::ios_base::scientific:
107 value.exponent =
bit -
F;
108 value.divisor =
B{1} <<
bit;
118 case std::ios_base::scientific:
123 case std::ios_base::fixed:
157 value.raw %= value.divisor;
160 const char*
const digits =
uppercase ?
"0123456789ABCDEF" :
"0123456789abcdef";
193 assert(value.raw < value.divisor);
197 typename BufferType::iterator point = buffer.end();
219 if(value.divisor % base == 0) {
220 value.divisor /= base;
224 assert(value.divisor > 0);
226 lastDigit = (value.raw / value.divisor) % base;
227 value.raw %= value.divisor;
248 assert(position >= buffer.begin() && position < end);
249 std::move_backward(position, end, end + 1);
250 if(point != buffer.end() && position < point) {
261 bool increment =
false;
262 if(value.raw > value.divisor / 2) {
265 }
else if(value.raw == value.divisor / 2) {
278 if((*p)++ !=
ctype.widen(
'9')) {
281 *p-- =
ctype.widen(
'0');
294 if(point != buffer.end()) {
296 std::swap(*(point - 1), *point);
314 if(point != buffer.end()) {
317 while(*(end - 1) ==
ctype.widen(
'0')) {
338 std::size_t
group = 0;
339 auto p = point != buffer.end() ? point :
end;
360 if(value.exponent < 0) {
362 value.exponent = -value.exponent;
369 if(value.exponent < 10) {
375 if(value.exponent == 0) {
378 while(value.exponent > 0) {
379 *
end++ =
ctype.widen(digits[value.exponent % 10]);
380 value.exponent /= 10;
388 constexpr std::streamsize
chunkSize = 64;
389 std::array<CharT, chunkSize> fillBuffer;
392 for(std::streamsize size, left =
count; left > 0; left -= size) {
394 os.rdbuf()->sputn(&fillBuffer[0], size);
400 const auto putRange = [&](
typename BufferType::const_iterator
begin,
typename BufferType::const_iterator
end) {
410 os.rdbuf()->sputn(&*begin, end - begin);
423 case std::ios_base::left:
428 case std::ios_base::internal:
449 template<
typename CharT,
class Traits,
typename B,
unsigned int F>
451 const typename std::basic_istream<CharT, Traits>::sentry
sentry(is);
456 const auto&
ctype = std::use_facet<std::ctype<CharT>>(is.getloc());
457 const auto&
numpunct = std::use_facet<std::numpunct<CharT>>(is.getloc());
465 return std::isxdigit(
ch) ||
ch ==
'x' ||
ch ==
'X' ||
ch ==
'p' ||
ch ==
'P' ||
ch ==
'i' ||
ch ==
'I' ||
ch ==
'n' ||
ch ==
'N' ||
ch ==
't' ||
466 ch ==
'T' ||
ch ==
'y' ||
ch ==
'Y' ||
ch ==
'-' ||
ch ==
'+';
469 const auto& peek = [&]() {
471 auto ch = is.rdbuf()->sgetc();
472 if(
ch == Traits::eof()) {
473 is.setstate(std::ios::eofbit);
484 is.rdbuf()->sbumpc();
496 const auto&
bump = [&]() {
497 is.rdbuf()->sbumpc();
500 const auto& next = [&]() {
510 }
else if(
ch ==
'+') {
514 const char infinity[] =
"infinity";
517 while(index < 8 &&
ch == infinity[index]) {
523 if(index == 3 || index == 8) {
524 x = negate ? std::numeric_limits<FixedPoint<B, F>>::min() : std::numeric_limits<FixedPoint<B, F>>::max();
526 is.setstate(std::ios::failbit);
534 constexpr auto noFraction = std::numeric_limits<std::size_t>::max();
540 if(
ch ==
'x' ||
ch ==
'X') {
552 for(;;
ch = next()) {
561 unsigned char val = base;
562 if(
ch >=
'0' &&
ch <=
'9') {
564 }
else if(
ch >=
'a' &&
ch <=
'f') {
566 }
else if(
ch >=
'A' &&
ch <=
'F') {
577 is.setstate(std::ios::failbit);
596 }
else if(
ch ==
'+') {
601 while(std::isdigit(
ch)) {
602 if(
exponent <= std::numeric_limits<int>::max() / 10) {
612 is.setstate(std::ios::failbit);
628 x = std::numeric_limits<FixedPoint<B, F>>::max();
647 constexpr auto isSigned = std::is_signed<B>::value;
651 constexpr auto maxValue = (
B{1} <<
sizeof(
B) * 8) - 1;
658 x = negate ? std::numeric_limits<FixedPoint<B, F>>::min() : std::numeric_limits<FixedPoint<B, F>>::max();
693 for(std::size_t e = 0; e <
exponent; ++e) {
699 for(std::size_t e = 0; e <
exponent; ++e) {
702 x = negate ? std::numeric_limits<FixedPoint<B, F>>::min() : std::numeric_limits<FixedPoint<B, F>>::max();
Iterator< Generator > end(const Generator &) noexcept
Returns a dummy end iterator.
Definition Iterator.hpp:82
Iterator< Generator > begin(Generator &generator) noexcept
Will return an iterator to the generator.
Definition Iterator.hpp:79
BufferType
Definition ASTEnums.hpp:492
Definition Application.hpp:19
constexpr Byte operator>>(const Byte arg, const _IntType shift) noexcept
Definition DataTypes.hpp:51
long findHighestBit(T value) noexcept
Definition FixedPoint.Stream.hpp:18
constexpr Byte operator<<(const Byte arg, const _IntType shift) noexcept
Definition DataTypes.hpp:44
constexpr CountAlgorithmFunctor count
Returns the number of elements matching an element.
Definition Count.hpp:82
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25