Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
others Namespace Reference

for vector More...

Functions

bool are_almost_equal (double a, double b, double absolute_tolerance=0.0001)
 Compare two floating point numbers with a certain tolerance. This is needed as with some values, the result (e.g.: -196.15) might be a bit lower (in this case, -196.499999...).
 
double kelvin_to_celsius (double temperature_in_k)
 Conversion from Kelvin to Celsius algorithm.
 

Detailed Description

for vector

for vector

Other algorithms.

for std::unordered_map

for reverse for assert for I/O operations for stack

Other algorithms

for assert for IO Operations for std::list

Other algorithms

for assert for I/O operations

Other algorithms

Function Documentation

◆ are_almost_equal()

bool others::are_almost_equal ( double a,
double b,
double absolute_tolerance = 0.0001 )

Compare two floating point numbers with a certain tolerance. This is needed as with some values, the result (e.g.: -196.15) might be a bit lower (in this case, -196.499999...).

Parameters
athe first number to compare
bthe second number to compare
tolerancethe tolerance to use when comparing the numbers
Returns
true if the numbers ARE equal within the given tolerance
false if the numbers are NOT equal within the given tolerance otherwise
40 {
41 return std::abs(a - b) < absolute_tolerance;
42}

◆ kelvin_to_celsius()

double others::kelvin_to_celsius ( double temperature_in_k)

Conversion from Kelvin to Celsius algorithm.

Parameters
numberthe Celsius number that will be used to convert
Returns
the Kelvin number converted to Celsius
49 {
50 const double absolute_zero_in_c = -273.15;
51 if (temperature_in_k < absolute_zero_in_c) {
52 throw std::invalid_argument("input temperature below absolute zero");
53 }
54 return temperature_in_k + absolute_zero_in_c;
55}