IntaRNA 3.4.1
RNA-RNA interaction prediction | C++ API
Loading...
Searching...
No Matches
PartitionArithmetic.h
Go to the documentation of this file.
1#ifndef INTARNA_PARTITIONARITHMETIC_H_
2#define INTARNA_PARTITIONARITHMETIC_H_
3#include "IntaRNA/general.h"
4#include <stdexcept>
5
6namespace IntaRNA {
12public:
14 static Z_type check(const Z_type x);
16 static Z_type add(const Z_type a, const Z_type b);
18 static Z_type multiply(const Z_type a, const Z_type b);
20 static Z_type divide(const Z_type a, const Z_type b);
22 static Z_type exp(const Z_type exponent);
23};
25 if (!(x>=0 && x<=std::numeric_limits<Z_type>::max())
26 || (x>0 && x<std::numeric_limits<Z_type>::min()))
27 throw std::range_error("partition arithmetic: numerical range exceeded");
28 return x;
29}
31 return check(check(a)+check(b));
32}
34 check(a); check(b);
35 if (a==0 || b==0) return 0;
36 const Z_type r=check(a*b);
37 if (r==0) throw std::range_error("partition arithmetic: product underflow");
38 return r;
39}
41 check(a); check(b);
42 if (b==0) throw std::range_error("partition arithmetic: zero denominator");
43 const Z_type r=check(a/b);
44 if (a>0 && r==0) throw std::range_error("partition arithmetic: quotient underflow");
45 return r;
46}
47inline Z_type PartitionArithmetic::exp(const Z_type exponent) {
48 const Z_type r=check(Z_exp(exponent));
49 if (r==0) throw std::range_error("partition arithmetic: exponential underflow");
50 return r;
51}
52}
53#endif
Definition PartitionArithmetic.h:11
static Z_type divide(const Z_type a, const Z_type b)
Definition PartitionArithmetic.h:40
static Z_type check(const Z_type x)
Definition PartitionArithmetic.h:24
static Z_type multiply(const Z_type a, const Z_type b)
Definition PartitionArithmetic.h:33
static Z_type add(const Z_type a, const Z_type b)
Definition PartitionArithmetic.h:30
static Z_type exp(const Z_type exponent)
Definition PartitionArithmetic.h:47
#define Z_exp
Definition general.h:90
Definition Accessibility.h:13
double Z_type
type for probabilities, RT and Boltzmann values
Definition general.h:88