Source code: C++ Temperature Conversion and Vapor Pressure Deficit (VPD) 🛠

I’ve made several updates to the temperature conversion classes:

  • Added Rankine units.
  • Set the base class to Celcius such that any mathematical operations using the temperature types are always performed in Celcius and then converted back to the target temperature unit. Math with temperature, in some cases, is nonsensical since we should be talking temperature deltas. Though, as a class, mathematical formulas can utilize the conversions allowing for flexibility. Just be aware that additions between two different units will always be converted to Celcius for the operation, first.
  • Refactored code such that temperature types are preserved internally. Previously, everything was converted to double float internally.
  • Fixed speeling error on faranheit.

This update will be utilized for any additional sourcecode that utilizes these classes and replaces the original source in the OP.

Temperature conversion classes:

//
// temperature_types.h
// Version timestamp: 2-9-2020, 1:33 PM
//
// Attribution : Copyright (c) 2018 Northern_Loki (sha256::6F290BF833967127BE26C92C8F6B1C1A3949C55A7EABCEF3ECC785CD2D38D30D)
// License is granted under the Creative Commons Attribution-ShareAlike 4.0 International.  https://creativecommons.org/licenses/by-sa/4.0/
//
# pragma once

# include <string>
# include <sstream>
# include <boost/variant.hpp>
# include <iostream>

# include "Conversion_Constants.h"

class celcius; class kelvin; class Temperature; class fahrenheit; class rankine;
typedef boost::variant<celcius, kelvin, fahrenheit, rankine, double> celcius_variant;
typedef boost::variant<celcius, kelvin, fahrenheit, rankine, double> kelvin_variant;
typedef boost::variant<celcius, kelvin, fahrenheit, rankine, double> fahrenheit_variant;
typedef boost::variant<celcius, kelvin, fahrenheit, rankine, double> rankine_variant;

class fahrenheit
{
    
public:
    double degrees_fahrenheit = 0;
    fahrenheit()
        : degrees_fahrenheit(0) {}
    fahrenheit(const fahrenheit& c) { degrees_fahrenheit = c.degrees_fahrenheit; } // Copy contructor
    fahrenheit(double r) { degrees_fahrenheit = r; }
    fahrenheit(fahrenheit_variant &r);
    void operator=(fahrenheit_variant &temp2);
    virtual fahrenheit operator-(fahrenheit_variant temp2);
    virtual fahrenheit operator+(fahrenheit_variant temp2); 
    virtual fahrenheit operator*(fahrenheit_variant temp2); 
    virtual fahrenheit operator/(fahrenheit_variant temp2); 
    virtual fahrenheit operator-=(fahrenheit_variant temp2);
    virtual fahrenheit operator+=(fahrenheit_variant temp2); 
    virtual fahrenheit operator++(int incr);
    virtual fahrenheit operator--(int incr); 
    virtual fahrenheit operator*=(fahrenheit_variant temp2);
    virtual fahrenheit operator/=(fahrenheit_variant temp2); 
    virtual double operator()(fahrenheit_variant temp2);
    virtual double operator()(); 
    virtual bool operator>(fahrenheit_variant temp2); 
    virtual bool operator<(fahrenheit_variant temp2); 
    virtual bool operator>=(fahrenheit_variant temp2); 
    virtual bool operator<=(fahrenheit_variant temp2); 
    virtual bool operator==(fahrenheit_variant temp2); 
    virtual bool operator!=(fahrenheit_variant temp2); 
    virtual operator celcius();
    virtual operator kelvin();
    virtual operator rankine();

    friend std::ostream& operator<<(std::ostream& lhs, const fahrenheit& rhs)
    {
        return (lhs << rhs.degrees_fahrenheit);
    }
    
    friend fahrenheit operator+(const double &c1, fahrenheit c2); 
    friend fahrenheit operator*(const double &c1, fahrenheit c2); 
    friend fahrenheit operator/(const double &c1, fahrenheit c2); 
    friend fahrenheit operator-(const double &c1, fahrenheit c2); 
    
    explicit operator double() const { return degrees_fahrenheit;}
    explicit operator float() const { return degrees_fahrenheit;}
    explicit operator int() const { return (int)(degrees_fahrenheit + 0.5);}
};


