HRCore V1.1.0
A High Resolution Calculation Library
Loading...
Searching...
No Matches
Value.hpp
Go to the documentation of this file.
1
9#ifndef __HRCORE_VALUE_HPP__
10#define __HRCORE_VALUE_HPP__
11
12#include "../HRCore.h"
13
14namespace HRCore {
15
20namespace Value {
27 class Integer {
28 public:
34 public:
37 {
38 auto x = this->q_data;
39 this->q_data = nullptr;
40 return Integer(x, this->positive, true, true);
41 }
42
45 {
46 auto x = this->r_data;
47 this->r_data = nullptr;
48 return Integer(x, this->positive, true, true);
49 }
50
52 void clear()
53 {
54 if (this->q_data)
55 this->q_data->delObject(this->q_data);
56 if (this->r_data)
57 this->r_data->delObject(this->r_data);
58 return;
59 }
60
61 protected:
62 Storage::Interface* q_data = nullptr;
63 Storage::Interface* r_data = nullptr;
64 bool positive = false;
65 friend class Integer;
66 };
67
84 Integer(Storage::Interface* ptr, bool positive = true, bool autoRelease = false, bool sim = true)
85 {
86 if (!ptr)
87 // throw(Exception(1));
89 this->_idata = ptr;
90 this->_idata_ar = autoRelease;
91 this->_isPostive = positive;
92 if (sim)
93 this->_simplify();
94 HRCORE_DBG(std::cout << "Interface* constructor! (_idata: " << this->_idata << ")" << std::endl;)
95 }
96
108 template <typename T>
109 static Integer make()
110 {
111 return Integer(new T, true, true, false);
112 }
113
116 {
117 return Integer(this->_idata->newObject(), true, true, false);
118 }
119
126 {
127 HRCORE_DBG(std::cout << "Move constructor! (_idata: " << c._idata << " -> " << this->_idata << ")" << std::endl;)
128 this->~Integer();
129 this->_idata = c._idata;
130 this->_isPostive = c._isPostive;
131 this->_idata_ar = c._idata_ar;
132 c._idata = nullptr;
133 c._idata_ar = false;
134 }
135
143 {
144 HRCORE_DBG(std::cout << "Move operator! (_idata: " << c._idata << " -> " << this->_idata << ")" << std::endl;)
145 this->~Integer();
146 this->_idata = c._idata;
147 this->_idata_ar = c._idata_ar;
148 this->_isPostive = c._isPostive;
149 c._idata_ar = false; // Avoid release idata; BUG detected before!
150 c._idata = nullptr;
151 return *this;
152 }
153
159 Integer(const Integer& c)
160 {
161 this->~Integer(); // Release current resource
162 this->_idata = c._idata->newObject();
163 this->_idata->extend(c._idata->length());
164 for (auto i = c._idata->begin(), j = this->_idata->begin(); i && j; i = c._idata->next(i), j = this->_idata->next(j))
165 *j.data = *i.data;
166 this->_idata_ar = true;
167 this->_isPostive = c._isPostive;
168 HRCORE_DBG(std::cout << "Copy constructor! (_idata: " << c._idata << " -> " << this->_idata << ")" << std::endl;)
169 }
170
171 ~Integer()
172 {
173 if (this->_idata_ar && this->_idata != nullptr) { // Avoid delete nullptr to cause exception
174 HRCORE_DBG(std::cout << "~Integer! (_idata: " << this->_idata << ")" << std::endl;)
175 this->_idata->delObject(this->_idata);
176 }
177 }
178
185 Integer& operator=(ival_t num)
186 {
187 auto tmp = this->_idata->newObject();
188 tmp->extend(1);
189 *tmp->at(0).data = num;
190 this->~Integer();
191 this->_idata = tmp;
192 this->_idata_ar = true;
193 this->_isPostive = true;
194 return *this;
195 }
196
199 {
200 *this = Integer(c);
201 return *this;
202 }
203
211 {
212 bool neg = (this->_isPostive ^ r._isPostive); // Determind if is +-
213 bool bigger = _absGreater(*this, r);
214 auto tmp = this->_idata->newObject();
215 size_t m = std::max(this->_idata->length(), r._idata->length());
216 tmp->extend(m + 1); // Prepare buffer
217 const Integer& op1 = (bigger ? *this : r);
218 const Integer& op2 = (bigger ? r : *this);
219 bool flag = true;
220 if (neg) {
221 _absSub(op1, op2, tmp);
222 flag = op1._isPostive;
223 } else {
224 _absPlus(op1, op2, tmp);
225 flag = this->_isPostive;
226 }
227 return Integer(tmp, flag, true, true);
228 }
229
237 {
238 return this->operator+(-r);
239 }
240
247 {
248 bool flag = !(this->_isPostive ^ r._isPostive);
249 // size_t m = std::max(this->_idata->length(), r._idata->length());
250 auto tmp = this->_idata->newObject();
251 tmp->extend(this->_idata->length() + r._idata->length() + 1);
252 bool bigger = _absGreater(*this, r);
253 const Integer& num1 = (bigger ? *this : r);
254 const Integer& num2 = (bigger ? r : *this);
255
257#if HRCORE_HIGHPERF
258#error HRCORE_HIGHPERF is enabled but currently not support (FFT) !
259#else
260 auto sop = tmp->begin();
261 for (auto i = num1._idata->begin(); i; i = num1._idata->next(i), sop = tmp->next(sop)) {
262 auto op = sop;
263 for (auto j = num2._idata->begin(); j; j = num2._idata->next(j), op = tmp->next(op)) {
264 idval_t t = (idval_t)*i.data * (idval_t)*j.data;
265 _doInc(tmp, op, t & (ival_t)0xFFFFFFFFFFFFFFFF); // Current bit
266 ival_t inc = t >> (HRCORE_UNIT_SIZE);
267 if (inc) // Increase bit
268 _doInc(tmp, tmp->next(op), inc);
269 }
270 }
271#endif
272 return Integer(tmp, flag, true, true);
273 }
274
280 {
281 if (_absEqual(this->make(), r))
283 bool flag = !(this->_isPostive ^ r._isPostive);
284 auto tmp = this->_idata->newObject();
286#if HRCORE_HIGHPERF
287#error HRCORE_HIGHPERF is enabled but currently not support (NTT) !
288#else
289 size_t ls = 0;
290 Integer div(r);
291 div.positive(true); // Enforce div to be positive
292 int8_t last = 0;
293 for (; (last = _absRelation(*this, div)) == 1; ++ls) { // Find the highest bit of result
294 div = div << 1;
295 HRCORE_DBGI(std::cout << ls + 1 << std::endl;)
296 }
297 /* if (ls == 0) { // abs(r) >= abs(this)
298 *tmp->begin().data = (last == 0);
299 return Integer(tmp, flag, true, true);
300 } */
301 // ls--;
302 // div = div >> 1; // Highest bit overflowed, cut out
303 size_t roffset = (ls) >> (HRCORE_UNIT_DIV);
304 int rem = ls - (roffset << (HRCORE_UNIT_DIV));
305 tmp->extend(roffset + 1);
306 auto op = tmp->at(roffset);
307 /* if (last == 0) { // Div r-shift == this;
308 *op.data = 1 << (rem + 1);
309 return Integer(tmp, flag, true, true);
310 } */
311 Integer sum(this->_idata->newObject(), true, true);
312 while (roffset != 0 || rem != -1) {
313 Integer dtmp = sum + div;
314 HRCORE_DBGI(std::cout << "[Integer::/] sum = " << sum << " div = " << div << " dtmp = " << dtmp << std::endl;)
315 if (rem < 0) {
316 op = tmp->prev(op);
317 rem = HRCORE_UNIT_SIZE - 1;
318 roffset--;
319 }
320 if (_absRelation(*this, dtmp) >= 0) { // The bit is valid
321 *op.data |= 1 << rem;
322 sum = dtmp;
323 }
324 div = div >> 1;
325 --rem;
326 }
327 sum._isPostive = this->_isPostive;
328 Integer rt = *this - sum;
329 rt._idata_ar = false; // Avoid auto-release to cause nullptr
331 ret.q_data = tmp;
332 ret.r_data = rt._idata;
333 ret.positive = flag;
334 return ret;
335#endif
336 }
337
345 {
346 auto x = this->divideBy(r);
347 x.r_data->delObject(x.r_data); // Avoid memory lack
348 return Integer(x.q_data, x.positive, true, true);
349 }
350
358 {
359 auto x = this->divideBy(r);
360 x.q_data->delObject(x.q_data); // Avoid memory lack
361 return Integer(x.r_data, x.positive, true, true);
362 }
363
368 {
369 Integer ret(*this);
370 ret._isPostive = !ret._isPostive;
371 return ret;
372 }
373
377 Integer operator+() const { return Integer(*this); }
378
380 bool positive() const { return this->_isPostive; }
381
386 void positive(bool p) { this->_isPostive = p; }
387
394 bool operator<(const Integer& r)
395 {
396 if (this->_isPostive ^ r._isPostive)
397 return !this->_isPostive;
398 return (this->_isPostive ? _absGreater(r, *this) : _absGreater(*this, r));
399 }
400
407 bool operator>(const Integer& r)
408 {
409 if (this->_isPostive ^ r._isPostive)
410 return this->_isPostive;
411 return (this->_isPostive ? _absGreater(*this, r) : _absGreater(r, *this));
412 }
413
415 bool operator==(const Integer& r)
416 {
417 if (this->_isPostive ^ r._isPostive)
418 return false;
419 return _absEqual(*this, r);
420 }
421
423 bool operator>=(const Integer& r) { return (operator>(r) || operator==(r)); }
424
426 bool operator<=(const Integer& r) { return (operator<(r) || operator==(r)); }
427
435 {
436 if (!n)
437 return Integer(*this);
438 // Integer ret(this->_idata->newObject(),this->_isPostive,true);
439 auto ret = this->_idata->newObject();
440 size_t offset = n >> HRCORE_UNIT_DIV;
441 size_t rem = n - (offset << HRCORE_UNIT_DIV);
442 if (rem > HRCORE_UNIT_SIZE)
444 ret->extend(this->_idata->length() + offset + 1);
445 for (auto s = this->_idata->begin(), d = ret->at(offset); s && d; s = this->_idata->next(s)) {
446 *d.data |= *s.data << rem;
447 d = ret->next(d);
448 //*d.data |= *s.data >> ((HRCORE_UNIT_SIZE)-rem); // BUG! right shift count >= width of type [-Wshift-count-overflow] -> undefined
449 *d.data |= (rem ? *s.data >> ((HRCORE_UNIT_SIZE)-rem) : 0);
450 }
451 return Integer(ret, this->_isPostive, true, true);
452 }
453
461 {
462 if (!n)
463 return Integer(*this);
464 auto ret = this->_idata->newObject();
465 size_t offset = n >> (HRCORE_UNIT_DIV);
466 size_t rem = n - (offset << (HRCORE_UNIT_DIV));
467 if (rem > HRCORE_UNIT_SIZE)
469 if (offset > this->_idata->length() + 1) { // Overflow! BUG
470 return this->make() = 0;
471 }
472 ret->extend(this->_idata->length() - offset + 1);
473 for (auto s = this->_idata->end(), d = ret->at(this->_idata->length() - offset - 1); d && s; s = this->_idata->prev(s)) {
474 *d.data |= *s.data >> rem;
475 d = ret->prev(d);
476 if (d)
477 *d.data |= (rem ? *s.data << ((HRCORE_UNIT_SIZE)-rem) : 0); // Same as before
478 }
479 return Integer(ret, this->_isPostive, true, true);
480 }
481
482 friend std::ostream& operator<<(std::ostream& os, Integer& rhs);
483 friend std::istream& operator>>(std::istream& is, Integer& rhs);
484
485 protected:
490 static int8_t _absRelation(const Integer& l, const Integer& r)
491 {
492 size_t m = l._idata->length();
493 size_t n = r._idata->length();
494 if (m != n)
495 return (m > n ? 1 : -1);
496 auto op1 = l._idata->end();
497 auto op2 = r._idata->end();
498 for (size_t i = 0; i < m; ++i) {
499 ival_t c1 = (op1 ? *op1.data : 0);
500 ival_t c2 = (op2 ? *op2.data : 0);
501 if (c1 != c2)
502 return (c1 > c2 ? 1 : -1);
503 op1 = l._idata->prev(op1);
504 op2 = r._idata->prev(op2);
505 }
506 return 0; // Equal
507 }
508
510 static bool _absGreater(const Integer& l, const Integer& r) { return (_absRelation(l, r) == 1); }
511
513 static bool _absEqual(const Integer& l, const Integer& r) { return (_absRelation(l, r) == 0); }
514
515 static bool _isZero(const Integer& l)
516 {
517 for (auto x = l._idata->begin(); x; x = l._idata->next(x)) {
518 if (*x.data != 0)
519 return false;
520 }
521 return true;
522 }
523
524 private:
526 Integer& _simplify()
527 {
528 size_t t = this->_idata->length();
529 for (auto i = this->_idata->end(); i && *i.data == 0; i = this->_idata->prev(i))
530 --t;
531 this->_idata->shrink((t == 0 ? 1 : t));
532 if (_isZero(*this))
533 this->_isPostive = true; // 0 is to be defined as positive
534 return *this;
535 }
536
538 static void _doInc(Storage::Interface* i, Storage::Interface::item_t pos, ival_t inc)
539 {
540 do {
541 idval_t ovf = (idval_t)inc + (idval_t)*pos.data;
542 *pos.data = ovf & (ival_t)0xFFFFFFFFFFFFFFFF; // Max 64 bits and force convert to fit size
543 inc = ovf >> (HRCORE_UNIT_SIZE);
544 pos = i->next(pos);
545 } while (inc); // Still overflow
546 }
547
549 static void _absPlus(const Integer& left, const Integer& right, Storage::Interface* ret)
550 {
551 size_t m = std::max(left._idata->length(), right._idata->length());
552 auto op1 = left._idata->begin();
553 auto op2 = right._idata->begin();
554 auto r = ret->begin();
555 for (size_t i = 0; i < m; ++i) {
556 ival_t c1 = (op1 ? *op1.data : 0);
557 ival_t c2 = (op2 ? *op2.data : 0);
558 idval_t tmp = (idval_t)c1 + (idval_t)c2;
559 _doInc(ret, r, tmp & (ival_t)0xFFFFFFFFFFFFFFFF);
560 //*r.data = tmp & (ival_t)0xFFFFFFFFFFFFFFFF;
561 ival_t ovf = tmp >> (HRCORE_UNIT_SIZE);
562 if (ovf) // Overflow
563 _doInc(ret, ret->next(r), ovf);
564 op1 = left._idata->next(op1);
565 op2 = right._idata->next(op2);
566 r = ret->next(r); // BUG2, Fixed
567 }
568 }
569
572 static bool _doBorrow(Storage::Interface* i, Storage::Interface::item_t pos)
573 {
574 size_t ls = 0;
575 while (pos && *pos.data < 1) {
576 pos = i->next(pos);
577 ++ls;
578 }
579 if (pos) {
580 --*pos.data;
581 for (size_t j = 0; j < ls; ++j) {
582 pos = i->prev(pos);
583 *pos.data = (ival_t)0xffffffffffffffff;
584 }
585 return true;
586 }
587 return false;
588 }
589
592 static void _absSub(const Integer& left, const Integer& right, Storage::Interface* ret)
593 {
594 HRCORE_DBG(Integer ll(left); Integer rr(right);)
595 HRCORE_DBG(std::cout << "[Integer::_absSub] Perform " << ll << " - " << rr << std::endl;)
596 size_t m = std::max(left._idata->length(), right._idata->length());
597 auto op1 = left._idata->begin();
598 auto op2 = right._idata->begin();
599 auto r = ret->begin();
600 for (size_t i = 0; i < m; ++i) {
601 if (!op1)
602 throw(Exception::LLR()); // left > right is required!
603 ival_t c1 = *op1.data;
604 ival_t c2 = (op2 ? *op2.data : 0);
605 if (c1 >= c2) {
606 *r.data = c1 - c2;
607 } else { // Not enough to do the sub
608 if (_doBorrow(left._idata, left._idata->next(op1))) {
609 idval_t nc = (idval_t)1 << (HRCORE_UNIT_SIZE) | c1;
610 *r.data = nc - c2;
611 } else {
612 throw(Exception::LLR()); // left < right
613 }
614 }
615 op1 = left._idata->next(op1);
616 op2 = right._idata->next(op2);
617 r = ret->next(r);
618 }
619 }
620
621 protected:
622 Storage::Interface* _idata = nullptr;
623 bool _idata_ar = false;
624 bool _isPostive = true;
625 }; // Class Integer
626
627#if HRCORE_ENABLE_FP
628
629#ifndef __HRCORE_FP_OPERATOR_HELPER__
633#define __HRCORE_FP_OPERATOR_HELPER__(x) \
634 bool x(const Float& rhs) \
635 { \
636 Float l(*this), r(rhs); \
637 _adjust(l, r); \
638 return l.Integer::x(r); \
639 }
640#endif
641
648 class Float : private Integer {
649 public:
650 // Inherit constructors and functions from Integer
651 using Integer::Integer;
652 using Integer::make;
653 using Integer::positive;
654
657 : Integer(c)
658 {
659 this->_fpos = c._fpos;
660 this->_tpos = c._tpos;
661 }
662
663 Float(Integer&& c, int fpos, size_t tpos)
664 : Integer(c)
665 {
666 HRCORE_DBGI(std::cout << "[Float::MoveConstructor] " << fpos << std::endl;)
667 this->_fpos = fpos;
668 this->_tpos = tpos;
669 }
670
672 Float(const Float& c)
673 : Integer(c)
674 {
675 this->_fpos = c._fpos;
676 this->_tpos = c._tpos;
677 }
678
680 Float(const Integer& c, int fpos = 0, size_t tpos = 0)
681 : Integer(c)
682 {
683 this->_fpos = fpos;
684 this->_tpos = tpos;
685 }
686
689 {
690 HRCORE_DBGI(std::cout << "[Float::MoveOperator] " << c._fpos << std::endl;)
691 this->Integer::operator=(c);
692 this->_fpos = c._fpos;
693 this->_tpos = c._tpos;
694 return *this;
695 }
696
699 {
700 this->Integer::operator=(c);
701 this->_fpos = c._fpos;
702 this->_tpos = c._tpos;
703 return *this;
704 }
705
707 Float& operator=(const double c)
708 {
709 bool flag = (c >= 0);
710 ival_t m = std::abs(c);
711 //*this = this->Integer::operator=(m);
712 Integer ret = this->make() = m;
713 Integer tim = this->make() = 10;
714 Integer div = this->make() = 1;
715 int dtmp = -HRCORE_FP_BITS_BASE;
716 int n = 0;
717 for (double x = (std::abs(c) - m); std::abs(x) > 1e-9; x -= n) {
718 x *= 10;
719 n = x;
720 Integer tmp = this->make() = n;
721 ret = ret * tim + tmp;
722 div = div * tim;
724 }
725 *this = Float((ret << -dtmp) / div, dtmp, 12);
726 this->_isPostive = flag;
727 return *this;
728 }
729
731 size_t precision() { return this->_precision; }
732
743 void precision(size_t n) { this->_precision = n; }
744
747 {
748 Float l(*this), r(s);
749 _adjust(l, r);
750 return Float(l.Integer::operator+(r), l._fpos, l._tpos);
751 }
752
755 {
756 Float l(*this), r(s);
757 _adjust(l, r);
758 return Float(l.Integer::operator-(r), l._fpos, l._tpos);
759 }
760
762 Float operator*(const Float& s) { return Float(this->Integer::operator*(s), this->_fpos + s._fpos, this->_tpos + s._tpos); }
763
766 {
767 if (this->_tpos >= this->_precision) {
768 return Float(this->Integer::operator/(s), this->_fpos, this->_tpos);
769 }
770 // Integer tim = this->make() = 10;
771 // Integer tmp = this->make() = 1;
772 size_t n = this->_precision - this->_tpos;
773 auto div = Float(*this << (n * HRCORE_FP_BITS_PER_DIGIT), this->_fpos - n * HRCORE_FP_BITS_PER_DIGIT, this->_precision); // May lost precision
774 HRCORE_DBG(std::cout << "[Test] " << div << std::endl;)
775 return div / s;
776 }
777
780 {
781 if (this->_tpos < s._tpos + this->_precision) {
782 size_t n = s._tpos + this->_precision - this->_tpos;
783 auto div = *this << (n * HRCORE_FP_BITS_PER_DIGIT);
784 return Float(div / s, this->_fpos - n * HRCORE_FP_BITS_PER_DIGIT - s._fpos, this->_precision);
785 } else {
786 return Float(this->Integer::operator/(s), this->_fpos - s._fpos, this->_precision);
787 }
788 }
789
792 {
793 HRCORE_DBG(std::cout << this->_fpos << std::endl;)
794 auto x = (this->_fpos >= 0 ? *this << this->_fpos : *this >> -(this->_fpos));
795 x.positive(this->_isPostive);
796 return x;
797 }
798
799 __HRCORE_FP_OPERATOR_HELPER__(operator<)
800 __HRCORE_FP_OPERATOR_HELPER__(operator>)
801 __HRCORE_FP_OPERATOR_HELPER__(operator==)
802 __HRCORE_FP_OPERATOR_HELPER__(operator>=)
803 __HRCORE_FP_OPERATOR_HELPER__(operator<=)
804
805 friend std::istream& operator>>(std::istream& is, Float& rhs);
806 friend std::ostream& operator<<(std::ostream& os, Float& rhs);
807
808 private:
810 static size_t _adjust(Float& fp1, Float& fp2)
811 {
812 int m = std::max(fp1._fpos, fp2._fpos);
813 int n = std::min(fp1._fpos, fp2._fpos);
814 size_t k = m - n;
815 if (!k)
816 return 0;
817 Float& adj = (m == fp1._fpos ? fp1 : fp2);
818 adj = Float(adj << k, n, std::max(fp1._tpos, fp2._tpos));
819 return k;
820 }
821
822 protected:
823 int _fpos = 0;
824 size_t _tpos = 0; // Float point in decimal, only negative
825 size_t _precision = HRCORE_FP_DEFAULT_PRECISION; // For division
826 }; // Class Float
827
828#endif
829
830}
831}
832
833#endif
Exception of divided by 0.
Definition: HRCore.h:244
Exception of internal error. Please dig into it and solve.
Definition: HRCore.h:241
Exception of Invalid Argument.
Definition: HRCore.h:243
A class as a storage interface, pure virtual.
Definition: StorageIF.hpp:28
virtual Interface * newObject()=0
Get a new object of same type.
virtual size_t length()=0
Get the length of storage.
virtual void delObject(const Interface *ptr)=0
Delete a object from newObject()
virtual bool shrink(size_t len)=0
Remove data from the end to shrink the size to a given length.
virtual bool extend(size_t len)=0
Extend the storage to a given length.
virtual item_t next(item_t cur)=0
Get next item.
virtual item_t end()=0
Returns the last item of storage.
virtual item_t begin()=0
Return the first item of storage.
virtual item_t prev(item_t cur)=0
Float type.
Definition: Value.hpp:648
Float & operator=(Float &&c)
Move operator.
Definition: Value.hpp:688
Float operator*(const Float &s)
Reload of operator*.
Definition: Value.hpp:762
Float operator/(const Integer &s)
Reload of operator/ (for Integer)
Definition: Value.hpp:765
static Integer make()
Construct a new Integer object using given type of Storage::Interface implement.
Definition: Value.hpp:109
Float & operator=(const double c)
transform IEEE-754 Floating point value into Float object
Definition: Value.hpp:707
Float & operator=(const Float &c)
Copy operator.
Definition: Value.hpp:698
Float(Float &&c)
Reload of move constructor.
Definition: Value.hpp:656
Float operator+(const Float &s)
Reload of operator+.
Definition: Value.hpp:746
Float operator-(const Float &s)
Reload of operator-.
Definition: Value.hpp:754
Float(const Float &c)
Reload of copy constructor.
Definition: Value.hpp:672
size_t precision()
Get current precision of division and input.
Definition: Value.hpp:731
Float operator/(const Float &s)
Reload of operator/ (for Float)
Definition: Value.hpp:779
Integer getInteger()
Get Interger section.
Definition: Value.hpp:791
Float(const Integer &c, int fpos=0, size_t tpos=0)
Copy value of Integer object and convert to a Float object.
Definition: Value.hpp:680
void precision(size_t n)
Set precision of division and input.
Definition: Value.hpp:743
Type defination of division result (For Integer only).
Definition: Value.hpp:33
Integer getRemainder()
Get remainder of division result.
Definition: Value.hpp:44
Integer getQuotient()
Get quotient of division result.
Definition: Value.hpp:36
void clear()
Clear the object and release memory allocated.
Definition: Value.hpp:52
Integer type.
Definition: Value.hpp:27
bool operator==(const Integer &r)
Test if (r == this)
Definition: Value.hpp:415
Integer & operator=(const Integer &c)
Copy operator.
Definition: Value.hpp:198
Integer operator+(const Integer &r)
Reload of operator+.
Definition: Value.hpp:210
friend std::istream & operator>>(std::istream &is, Integer &rhs)
Reload of operator>> to support std::cin and other std::istream with Integer.
Definition: Utils.hpp:119
Integer(Integer &&c)
Move a Integer object.
Definition: Value.hpp:125
Integer operator/(const Integer &r)
Reload of operator/.
Definition: Value.hpp:344
Integer operator+() const
Reload of operator+() const.
Definition: Value.hpp:377
static bool _absEqual(const Integer &l, const Integer &r)
Examine if l == r.
Definition: Value.hpp:513
static int8_t _absRelation(const Integer &l, const Integer &r)
Get relation of l and r.
Definition: Value.hpp:490
Integer operator<<(size_t n)
Reload of << (Left shift)
Definition: Value.hpp:434
static Integer make()
Construct a new Integer object using given type of Storage::Interface implement.
Definition: Value.hpp:109
void positive(bool p)
Set the sign of object.
Definition: Value.hpp:386
bool operator>=(const Integer &r)
Test if (this >= r)
Definition: Value.hpp:423
Integer operator-(const Integer &r)
Reload of operator-(r)
Definition: Value.hpp:236
bool operator<(const Integer &r)
Compare this and r with operator <.
Definition: Value.hpp:394
friend std::ostream & operator<<(std::ostream &os, Integer &rhs)
Reload of operator<< to support std::cout and other std::ostream with Integer.
Definition: Utils.hpp:56
Integer operator>>(size_t n)
Reload of >> (Logical right shift)
Definition: Value.hpp:460
Integer & operator=(Integer &&c)
Move operator.
Definition: Value.hpp:142
Integer operator*(const Integer &r)
Reload of operator*(r)
Definition: Value.hpp:246
Integer(const Integer &c)
Copy and construct a new Integer object.
Definition: Value.hpp:159
Integer make()
Make a new object with same Interface type.
Definition: Value.hpp:115
static bool _absGreater(const Integer &l, const Integer &r)
Examine if l > r.
Definition: Value.hpp:510
bool operator>(const Integer &r)
Compare this and r with operator >
Definition: Value.hpp:407
Integer(Storage::Interface *ptr, bool positive=true, bool autoRelease=false, bool sim=true)
Construct a new Integer object.
Definition: Value.hpp:84
DivisionResult_t divideBy(const Integer &r)
A function to calculate (*this / r)
Definition: Value.hpp:279
bool operator<=(const Integer &r)
Test if (this <= r)
Definition: Value.hpp:426
Integer operator%(const Integer &r)
Reload of operator%.
Definition: Value.hpp:357
Integer operator-() const
Reload of operator-() const.
Definition: Value.hpp:367
bool positive() const
Return the sign of object.
Definition: Value.hpp:380
Integer & operator=(ival_t num)
Reload of operator= to support a ival_t be converted to Integer.
Definition: Value.hpp:185
#define HRCORE_UNIT_SIZE
Decide how many bits should be used by single storage unit. Default: 32.
Definition: HRCore.h:49
#define HRCORE_FP_DEFAULT_PRECISION
Set default precision of Value::Float. Default: 10.
Definition: HRCore.h:101
#define HRCORE_FP_BITS_BASE
Decide how many bits as a base of Float. Default: 24.
Definition: HRCore.h:84
#define HRCORE_FP_BITS_PER_DIGIT
Decide how many bits for a digit in Float. Default: 8.
Definition: HRCore.h:94
HRCore main namespace, contains all classes.
Definition: LinkedList.hpp:14