forked from peteroupc/CBOR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtendedRational.cs
211 lines (182 loc) · 6.94 KB
/
ExtendedRational.cs
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
Written in 2014 by Peter O.
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
If you like this, you should donate to Peter O.
at: http://peteroupc.github.io/
*/
using System;
using PeterO.Numbers;
namespace PeterO {
/// <include file='../docs.xml'
/// path='docs/doc[@name="T:PeterO.ExtendedRational"]/*'/>
[Obsolete(
"Use ERational from PeterO.Numbers/com.upokecenter.numbers and the output of this class's ToString method.")]
public sealed class ExtendedRational : IComparable<ExtendedRational>,
IEquatable<ExtendedRational> {
/// <include file='../docs.xml'
/// path='docs/doc[@name="F:PeterO.ExtendedRational.NaN"]/*'/>
[Obsolete("Use ERational from PeterO.Numbers/com.upokecenter.numbers.")]
public static readonly ExtendedRational NaN =
new ExtendedRational(ERational.NaN);
/// <include file='../docs.xml'
/// path='docs/doc[@name="F:PeterO.ExtendedRational.NegativeInfinity"]/*'/>
public static readonly ExtendedRational NegativeInfinity = new
ExtendedRational(ERational.NegativeInfinity);
/// <include file='../docs.xml'
/// path='docs/doc[@name="F:PeterO.ExtendedRational.NegativeZero"]/*'/>
public static readonly ExtendedRational NegativeZero =
new ExtendedRational(ERational.NegativeZero);
/// <include file='../docs.xml'
/// path='docs/doc[@name="F:PeterO.ExtendedRational.One"]/*'/>
public static readonly ExtendedRational One =
FromBigIntegerInternal(BigInteger.One);
/// <include file='../docs.xml'
/// path='docs/doc[@name="F:PeterO.ExtendedRational.PositiveInfinity"]/*'/>
public static readonly ExtendedRational PositiveInfinity = new
ExtendedRational(ERational.PositiveInfinity);
/// <include file='../docs.xml'
/// path='docs/doc[@name="F:PeterO.ExtendedRational.SignalingNaN"]/*'/>
[Obsolete("Use ERational from PeterO.Numbers/com.upokecenter.numbers.")]
public static readonly ExtendedRational SignalingNaN = new
ExtendedRational(ERational.SignalingNaN);
/// <include file='../docs.xml'
/// path='docs/doc[@name="F:PeterO.ExtendedRational.Ten"]/*'/>
public static readonly ExtendedRational Ten =
FromBigIntegerInternal(BigInteger.valueOf(10));
/// <include file='../docs.xml'
/// path='docs/doc[@name="F:PeterO.ExtendedRational.Zero"]/*'/>
public static readonly ExtendedRational Zero =
FromBigIntegerInternal(BigInteger.Zero);
private readonly ERational er;
/// <include file='../docs.xml'
/// path='docs/doc[@name="M:PeterO.ExtendedRational.#ctor(PeterO.BigInteger,PeterO.BigInteger)"]/*'/>
public ExtendedRational(BigInteger numerator, BigInteger denominator) {
this.er = new ERational(numerator.Ei, denominator.Ei);
}
internal ExtendedRational(ERational er) {
if (er == null) {
throw new ArgumentNullException("er");
}
this.er = er;
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="P:PeterO.ExtendedRational.Denominator"]/*'/>
public BigInteger Denominator {
get {
return new BigInteger(this.Er.Denominator);
}
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="P:PeterO.ExtendedRational.IsFinite"]/*'/>
[Obsolete("Use ERational from PeterO.Numbers/com.upokecenter.numbers.")]
public bool IsFinite {
get {
return this.Er.IsFinite;
}
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="P:PeterO.ExtendedRational.IsNegative"]/*'/>
public bool IsNegative {
get {
return this.Er.IsNegative;
}
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="P:PeterO.ExtendedRational.IsZero"]/*'/>
[Obsolete("Use ERational from PeterO.Numbers/com.upokecenter.numbers.")]
public bool IsZero {
get {
return this.Er.IsZero;
}
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="P:PeterO.ExtendedRational.Numerator"]/*'/>
public BigInteger Numerator {
get {
return new BigInteger(this.Er.Numerator);
}
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="P:PeterO.ExtendedRational.Sign"]/*'/>
[Obsolete("Use ERational from PeterO.Numbers/com.upokecenter.numbers.")]
public int Sign {
get {
return this.Er.Sign;
}
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="P:PeterO.ExtendedRational.UnsignedNumerator"]/*'/>
public BigInteger UnsignedNumerator {
get {
return new BigInteger(this.Er.UnsignedNumerator);
}
}
internal ERational Er {
get {
return this.er;
}
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="M:PeterO.ExtendedRational.Create(System.Int32,System.Int32)"]/*'/>
public static ExtendedRational Create(
int numeratorSmall,
int denominatorSmall) {
return new ExtendedRational(
ERational.Create(
numeratorSmall,
denominatorSmall));
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="M:PeterO.ExtendedRational.Create(PeterO.BigInteger,PeterO.BigInteger)"]/*'/>
public static ExtendedRational Create(
BigInteger numerator,
BigInteger denominator) {
if (numerator == null) {
throw new ArgumentNullException("numerator");
}
if (denominator == null) {
throw new ArgumentNullException("denominator");
}
return new ExtendedRational(
ERational.Create(
numerator.Ei,
denominator.Ei));
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="M:PeterO.ExtendedRational.ToString"]/*'/>
public override string ToString() {
return this.Er.ToString();
}
internal static ERational FromLegacy(ExtendedRational bei) {
return bei.Er;
}
internal static ExtendedRational ToLegacy(ERational ei) {
return new ExtendedRational(ei);
}
private static ExtendedRational FromBigIntegerInternal(BigInteger bigint) {
return new ExtendedRational(ERational.FromEInteger(bigint.Ei));
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="M:PeterO.ExtendedRational.CompareTo(PeterO.ExtendedRational)"]/*'/>
public int CompareTo(ExtendedRational other) {
return this.Er.CompareTo(other == null ? null : other.Er);
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="M:PeterO.ExtendedRational.Equals(PeterO.ExtendedRational)"]/*'/>
public bool Equals(ExtendedRational other) {
return this.Er.Equals(other == null ? null : other.Er);
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="M:PeterO.ExtendedRational.Equals(System.Object)"]/*'/>
public override bool Equals(object obj) {
var other = obj as ExtendedRational;
return this.Er.Equals(other == null ? null : other.Er);
}
/// <include file='../docs.xml'
/// path='docs/doc[@name="M:PeterO.ExtendedRational.GetHashCode"]/*'/>
public override int GetHashCode() {
return this.Er.GetHashCode();
}
}
}