class kelvin 
{
    
public:
    double degrees_kelvin = 0;
    kelvin()
        : degrees_kelvin(0) {}
    kelvin(const kelvin& c) { degrees_kelvin = c.degrees_kelvin; } // Copy contructor
    kelvin(double r) { degrees_kelvin = r; }
    kelvin(kelvin_variant &r);
    void operator=(kelvin_variant &temp2);
    virtual kelvin operator-(kelvin_variant temp2);
    virtual kelvin operator+(kelvin_variant temp2); 
    virtual kelvin operator*(kelvin_variant temp2); 
    virtual kelvin operator/(kelvin_variant temp2); 
    virtual kelvin operator-=(kelvin_variant temp2);
    virtual kelvin operator+=(kelvin_variant temp2); 
    virtual kelvin operator++(int incr);
    virtual kelvin operator--(int incr); 
    virtual kelvin operator*=(kelvin_variant temp2);
    virtual kelvin operator/=(kelvin_variant temp2); 
    virtual double operator()(kelvin_variant temp2); 
    virtual double operator()(); 
    virtual bool operator>(kelvin_variant temp2); 
    virtual bool operator<(kelvin_variant temp2); 
    virtual bool operator>=(kelvin_variant temp2); 
    virtual bool operator<=(kelvin_variant temp2); 
    virtual bool operator==(kelvin_variant temp2); 
    virtual bool operator!=(kelvin_variant temp2); 
    virtual operator celcius();
    virtual operator fahrenheit();
    virtual operator rankine();

    friend std::ostream& operator<<(std::ostream& lhs, const kelvin& rhs)
    {
        return (lhs << rhs.degrees_kelvin);
    }
    
    friend kelvin operator+(const double &c1, kelvin c2); 
    friend kelvin operator*(const double &c1, kelvin c2); 
    friend kelvin operator/(const double &c1, kelvin c2); 
    friend kelvin operator-(const double &c1, kelvin c2); 
    
    explicit operator double() const { return degrees_kelvin;}
    explicit operator float() const { return degrees_kelvin;}
    explicit operator int() const { return (int)(degrees_kelvin + 0.5);}
};


class celcius
{
    
public:
    double degrees_celcius = 0;
    celcius()
        : degrees_celcius(0) {}
    celcius(const celcius& c) { degrees_celcius = c.degrees_celcius; } // Copy contructor
    celcius(double r) { degrees_celcius = r; }
    celcius(celcius_variant &r);
    void operator=(celcius_variant &temp2);
    virtual celcius operator-(celcius_variant temp2);
    virtual celcius operator+(celcius_variant temp2); 
    virtual celcius operator*(celcius_variant temp2); 
    virtual celcius operator/(celcius_variant temp2); 
    virtual celcius operator-=(celcius_variant temp2);
    virtual celcius operator+=(celcius_variant temp2); 
    virtual celcius operator++(int incr);
    virtual celcius operator--(int incr); 
    virtual celcius operator*=(celcius_variant temp2);
    virtual celcius operator/=(celcius_variant temp2); 
    virtual double operator()(celcius_variant temp2); 
    virtual double operator()(); 
    virtual bool operator>(celcius_variant temp2); 
    virtual bool operator<(celcius_variant temp2); 
    virtual bool operator>=(celcius_variant temp2); 
    virtual bool operator<=(celcius_variant temp2); 
    virtual bool operator==(celcius_variant temp2); 
    virtual bool operator!=(celcius_variant temp2); 
    virtual operator kelvin();
    virtual operator fahrenheit();
    virtual operator rankine();
    
    friend std::ostream& operator<<(std::ostream& lhs, const celcius& rhs)
    {
        return (lhs << rhs.degrees_celcius);
    }
    
    friend celcius operator+(const double &c1, const celcius &c2); 
    friend celcius operator*(const double &c1, const celcius &c2); 
    friend celcius operator/(const double &c1, const celcius &c2); 
    friend celcius operator-(const double &c1, const celcius &c2); 
    
    explicit operator double() const { return degrees_celcius;}
    explicit operator float() const { return degrees_celcius;}
    explicit operator int() const { return (int)(degrees_celcius + 0.5);}
    
};

