LocARNA-1.8.11
infty_int.hh
1 #ifndef LOCARNA_INFTY_INT_HH
2 #define LOCARNA_INFTY_INT_HH
3 
4 #ifdef HAVE_CONFIG_H
5 # include <config.h>
6 #endif
7 
8 #include <algorithm>
9 #include <iosfwd>
10 #include <assert.h>
11 
12 namespace LocARNA {
13 
14  class FiniteInt;
15  class InftyInt;
16 
57  public:
59  typedef long int base_type;
60 
61  protected:
62  base_type val;
63 
65  static const base_type min_finity;
66 
68  static const base_type max_finity;
69 
71  static const base_type min_normal_neg_infty;
72 
74  static const base_type max_normal_pos_infty;
75  public:
76 
80  TaintedInftyInt(): val(0) {
81  }
82 
87  explicit
88  TaintedInftyInt(const base_type &x)
89  : val(x) {
90  }
91 
97  static
98  base_type
100  return min_finity;
101  }
102 
108  static
109  base_type
111  return max_finity;
112  }
113 
119  bool
120  is_neg_infty() const {
121  return val < min_finity;
122  }
123 
129  bool
130  is_pos_infty() const {
131  return val > max_finity;
132  }
133 
139  bool
140  is_finite() const {
141  return min_finity <= val && val <= max_finity;
142  }
143 
149  bool
150  is_normal() const {
151  return min_normal_neg_infty <= val && val <= max_normal_pos_infty;
152  }
153 
160  base_type
161  finite_value() const {
162  assert(is_finite());
163  return val;
164  }
165 
174  operator =(const FiniteInt &x);
175 
184  friend
185  bool
186  operator ==(const TaintedInftyInt &x, const TaintedInftyInt &y);
187 
196  friend
198  operator +(const TaintedInftyInt &x, const FiniteInt &y);
199 
208  friend
210  operator -(const TaintedInftyInt &x, const FiniteInt &y);
211 
220  friend
222  operator +(const InftyInt &x, const InftyInt &y);
223 
232  friend
234  operator -(const InftyInt &x, const InftyInt &y);
235 
244  friend
246  min(const TaintedInftyInt &x, const TaintedInftyInt &y);
247 
256  friend
258  max(const TaintedInftyInt &x, const TaintedInftyInt &y);
259 
271  friend
272  bool
273  operator > (const TaintedInftyInt &x, const TaintedInftyInt &y);
274 
286  friend
287  bool
288  operator < (const TaintedInftyInt &x, const TaintedInftyInt &y);
289 
301  friend
302  bool
303  operator >= (const TaintedInftyInt &x, const TaintedInftyInt &y);
304 
316  friend
317  bool
318  operator <= (const TaintedInftyInt &x, const TaintedInftyInt &y);
319 
320 
321  friend class InftyInt;
322 
331  friend
332  std::ostream &
333  operator <<(std::ostream &out, const TaintedInftyInt &x);
334 
335  };
336 
344  class InftyInt : public TaintedInftyInt {
345 
346  public:
347 
349  static const InftyInt neg_infty;
351  static const InftyInt pos_infty;
352 
353  private:
354  void normalize() {
355  //std::cout << "NORMALIZE" <<std::endl;
356  if (is_neg_infty()) {
357  val = neg_infty.val;
358  } else if (is_pos_infty()) {
359  val = pos_infty.val;
360  }
361  }
362  public:
363 
369  }
370 
376  explicit
378  assert(is_normal());
379  }
380 
386  explicit
387  InftyInt(const FiniteInt &x);
388 
396  normalize();
397  }
398 
406  InftyInt &
408  val = x.val;
409  normalize();
410  return *this;
411  }
412 
420  InftyInt &
421  operator +=(const FiniteInt &x);
422 
430  InftyInt &
431  operator -=(const FiniteInt &x);
432 
433 
442  friend
443  InftyInt
444  operator +(const InftyInt &x, const FiniteInt &y);
445 
454  friend
455  InftyInt
456  operator -(const InftyInt &x, const FiniteInt &y);
457 
458  };
459 
464  class FiniteInt : public InftyInt {
465  public:
466 
471  }
472 
479  assert(is_finite());
480  }
481 
487  const base_type &
488  finite_value() const {
489  return val;
490  }
491 
499  friend
500  FiniteInt
501  operator +(const FiniteInt &x, const FiniteInt &y);
502 
510  friend
511  FiniteInt
512  operator -(const FiniteInt &x, const FiniteInt &y);
513 
514  };
515 
516  inline
518  operator +(const TaintedInftyInt &x, const FiniteInt &y) {
519  TaintedInftyInt res(x);
520  res.val+=y.val;
521  return res;
522  }
523 
524  inline
526  operator -(const TaintedInftyInt &x, const FiniteInt &y) {
527  TaintedInftyInt res(x);
528  res.val-=y.val;
529  return res;
530  }
531 
532  inline
534  operator +(const InftyInt &x, const InftyInt &y) {
535  TaintedInftyInt res(x);
536  res.val+=y.val;
537  return res;
538  }
539 
540  inline
542  operator -(const InftyInt &x, const InftyInt &y) {
543  TaintedInftyInt res(x);
544  res.val-=y.val;
545  return res;
546  }
547 
548 
549  inline
550  InftyInt &
552  val += x.val;
553  return *this;
554  }
555 
556  inline
557  InftyInt &
559  val -= x.val;
560  return *this;
561  }
562 
563 
564  inline
565  InftyInt
566  operator +(const InftyInt &x, const FiniteInt &y) {
567  InftyInt res(x);
568  res.val+=y.val;
569  return res;
570  }
571 
572  inline
573  InftyInt
574  operator -(const InftyInt &x, const FiniteInt &y) {
575  InftyInt res(x);
576  res.val-=y.val;
577  return res;
578  }
579 
580  inline
581  FiniteInt
582  operator +(const FiniteInt &x, const FiniteInt &y) {
583  FiniteInt res(x);
584  res.val+=y.val;
585  return res;
586  }
587 
588  inline
589  FiniteInt
590  operator -(const FiniteInt &x, const FiniteInt &y) {
591  FiniteInt res(x);
592  res.val-=y.val;
593  return res;
594  }
595 
596  inline
597  bool
599  return x.val==y.val;
600  }
601 
602  inline
605  val=x.val;
606  return *this;
607  }
608 
609  inline
611  min(const TaintedInftyInt &x, const TaintedInftyInt &y) {
612  return TaintedInftyInt(std::min(x.val,y.val));
613  }
614 
615  inline
617  max(const TaintedInftyInt &x, const TaintedInftyInt &y) {
618  return TaintedInftyInt(std::max(x.val,y.val));
619  }
620 
621  inline
623  }
624 
625  inline
626  bool
628  return x.val > y.val;
629  }
630 
631  inline
632  bool
634  return x.val < y.val;
635  }
636 
637  inline
638  bool
640  return x.val >= y.val;
641  }
642 
643  inline
644  bool
646  return x.val <= y.val;
647  }
648 
649 
650 
651 
652 } // end namespace LocARNA
653 
654 
655 #endif
friend TaintedInftyInt max(const TaintedInftyInt &x, const TaintedInftyInt &y)
Maximum.
Definition: infty_int.hh:617
static const InftyInt neg_infty
normalized negative infinity
Definition: infty_int.hh:349
friend bool operator==(const TaintedInftyInt &x, const TaintedInftyInt &y)
Equality test.
Definition: infty_int.hh:598
InftyInt(const TaintedInftyInt &x)
Construct from potentially tainted.
Definition: infty_int.hh:395
InftyInt & operator-=(const FiniteInt &x)
Definition: infty_int.hh:558
TaintedInftyInt & operator=(const FiniteInt &x)
Assignment.
Definition: infty_int.hh:604
Definition: infty_int.hh:56
base_type val
value
Definition: infty_int.hh:62
friend bool operator>(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:627
friend bool operator<(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:633
friend bool operator<=(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:645
Definition: aligner.cc:17
long int base_type
the base type
Definition: infty_int.hh:59
FiniteInt()
Construct empty.
Definition: infty_int.hh:470
static const base_type max_finity
maximum finite value
Definition: infty_int.hh:68
InftyInt()
Construct empty.
Definition: infty_int.hh:368
const base_type & finite_value() const
Access finite value.
Definition: infty_int.hh:488
base_type finite_value() const
Convert finite value to base type.
Definition: infty_int.hh:161
TaintedInftyInt()
Construct empty.
Definition: infty_int.hh:80
static const base_type min_finity
minimum finite value
Definition: infty_int.hh:65
Definition: infty_int.hh:344
friend TaintedInftyInt operator+(const TaintedInftyInt &x, const FiniteInt &y)
Add.
Definition: infty_int.hh:518
static const InftyInt pos_infty
normalized positive infinity
Definition: infty_int.hh:351
static const base_type max_normal_pos_infty
maximum normal infinite value
Definition: infty_int.hh:74
FiniteInt(base_type x)
Construct from base type value.
Definition: infty_int.hh:478
Definition: infty_int.hh:464
InftyInt(const base_type &x)
Construct from base type.
Definition: infty_int.hh:377
InftyInt & operator+=(const FiniteInt &x)
Definition: infty_int.hh:551
TaintedInftyInt(const base_type &x)
Construct from base type.
Definition: infty_int.hh:88
friend std::ostream & operator<<(std::ostream &out, const TaintedInftyInt &x)
Definition: infty_int.cc:40
bool is_finite() const
Definition: infty_int.hh:140
bool is_neg_infty() const
Definition: infty_int.hh:120
bool is_pos_infty() const
Definition: infty_int.hh:130
friend TaintedInftyInt operator-(const TaintedInftyInt &x, const FiniteInt &y)
Subtract.
Definition: infty_int.hh:526
static base_type max_finite()
maximum finite value
Definition: infty_int.hh:110
bool is_normal() const
Definition: infty_int.hh:150
static base_type min_finite()
minimum finite value
Definition: infty_int.hh:99
friend TaintedInftyInt min(const TaintedInftyInt &x, const TaintedInftyInt &y)
Minimum.
Definition: infty_int.hh:611
static const base_type min_normal_neg_infty
minimum normal infinite value
Definition: infty_int.hh:71
friend bool operator>=(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:639