TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
others Namespace Reference

for vector More...

Namespaces

namespace  Cache
 Cache algorithm.
 

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

for assert

Other algorithms.

for IO operations

for reverse for assert for I/O operations for stack

Other algorithms

for assert for std::abs

Other algorithms

for IO Operations for std::list for std::unordered_map

Other algorithms

for assert for std::uint64_t 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

Definition at line 40 of file kelvin_to_celsius.cpp.

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

Definition at line 49 of file kelvin_to_celsius.cpp.

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}