class rankine
{
    
public:
    double degrees_rankine = 0;
    rankine()
        : degrees_rankine(0) {}
    rankine(const rankine& c) { degrees_rankine = c.degrees_rankine; } // Copy contructor
    rankine(double r) { degrees_rankine = r; }
    rankine(rankine_variant &r);
    void operator=(rankine_variant &temp2);
    virtual rankine operator-(rankine_variant temp2);
    virtual rankine operator+(rankine_variant temp2); 
    virtual rankine operator*(rankine_variant temp2); 
    virtual rankine operator/(rankine_variant temp2); 
    virtual rankine operator-=(rankine_variant temp2);
    virtual rankine operator+=(rankine_variant temp2); 
    virtual rankine operator++(int incr);
    virtual rankine operator--(int incr); 
    virtual rankine operator*=(rankine_variant temp2);
    virtual rankine operator/=(rankine_variant temp2); 
    virtual double operator()(rankine_variant temp2); 
    virtual double operator()(); 
    virtual bool operator>(rankine_variant temp2); 
    virtual bool operator<(rankine_variant temp2); 
    virtual bool operator>=(rankine_variant temp2); 
    virtual bool operator<=(rankine_variant temp2); 
    virtual bool operator==(rankine_variant temp2); 
    virtual bool operator!=(rankine_variant temp2); 
    virtual operator kelvin();
    virtual operator fahrenheit();
    virtual operator celcius();
    
    friend std::ostream& operator<<(std::ostream& lhs, const rankine& rhs)
    {
        return (lhs << rhs.degrees_rankine);
    }
    
    friend rankine operator+(const double &c1, const rankine &c2); 
    friend rankine operator*(const double &c1, const rankine &c2); 
    friend rankine operator/(const double &c1, const rankine &c2); 
    friend rankine operator-(const double &c1, const rankine &c2); 
    
    explicit operator double() const { return degrees_rankine;}
    explicit operator float() const { return degrees_rankine;}
    explicit operator int() const { return (int)(degrees_rankine + 0.5);}
};



class tcelcius_variant : public boost::static_visitor<celcius>
{
public:
    celcius operator()(double temperature) const
    {
        return (temperature);
    }
    
    celcius operator()(celcius temperature) const
    {
        return (temperature);
    }
    
    celcius operator()(kelvin temperature) const
    {
        celcius temp = temperature.degrees_kelvin - 273.15;
        return (temp);
    }
    
    celcius operator()(fahrenheit temperature) const
    {
        celcius temp = (temperature.degrees_fahrenheit - 32.0) / (1.8);
        return (temp);
    }
    
    celcius operator()(rankine temperature) const
    {
        celcius temp = (temperature.degrees_rankine -  491.67) / (1.8);
        return (temp);
    }
    
};

class tkelvin_variant : public boost::static_visitor<kelvin>
{
public:
    kelvin operator()(double temperature) const
    {
        return (temperature);
    }
    
    kelvin operator()(kelvin temperature) const
    {
        return (temperature);
    }
    
    kelvin operator()(celcius temperature) const
    {
        kelvin temp = temperature.degrees_celcius + 273.15;
        return (temp);
    }
    
    kelvin operator()(fahrenheit temperature) const
    {
        kelvin temp = (temperature.degrees_fahrenheit - 32.0) / (1.8) + 273.15;
        return (temp);
    }
    
    kelvin operator()(rankine temperature) const
    {
        kelvin temp = (temperature.degrees_rankine) / (1.8);
        return (temp);
    }
    
};

class tfahrenheit_variant : public boost::static_visitor<fahrenheit>
{
public:
    fahrenheit operator()(double temperature) const
    {
        return (temperature);
    }
    
    fahrenheit operator()(fahrenheit temperature) const
    {
        return (temperature);
    }
    
    fahrenheit operator()(celcius temperature) const
    {
        fahrenheit temp = temperature.degrees_celcius * (1.8) + 32.0;
        return (temp);
    }
    
    fahrenheit operator()(kelvin temperature) const
    {
        fahrenheit temp = (temperature.degrees_kelvin) * (1.8) - 459.67;
        return (temp);
    }
    
    fahrenheit operator()(rankine temperature) const
    {
        fahrenheit temp = (temperature.degrees_rankine) - 459.67;
        return (temp);
    }
    
};

