forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyFloat.IComparable.cs
More file actions
34 lines (26 loc) · 943 Bytes
/
PyFloat.IComparable.cs
File metadata and controls
34 lines (26 loc) · 943 Bytes
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
using System;
namespace Python.Runtime;
partial class PyFloat : IComparable<double>, IComparable<float>
, IEquatable<double>, IEquatable<float>
, IComparable<PyFloat?>, IEquatable<PyFloat?>
{
public override bool Equals(object o)
{
using var _ = Py.GIL();
return o switch
{
double f64 => this.Equals(f64),
float f32 => this.Equals(f32),
_ => base.Equals(o),
};
}
public int CompareTo(double other) => this.ToDouble().CompareTo(other);
public int CompareTo(float other) => this.ToDouble().CompareTo(other);
public bool Equals(double other) => this.ToDouble().Equals(other);
public bool Equals(float other) => this.ToDouble().Equals(other);
public int CompareTo(PyFloat? other)
{
return other is null ? 1 : this.CompareTo(other.BorrowNullable());
}
public bool Equals(PyFloat? other) => base.Equals(other);
}