-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextreal.cpp
99 lines (89 loc) · 2.59 KB
/
extreal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// extreal.cpp ----------------------------------------------------------
#define WANT_STREAM
#include "include.h"
#include "boolean.h"
#include "extreal.h"
#ifdef use_namespace
//namespace NEWRAN {
#endif
ExtReal ExtReal::operator+(const ExtReal& er) const
{
if (c==Finite && er.c==Finite) return ExtReal(value+er.value);
if (c==Missing || er.c==Missing) return ExtReal(Missing);
if (c==Indefinite || er.c==Indefinite) return ExtReal(Indefinite);
if (c==PlusInfinity)
{
if (er.c==MinusInfinity) return ExtReal(Indefinite);
return *this;
}
if (c==MinusInfinity)
{
if (er.c==PlusInfinity) return ExtReal(Indefinite);
return *this;
}
return er;
}
ExtReal ExtReal::operator-(const ExtReal& er) const
{
if (c==Finite && er.c==Finite) return ExtReal(value-er.value);
if (c==Missing || er.c==Missing) return ExtReal(Missing);
if (c==Indefinite || er.c==Indefinite) return ExtReal(Indefinite);
if (c==PlusInfinity)
{
if (er.c==PlusInfinity) return ExtReal(Indefinite);
return *this;
}
if (c==MinusInfinity)
{
if (er.c==MinusInfinity) return ExtReal(Indefinite);
return *this;
}
return er;
}
ExtReal ExtReal::operator*(const ExtReal& er) const
{
if (c==Finite && er.c==Finite) return ExtReal(value*er.value);
if (c==Missing || er.c==Missing) return ExtReal(Missing);
if (c==Indefinite || er.c==Indefinite) return ExtReal(Indefinite);
if (c==Finite)
{
if (value==0.0) return ExtReal(Indefinite);
if (value>0.0) return er;
return (-er);
}
if (er.c==Finite)
{
if (er.value==0.0) return ExtReal(Indefinite);
if (er.value>0.0) return *this;
return -(*this);
}
if (c==PlusInfinity) return er;
return (-er);
}
ExtReal ExtReal::operator-() const
{
switch (c)
{
case Finite: return ExtReal(-value);
case PlusInfinity: return ExtReal(MinusInfinity);
case MinusInfinity: return ExtReal(PlusInfinity);
case Indefinite: return ExtReal(Indefinite);
case Missing: return ExtReal(Missing);
}
return 0.0;
}
std::ostream& operator<<(std::ostream& os, const ExtReal& er)
{
switch (er.c)
{
case Finite: os << er.value; break;
case PlusInfinity: os << "plus-infinity"; break;
case MinusInfinity: os << "minus-infinity"; break;
case Indefinite: os << "indefinite"; break;
case Missing: os << "missing"; break;
}
return os;
}
#ifdef use_namespace
}
#endif