class trankine_variant : public boost::static_visitor<rankine>
{
public:
    rankine operator()(double temperature) const
    {
        return (temperature);
    }
    
    rankine operator()(rankine temperature) const
    {
        return (temperature);
    }
    
    rankine operator()(celcius temperature) const
    {
        rankine temp = (temperature.degrees_celcius + 273.15) * (1.8);
        return (temp);
    }
    
    rankine operator()(kelvin temperature) const
    {
        rankine temp = (temperature.degrees_kelvin) * (1.8);
        return (temp);
    }
    
    rankine operator()(fahrenheit temperature) const
    {
        rankine temp = (temperature.degrees_fahrenheit) + 459.67;
        return (temp);
    }
    
};
//
// Conversion_Utilities.h
// Version timestamp: 2-9-2020, 7:50 PM
//
// Attribution : Copyright (c) 2018 Northern_Loki (sha256::6F290BF833967127BE26C92C8F6B1C1A3949C55A7EABCEF3ECC785CD2D38D30D)
// License is granted under the Creative Commons Attribution-ShareAlike 4.0 International.  https://creativecommons.org/licenses/by-sa/4.0/
//
# pragma once
# include "temperature_types.h"
# include "power_types.h"
# include "volume_types.h"
# include "pressure_types.h"
# include "mass_types.h"
# include "volume_types.h"

# ifdef __cplusplus
extern "C" {
# endif

    int Conversion_UtilitiesTest();

# ifdef __cplusplus
}
# endif
//
// Kelvin.cpp
// Version timestamp: 2-9-2020, 1:33 PM
//
// Attribution : Copyright (c) 2018 Northern_Loki (sha256::6F290BF833967127BE26C92C8F6B1C1A3949C55A7EABCEF3ECC785CD2D38D30D)
// License is granted under the Creative Commons Attribution-ShareAlike 4.0 International.  https://creativecommons.org/licenses/by-sa/4.0/
//
# include "temperature_types.h"

kelvin::kelvin(kelvin_variant &r)
{
    kelvin_variant c = r;
    kelvin temp = boost::apply_visitor(tkelvin_variant(), c);
    this->degrees_kelvin = temp.degrees_kelvin;
}

kelvin::operator fahrenheit()
{
    fahrenheit temp = (this->degrees_kelvin) * (1.8) - 459.67;
    return (temp);
}

kelvin::operator celcius()
{
    celcius temp = this->degrees_kelvin - 273.15;
    return (temp);
}

kelvin::operator rankine()
{
    rankine temp = this->degrees_kelvin * (1.8);
    return (temp);
}


void kelvin::operator=(kelvin_variant &temp2) 
{
    kelvin temp = boost::apply_visitor(tkelvin_variant(), temp2);
    this->degrees_kelvin = temp.degrees_kelvin;
}

kelvin kelvin::operator-(kelvin_variant temp2) 
{
    celcius temp = celcius(*this);
    temp -= boost::apply_visitor(tcelcius_variant(), temp2);
    
    return ((kelvin)temp);
}

kelvin kelvin::operator+(celcius_variant temp2) 
{
    celcius temp = celcius(*this);
    temp += boost::apply_visitor(tcelcius_variant(), temp2);
    
    return ((kelvin)temp);
}

kelvin operator+(const double &c1, kelvin c2)
{
    celcius temp = c1 + celcius(c2);
    return ((kelvin)temp);
}

kelvin operator*(const double &c1, kelvin c2)
{
    celcius temp = c1 * celcius(c2);
    return ((kelvin)temp);
}

kelvin operator/(const double &c1, kelvin c2)
{
    celcius temp = c1 / celcius(c2);
    return ((kelvin)temp);
}

kelvin operator-(const double &c1, kelvin c2)
{
    celcius temp = c1 - celcius(c2);
    return ((kelvin)temp);
}

kelvin kelvin::operator*(kelvin_variant temp2) 
{
    celcius temp = celcius(*this);
    temp *= boost::apply_visitor(tcelcius_variant(), temp2);
    
    return ((kelvin)temp);
}

