- A < B ....... A - B < - EPS
- A > B ....... A - B > EPS
- A == B ....... abs(A - B) <= EPS
- A <= B ....... A - B <= EPS
- A >= B ....... A - B >= - EPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef SUNMOON_DOUBLE | |
#define SUNMOON_DOUBLE | |
#include <cmath> | |
#include <iostream> | |
const double EPS = 1e-9; | |
struct Double { | |
double d; | |
Double(double d = 0) : d(d) {} | |
Double operator-() const { return -d; } | |
Double operator+(const Double &b) const { return d + b.d; } | |
Double operator-(const Double &b) const { return d - b.d; } | |
Double operator*(const Double &b) const { return d * b.d; } | |
Double operator/(const Double &b) const { return d / b.d; } | |
Double operator+=(const Double &b) { return d += b.d; } | |
Double operator-=(const Double &b) { return d -= b.d; } | |
Double operator*=(const Double &b) { return d *= b.d; } | |
Double operator/=(const Double &b) { return d /= b.d; } | |
bool operator<(const Double &b) const { return d - b.d < -EPS; } | |
bool operator>(const Double &b) const { return d - b.d > EPS; } | |
bool operator==(const Double &b) const { return fabs(d - b.d) <= EPS; } | |
bool operator!=(const Double &b) const { return fabs(d - b.d) > EPS; } | |
bool operator<=(const Double &b) const { return d - b.d <= EPS; } | |
bool operator>=(const Double &b) const { return d - b.d >= -EPS; } | |
friend std::ostream &operator<<(std::ostream &os, const Double &db) { | |
return os << db.d; | |
} | |
friend std::istream &operator>>(std::istream &is, Double &db) { | |
return is >> db.d; | |
} | |
}; | |
#endif |
沒有留言:
張貼留言