| 1 |
#Region "Microsoft.VisualBasic::ee81197d8117588452030dc667220d62, Microsoft.VisualBasic.Core\Language\Value\Numeric\float.vb"
|
| 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 |
#End Region
|
| 48 |
|
| 49 |
Imports System.Runtime.CompilerServices
|
| 50 |
|
| 51 |
Namespace Language
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
Public Class float : Inherits Value(Of Double)
|
| 57 |
Implements IComparable
|
| 58 |
Implements IConvertible
|
| 59 |
Implements IEquatable(Of Double)
|
| 60 |
|
| 61 |
Sub New(x#)
|
| 62 |
Value = x#
|
| 63 |
End Sub
|
| 64 |
|
| 65 |
Sub New()
|
| 66 |
Me.New(0R)
|
| 67 |
End Sub
|
| 68 |
|
| 69 |
Public Overrides Function ToString() As String
|
| 70 |
Return Value
|
| 71 |
End Function
|
| 72 |
|
| 73 |
Public Function CompareTo(obj As Object) As Integer Implements IComparable.CompareTo
|
| 74 |
Dim type As Type = obj.GetType
|
| 75 |
|
| 76 |
If type.Equals(GetType(Double)) Then
|
| 77 |
Return Value.CompareTo(DirectCast(obj, Double))
|
| 78 |
ElseIf type.Equals(GetType(float)) Then
|
| 79 |
Return Value.CompareTo(DirectCast(obj, float).Value)
|
| 80 |
Else
|
| 81 |
Throw New Exception($"Miss-match of type: {GetType(float).FullName} --> {type.FullName}")
|
| 82 |
End If
|
| 83 |
End Function
|
| 84 |
|
| 85 |
#Region "Numeric operators"
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
Public Shared Operator <(n#, x As float) As float
|
| 95 |
If n >= x.Value Then
|
| 96 |
Return New float(Double.MaxValue)
|
| 97 |
Else
|
| 98 |
Return x
|
| 99 |
End If
|
| 100 |
End Operator
|
| 101 |
|
| 102 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 103 |
Public Shared Operator *(n#, x As float) As Double
|
| 104 |
Return n * x.Value
|
| 105 |
End Operator
|
| 106 |
|
| 107 |
Public Overloads Shared Operator +(x As float, y As float) As Double
|
| 108 |
Return x.Value + y.Value
|
| 109 |
End Operator
|
| 110 |
|
| 111 |
Public Overloads Shared Operator /(x As float, y As float) As Double
|
| 112 |
Return x.Value / y.Value
|
| 113 |
End Operator
|
| 114 |
|
| 115 |
Public Overloads Shared Operator +(x#, y As float) As Double
|
| 116 |
Return x + y.Value
|
| 117 |
End Operator
|
| 118 |
|
| 119 |
Public Overloads Shared Widening Operator CType(x As Double) As float
|
| 120 |
Return New float(x)
|
| 121 |
End Operator
|
| 122 |
|
| 123 |
Public Overloads Shared Operator <=(x As float, n As Double) As Boolean
|
| 124 |
Return x.Value <= n
|
| 125 |
End Operator
|
| 126 |
|
| 127 |
Public Overloads Shared Operator >=(x As float, n As Double) As Boolean
|
| 128 |
Return x.Value >= n
|
| 129 |
End Operator
|
| 130 |
|
| 131 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 132 |
Public Overloads Shared Operator /(x As float, n As Double) As Double
|
| 133 |
Return x.Value / n
|
| 134 |
End Operator
|
| 135 |
|
| 136 |
Public Shared Operator >(n As Double, x As float) As float
|
| 137 |
Return x
|
| 138 |
End Operator
|
| 139 |
|
| 140 |
Public Shared Operator ^(x As float, power As Double) As Double
|
| 141 |
Return x.Value ^ power
|
| 142 |
End Operator
|
| 143 |
|
| 144 |
Public Overloads Shared Narrowing Operator CType(f As float) As Double
|
| 145 |
Return f.Value
|
| 146 |
End Operator
|
| 147 |
|
| 148 |
Public Overloads Shared Operator -(a As float, b As float) As Double
|
| 149 |
Return a.Value - b.Value
|
| 150 |
End Operator
|
| 151 |
|
| 152 |
Public Overloads Shared Operator *(a As float, b As float) As Double
|
| 153 |
Return a.Value * b.Value
|
| 154 |
End Operator
|
| 155 |
#End Region
|
| 156 |
|
| 157 |
#Region "Implements IConvertible"
|
| 158 |
|
| 159 |
Public Function GetTypeCode() As TypeCode Implements IConvertible.GetTypeCode
|
| 160 |
Return TypeCode.Double
|
| 161 |
End Function
|
| 162 |
|
| 163 |
Public Function ToBoolean(provider As IFormatProvider) As Boolean Implements IConvertible.ToBoolean
|
| 164 |
If Value = 0R Then
|
| 165 |
Return False
|
| 166 |
Else
|
| 167 |
Return True
|
| 168 |
End If
|
| 169 |
End Function
|
| 170 |
|
| 171 |
Public Function ToChar(provider As IFormatProvider) As Char Implements IConvertible.ToChar
|
| 172 |
Return ChrW(CInt(Value))
|
| 173 |
End Function
|
| 174 |
|
| 175 |
Public Function ToSByte(provider As IFormatProvider) As SByte Implements IConvertible.ToSByte
|
| 176 |
Return CSByte(Value)
|
| 177 |
End Function
|
| 178 |
|
| 179 |
Public Function ToByte(provider As IFormatProvider) As Byte Implements IConvertible.ToByte
|
| 180 |
Return CByte(Value)
|
| 181 |
End Function
|
| 182 |
|
| 183 |
Public Function ToInt16(provider As IFormatProvider) As Short Implements IConvertible.ToInt16
|
| 184 |
Return CShort(Value)
|
| 185 |
End Function
|
| 186 |
|
| 187 |
Public Function ToUInt16(provider As IFormatProvider) As UShort Implements IConvertible.ToUInt16
|
| 188 |
Return CUShort(Value)
|
| 189 |
End Function
|
| 190 |
|
| 191 |
Public Function ToInt32(provider As IFormatProvider) As Integer Implements IConvertible.ToInt32
|
| 192 |
Return CInt(Value)
|
| 193 |
End Function
|
| 194 |
|
| 195 |
Public Function ToUInt32(provider As IFormatProvider) As UInteger Implements IConvertible.ToUInt32
|
| 196 |
Return CUInt(Value)
|
| 197 |
End Function
|
| 198 |
|
| 199 |
Public Function ToInt64(provider As IFormatProvider) As Long Implements IConvertible.ToInt64
|
| 200 |
Return CLng(Value)
|
| 201 |
End Function
|
| 202 |
|
| 203 |
Public Function ToUInt64(provider As IFormatProvider) As ULong Implements IConvertible.ToUInt64
|
| 204 |
Return CULng(Value)
|
| 205 |
End Function
|
| 206 |
|
| 207 |
Public Function ToSingle(provider As IFormatProvider) As Single Implements IConvertible.ToSingle
|
| 208 |
Return CSng(Value)
|
| 209 |
End Function
|
| 210 |
|
| 211 |
Public Function ToDouble(provider As IFormatProvider) As Double Implements IConvertible.ToDouble
|
| 212 |
Return Value
|
| 213 |
End Function
|
| 214 |
|
| 215 |
Public Function ToDecimal(provider As IFormatProvider) As Decimal Implements IConvertible.ToDecimal
|
| 216 |
Return CDec(Value)
|
| 217 |
End Function
|
| 218 |
|
| 219 |
Public Function ToDateTime(provider As IFormatProvider) As Date Implements IConvertible.ToDateTime
|
| 220 |
Return Date.FromBinary(CLng(Value))
|
| 221 |
End Function
|
| 222 |
|
| 223 |
Public Overloads Function ToString(provider As IFormatProvider) As String Implements IConvertible.ToString
|
| 224 |
Return Value.ToString(provider)
|
| 225 |
End Function
|
| 226 |
|
| 227 |
Public Function ToType(conversionType As Type, provider As IFormatProvider) As Object Implements IConvertible.ToType
|
| 228 |
Return CTypeDynamic(Value, conversionType)
|
| 229 |
End Function
|
| 230 |
#End Region
|
| 231 |
|
| 232 |
#Region "Implements IEquatable(Of Double)"
|
| 233 |
Public Overloads Function Equals(other As Double) As Boolean Implements IEquatable(Of Double).Equals
|
| 234 |
Return Value = other
|
| 235 |
End Function
|
| 236 |
#End Region
|
| 237 |
|
| 238 |
End Class
|
| 239 |
End Namespace
|