kelvin kelvin::operator/(kelvin_variant temp2) 
{
    celcius temp = celcius(*this);
    temp /= boost::apply_visitor(tcelcius_variant(), temp2);
    
    return ((kelvin)temp);
}

double kelvin::operator()(kelvin_variant temp2) 
{
    kelvin temp = boost::apply_visitor(tkelvin_variant(), temp2);
    return (temp.degrees_kelvin);
}

double kelvin::operator()() 
{
    double temp = this->degrees_kelvin;
    return (temp);
}

kelvin kelvin::operator-=(kelvin_variant temp2) 
{
    celcius temp = celcius(*this);
    temp = temp - boost::apply_visitor(tcelcius_variant(), temp2);
    kelvin tempk = temp;
    this->degrees_kelvin = tempk.degrees_kelvin;
    
    return (tempk);
}

kelvin kelvin::operator+=(kelvin_variant temp2) 
{
    celcius temp = celcius(*this);
    temp = temp + boost::apply_visitor(tcelcius_variant(), temp2);
    kelvin tempk = temp;
    this->degrees_kelvin = tempk.degrees_kelvin;
    
    return (tempk);
}

kelvin kelvin::operator++(int incr) 
{
    this->degrees_kelvin +=  1.0;
    return (this->degrees_kelvin);
}

kelvin kelvin::operator--(int incr) 
{
    this->degrees_kelvin -= 1.0;
    return (this->degrees_kelvin);
}

kelvin kelvin::operator*=(kelvin_variant temp2) 
{
    celcius temp = celcius(*this);
    temp = temp * boost::apply_visitor(tcelcius_variant(), temp2);
    kelvin tempk = temp;
    this->degrees_kelvin = tempk.degrees_kelvin;
    
    return (tempk);
}

kelvin kelvin::operator/=(kelvin_variant temp2) 
{
    celcius temp = celcius(*this);
    temp = temp / boost::apply_visitor(tcelcius_variant(), temp2);
    kelvin tempk = temp;
    this->degrees_kelvin = tempk.degrees_kelvin;
    
    return (tempk);
}

bool kelvin::operator>(kelvin_variant temp2) 
{
    kelvin temp = boost::apply_visitor(tkelvin_variant(), temp2);
    if (this->degrees_kelvin > temp.degrees_kelvin) return (1);
    return (0);
}

bool kelvin::operator<(kelvin_variant temp2) 
{
    kelvin temp = boost::apply_visitor(tkelvin_variant(), temp2);
    if (this->degrees_kelvin < temp.degrees_kelvin) return (1);
    return (0);
}

bool kelvin::operator==(kelvin_variant temp2) 
{
    kelvin temp = boost::apply_visitor(tkelvin_variant(), temp2);
    if (fabs(temp.degrees_kelvin - this->degrees_kelvin) <= 
    __DBL_EPSILON__ * fmax(fabs(temp.degrees_kelvin), fabs(this->degrees_kelvin))) return (1);
    return (0);
}

bool kelvin::operator!=(kelvin_variant temp2) 
{
    kelvin temp = boost::apply_visitor(tkelvin_variant(), temp2);
    if (fabs(temp.degrees_kelvin - this->degrees_kelvin) <= 
        __DBL_EPSILON__ * fmax(fabs(temp.degrees_kelvin), fabs(this->degrees_kelvin))) return (0);
    return (1);
}

bool kelvin::operator>=(kelvin_variant temp2) 
{
    kelvin temp = boost::apply_visitor(tkelvin_variant(), temp2);
    if (this->degrees_kelvin >= temp.degrees_kelvin) return (1);
    return (0);
}
bool kelvin::operator<=(kelvin_variant temp2) 
{
    kelvin temp = boost::apply_visitor(tkelvin_variant(), temp2);
    if (this->degrees_kelvin <= temp.degrees_kelvin) return (1);
    return (0);
}
//
// fahrenheit.cpp
// Version timestamp: 2-9-2020, 1:33 PM
//
// Attribution : Copyright (c) 2018 Northern_Loki (sha256::6F290BF833967127BE26C92C8F6B1C1A3949C55A7EABCEF3ECC785CD2D38D30D)
// License is granted under the Creative Commons Attribution-ShareAlike 4.0 International.  https://creativecommons.org/licenses/by-sa/4.0/
//
# include "temperature_types.h"

