-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoot.cs
More file actions
46 lines (39 loc) · 1.24 KB
/
Copy pathRoot.cs
File metadata and controls
46 lines (39 loc) · 1.24 KB
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
using Ricis.Core.Rationals;
using System.Linq.Expressions;
namespace Ricis.Core;
/// <summary>
/// Представление одного точного корня
/// </summary>
public readonly struct Root : IEquatable<Root>
{
public ParameterExpression Parameter { get; }
public Rational? RationalValue { get; } // если корень рациональный
public double DoubleValue { get; } // всегда есть (для подстановки)
public Root(ParameterExpression param, Rational value)
{
Parameter = param;
RationalValue = value;
DoubleValue = value.ToDouble();
}
public Root(ParameterExpression param, double value)
{
Parameter = param;
RationalValue = null;
DoubleValue = value;
}
public bool Equals(Root other)
{
return Parameter == other.Parameter &&
Math.Abs(DoubleValue - other.DoubleValue) == 0;
}
public override int GetHashCode()
{
return HashCode.Combine(Parameter, DoubleValue);
}
public override string ToString()
{
return RationalValue.HasValue
? $"{Parameter.Name} = {RationalValue.Value}"
: $"{Parameter.Name} ≈ {DoubleValue:R}";
}
}