TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
kelvin_to_celsius.cpp File Reference

Conversion from Kelvin to Celsius degrees. More...

#include <cassert>
#include <cmath>
#include <iostream>
Include dependency graph for kelvin_to_celsius.cpp:

Go to the source code of this file.

Namespaces

namespace  others
 for vector
 

Functions

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...).
 
double others::kelvin_to_celsius (double temperature_in_k)
 Conversion from Kelvin to Celsius algorithm.
 
static void tests ()
 Self-test implementations.
 
int main ()
 Main function.
 

Detailed Description

Conversion from Kelvin to Celsius degrees.

The algorithm consists on converting a Kelvin degree value to a Celsius value. The formula to convert a Kelvin to a Celsius value is:

\[ C = K - 273.15 \]

where:

  • C is the Celsius temperature
  • K is the Kelvin temperature

Check out Kelvin and Celsius on Wikipedia for more information about their story, how do they work, when and why they should be used, etc..

Author
David Leal

Definition in file kelvin_to_celsius.cpp.

Function Documentation

◆ main()

int main ( void )

Main function.

Returns
0 on exit

Definition at line 78 of file kelvin_to_celsius.cpp.

78 {
79 tests(); // run self-test implementations
80 return 0;
81}
static void tests()
Self-test implementations.

◆ tests()

static void tests ( )
static

Self-test implementations.

Returns
void

Definition at line 62 of file kelvin_to_celsius.cpp.

62 {
70
71 std::cout << "All tests have successfully passed!\n";
72}
double kelvin_to_celsius(double temperature_in_k)
Conversion from Kelvin to Celsius algorithm.
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,...