fahrenheit::fahrenheit(fahrenheit_variant &r)
{
    fahrenheit_variant c = r;
    
    fahrenheit temp = boost::apply_visitor(tfahrenheit_variant(), c);
    this->degrees_fahrenheit = temp.degrees_fahrenheit;
}

fahrenheit::operator kelvin()
{
    kelvin temp = (this->degrees_fahrenheit - 32.0) / (1.8) + 273.15;
    return (temp);
}

fahrenheit::operator celcius()
{
    celcius temp = (this->degrees_fahrenheit - 32.0) / (1.8);
    return (temp);
}

fahrenheit::operator rankine()
{
    rankine temp = (this->degrees_fahrenheit + 459.67);
    return (temp);
}

void fahrenheit::operator=(fahrenheit_variant &temp2) 
{
    fahrenheit temp = boost::apply_visitor(tcelcius_variant(), temp2);
    this->degrees_fahrenheit = temp.degrees_fahrenheit;
}

fahrenheit fahrenheit::operator-(fahrenheit_variant temp2) 
{
    celcius temp = celcius(*this);
    temp -= boost::apply_visitor(tcelcius_variant(), temp2);
    
    return ((fahrenheit)temp);
}

fahrenheit fahrenheit::operator+(fahrenheit_variant temp2) 
{
    celcius temp = celcius(*this);
    temp += boost::apply_visitor(tcelcius_variant(), temp2);
    
    return ((fahrenheit)temp);
}

fahrenheit operator+(const double &c1, fahrenheit c2)
{
    celcius temp = c1 + celcius(c2);
    return ((fahrenheit)temp);
}

fahrenheit operator*(const double &c1, fahrenheit c2)
{
    celcius temp = c1 * celcius(c2);
    return ((fahrenheit)temp);
}

fahrenheit operator/(const double &c1, fahrenheit c2)
{
    celcius temp = c1 / celcius(c2);
    return ((fahrenheit)temp);
}

fahrenheit operator-(const double &c1, fahrenheit c2)
{
    celcius temp = c1 - celcius(c2);
    return ((fahrenheit)temp);
}

fahrenheit fahrenheit::operator*(fahrenheit_variant temp2) 
{
    celcius temp = celcius(*this);
    temp *= boost::apply_visitor(tcelcius_variant(), temp2);
    
    return ((fahrenheit)temp);
}

fahrenheit fahrenheit::operator/(fahrenheit_variant temp2) 
{
    celcius temp = celcius(*this);
    temp /= boost::apply_visitor(tcelcius_variant(), temp2);
    
    return ((fahrenheit)temp);
}

double fahrenheit::operator()(fahrenheit_variant temp2) 
{
    fahrenheit temp = boost::apply_visitor(tfahrenheit_variant(), temp2);
    return (temp.degrees_fahrenheit);
}

double fahrenheit::operator()() 
{
    double temp = this->degrees_fahrenheit;
    return (temp);
}

fahrenheit fahrenheit::operator-=(fahrenheit_variant temp2) 
{
    celcius temp = celcius(*this);
    temp = temp - boost::apply_visitor(tcelcius_variant(), temp2);
    fahrenheit tempf = temp;
    this->degrees_fahrenheit = tempf.degrees_fahrenheit;
    
    return (tempf);
}

fahrenheit fahrenheit::operator+=(fahrenheit_variant temp2) 
{
    celcius temp = celcius(*this);
    temp = temp + boost::apply_visitor(tcelcius_variant(), temp2);
    fahrenheit tempf = temp;
    this->degrees_fahrenheit = tempf.degrees_fahrenheit;
    
    return (tempf);
}

fahrenheit fahrenheit::operator++(int incr) 
{
    this->degrees_fahrenheit +=  1.0;
    return (this->degrees_fahrenheit);
}

fahrenheit fahrenheit::operator--(int incr) 
{
    this->degrees_fahrenheit -=  1.0;
    return (this->degrees_fahrenheit);
}

fahrenheit fahrenheit::operator*=(fahrenheit_variant temp2) 
{
    celcius temp = celcius(*this);
    temp = temp * boost::apply_visitor(tcelcius_variant(), temp2);
    fahrenheit tempf = temp;
    this->degrees_fahrenheit = tempf.degrees_fahrenheit;
    
    return (tempf);
}

