Peano 4
Loading...
Searching...
No Matches
ScalarOperations.cpp
Go to the documentation of this file.
2
3#include <cmath>
4
5int tarch::la::abs (int value) {
6 return value < 0 ? - value : value;
7}
8
9double tarch::la::abs( const std::complex<double>& value ) {
10 return std::sqrt( value.real()*value.real() + value.imag() * value.imag() );
11}
12
13double tarch::la::abs(double value) {
14 return std::abs(value);
15}
16
17int tarch::la::aPowI(int i,int a) {
18 int result = 1;
19 for (int d=0; d<i; d++) {
20 result *= a;
21 }
22 return result;
23}
24
26 double lhs,
27 double rhs,
28 double tolerance
29) {
30 return lhs - rhs > tolerance;
31}
32
34 double lhs,
35 double rhs,
36 double tolerance
37) {
38 return lhs - rhs >= - tolerance;
39}
40
41
42/*
43bool tarch::la::smaller (
44 double lhs,
45 double rhs,
46 double tolerance
47) {
48 return lhs - rhs < -tolerance;
49}
50*/
51
53 double lhs,
54 double rhs,
55 double tolerance
56) {
57 return lhs - rhs <= tolerance;
58}
59
61 double lhs,
62 double rhs,
63 double tolerance
64) {
65 return std::abs(rhs - lhs) <= tolerance;
66}
67
69 const std::complex<double>& lhs,
70 const std::complex<double>& rhs,
71 double tolerance
72) {
73 return (std::abs(rhs.real() - lhs.real()) <= tolerance) && (std::abs(rhs.imag() - lhs.imag()) <= tolerance);
74}
75
76int tarch::la::sign (double number, double tolerance) {
77 if ( greater(number, tolerance) ) {
78 return 1;
79 } else if ( greater(tolerance, number) ) {
80 return -1;
81 }
82 return 0;
83}
84
85int tarch::la::round(double value) {
86 return static_cast<int>(std::floor(value+0.5));
87}
88
89int tarch::la::round(float value) {
90 return static_cast<int>(std::floor(value+0.5));
91}
bool greater(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
double abs(double value)
Returns the absolute value of a type by redirecting to std::abs.
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
int sign(double value, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool equals(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares to matrices on equality by means of a numerical accuracy.
int aPowI(int i, int a)
Computes the i-th power of a in integer arithmetic.
int round(double value)