fahrenheit fahrenheit::operator/=(fahrenheit_variant temp2) 
{
    celcius temp = celcius(*this);
    temp = temp / boost::apply_visitor(tcelcius_variant(), temp2);
    fahrenheit tempf = temp;
    this->degrees_fahrenheit = tempf.degrees_fahrenheit;
    
    return (tempf);
}

bool fahrenheit::operator>(fahrenheit_variant temp2) 
{ 
    fahrenheit temp = boost::apply_visitor(tfahrenheit_variant(), temp2);
    if (this->degrees_fahrenheit > temp.degrees_fahrenheit) return (1);
    return (0);
}

bool fahrenheit::operator<(fahrenheit_variant temp2) 
{
    fahrenheit temp = boost::apply_visitor(tfahrenheit_variant(), temp2);
    if (this->degrees_fahrenheit < temp.degrees_fahrenheit) return (1);
    return (0);
}

bool fahrenheit::operator==(fahrenheit_variant temp2) 
{
    fahrenheit temp = boost::apply_visitor(tfahrenheit_variant(), temp2);
    if (fabs(temp.degrees_fahrenheit - this->degrees_fahrenheit) <= 
    __DBL_EPSILON__ * fmax(fabs(temp.degrees_fahrenheit), fabs(this->degrees_fahrenheit))) return (1);
    return (0);
}

bool fahrenheit::operator!=(fahrenheit_variant temp2) 
{
    fahrenheit temp = boost::apply_visitor(tfahrenheit_variant(), temp2);
    if (fabs(temp.degrees_fahrenheit - this->degrees_fahrenheit) <= 
    __DBL_EPSILON__ * fmax(fabs(temp.degrees_fahrenheit), fabs(this->degrees_fahrenheit))) return (0);
    return (1);
}

bool fahrenheit::operator>=(fahrenheit_variant temp2) 
{
    fahrenheit temp = boost::apply_visitor(tfahrenheit_variant(), temp2);
    if (this->degrees_fahrenheit >= temp.degrees_fahrenheit) return (1);
    return (0);
}
bool fahrenheit::operator<=(fahrenheit_variant temp2) 
{
    fahrenheit temp = boost::apply_visitor(tfahrenheit_variant(), temp2);
    if (this->degrees_fahrenheit <= temp.degrees_fahrenheit) return (1);
    return (0);
}
//
// Celcius.cpp
// Version timestamp: 2-9-2020, 1:33 PM
//
// Attribution : Copyright (c) 2018 Northern_Loki (sha256::6F290BF833967127BE26C92C8F6B1C1A3949C55A7EABCEF3ECC785CD2D38D30D)
// License is granted under the Creative Commons Attribution-ShareAlike 4.0 International.  https://creativecommons.org/licenses/by-sa/4.0/
//
# include "temperature_types.h"

celcius::celcius(celcius_variant &r)
{
    celcius_variant c = r;
    
    celcius temp = boost::apply_visitor(tkelvin_variant(), c);
    this->degrees_celcius = temp.degrees_celcius;
}

celcius::operator kelvin()
{
    kelvin temp = this->degrees_celcius + 273.15;
    return (temp);
}

celcius::operator fahrenheit()
{
    fahrenheit temp = this->degrees_celcius * (1.8) + 32.0;
    return (temp);
}

celcius::operator rankine()
{
    rankine temp = (this->degrees_celcius + 273.15) * (1.8);
    return (temp);
}

void celcius::operator=(celcius_variant &temp2) 
{
    celcius temp = boost::apply_visitor(tcelcius_variant(), temp2);
    this->degrees_celcius = temp.degrees_celcius;
}

celcius celcius::operator-(celcius_variant temp2) 
{
    celcius temp = this->degrees_celcius - boost::apply_visitor(tcelcius_variant(), temp2);
    return (temp);
}

celcius celcius::operator+(celcius_variant temp2) 
{
    celcius temp = this->degrees_celcius + boost::apply_visitor(tcelcius_variant(), temp2);
    return (temp);
}

celcius operator+(const double &c1, const celcius &c2)
{
    celcius temp = c1 + c2.degrees_celcius;
    return (temp);
}

celcius operator*(const double &c1, const celcius &c2)
{
    celcius temp = c1 * c2.degrees_celcius;
    return (temp);
}

celcius operator/(const double &c1, const celcius &c2)
{
    celcius temp = c1 / c2.degrees_celcius;
    return (temp);
}

celcius operator-(const double &c1, const celcius &c2)
{
    celcius temp = c1 - c2.degrees_celcius;
    return (temp);
}

celcius celcius::operator++(int incr) 
{
    this->degrees_celcius +=  1.0;
    return (this->degrees_celcius);
}

celcius celcius::operator--(int incr) 
{
    this->degrees_celcius -=  1.0;
    return (this->degrees_celcius);
}

celcius celcius::operator*(celcius_variant temp2) 
{
    celcius temp = this->degrees_celcius * boost::apply_visitor(tcelcius_variant(), temp2);
    return (temp);
}

celcius celcius::operator/(celcius_variant temp2) 
{
    celcius temp = this->degrees_celcius / boost::apply_visitor(tcelcius_variant(), temp2);
    return (temp);
}

double celcius::operator()(celcius_variant temp2) 
{
    celcius temp = boost::apply_visitor(tcelcius_variant(), temp2);
    return (temp.degrees_celcius);
}

double celcius::operator()() 
{
    celcius temp = this->degrees_celcius;
    return (temp.degrees_celcius);
}

celcius celcius::operator-=(celcius_variant temp2) 
{
    celcius temp = this->degrees_celcius - boost::apply_visitor(tcelcius_variant(), temp2);
    this->degrees_celcius = temp.degrees_celcius;
    return (this->degrees_celcius);
}

celcius celcius::operator+=(celcius_variant temp2) 
{
    celcius temp = this->degrees_celcius + boost::apply_visitor(tcelcius_variant(), temp2);
    this->degrees_celcius = temp.degrees_celcius;
    return (this->degrees_celcius);
}

celcius celcius::operator*=(celcius_variant temp2) 
{
    celcius temp = this->degrees_celcius * boost::apply_visitor(tcelcius_variant(), temp2);
    this->degrees_celcius = temp.degrees_celcius;
    return (this->degrees_celcius);
}

celcius celcius::operator/=(celcius_variant temp2) 
{
    celcius temp = this->degrees_celcius / boost::apply_visitor(tcelcius_variant(), temp2);
    this->degrees_celcius = temp.degrees_celcius;
    return (this->degrees_celcius);
}

bool celcius::operator>(celcius_variant temp2) 
{
    celcius temp = boost::apply_visitor(tcelcius_variant(), temp2);
    if (this->degrees_celcius > temp.degrees_celcius) return (1);
    return (0);
}

bool celcius::operator<(celcius_variant temp2) 
{
    celcius temp = boost::apply_visitor(tcelcius_variant(), temp2);
    if (this->degrees_celcius < temp.degrees_celcius) return (1);
    return (0);
}

bool celcius::operator==(celcius_variant temp2) 
{
    celcius temp = boost::apply_visitor(tcelcius_variant(), temp2);
    if (fabs(temp.degrees_celcius - this->degrees_celcius) <= 
        __DBL_EPSILON__ * fmax(fabs(temp.degrees_celcius), fabs(this->degrees_celcius))) return (1);
    return (0);
}

bool celcius::operator!=(celcius_variant temp2) 
{
    celcius temp = boost::apply_visitor(tcelcius_variant(), temp2);
    if (fabs(temp.degrees_celcius - this->degrees_celcius) <=
        __DBL_EPSILON__ * fmax(fabs(temp.degrees_celcius), fabs(this->degrees_celcius))) return (0);
    return (1);
}

bool celcius::operator>=(celcius_variant temp2) 
{
    celcius temp = boost::apply_visitor(tcelcius_variant(), temp2);
    if (this->degrees_celcius >= temp.degrees_celcius) return (1);
    return (0);
}

bool celcius::operator<=(celcius_variant temp2) 
{
    celcius temp = boost::apply_visitor(tcelcius_variant(), temp2);
    if (this->degrees_celcius <= temp.degrees_celcius) return (1);
    return (0);
}

CC BY-SA 4.0

3 Likes