Class VBNumericType
Represents any numeric data type mentioned in the MS-VBAL language specifications.
public abstract record VBNumericType : VBIntrinsicType, IEquatable<VBType>, IEquatable<VBIntrinsicType>, INumericType, IEquatable<VBNumericType>
- Inheritance
-
VBNumericType
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
VBNumericType(string, Type)
Represents any numeric data type mentioned in the MS-VBAL language specifications.
protected VBNumericType(string Name, Type ManagedType)
Parameters
Properties
ManagedMaxValue
Gets the maximum representable managed (.net) value for this data type.
public abstract double ManagedMaxValue { get; }
Property Value
ManagedMinValue
Gets the minimum representable managed (.net) value for this data type.
public abstract double ManagedMinValue { get; }
Property Value
Methods
BankersRounding(VBNumericTypedValue)
Implements MS-VBAL 5.5.1.2.1.1 Banker's Rounding. A midpoint rounding scheme also known as "round-to-even" rounds to the nearest rounded value such that the least-significant digit is even.
public static double BankersRounding(VBNumericTypedValue value)
Parameters
valueVBNumericTypedValueThe numeric value to be rounded.
Returns
BankersRounding(double)
Implements MS-VBAL 5.5.1.2.1.1 Banker's Rounding. A midpoint rounding scheme also known as "round-to-even" rounds to the nearest rounded value such that the least-significant digit is even.
public static double BankersRounding(double value)
Parameters
valuedoubleThe floating-point numeric value to be rounded.
Returns
- double
The nearest whole number, as a double: a whole number past the range of an int is still the one it rounds to.
CreateValue(double)
Creates a value of this numeric type holding value, converted to this
type's managed representation (banker's rounding for integral targets, as per Convert).
public abstract VBNumericTypedValue CreateValue(double value)
Parameters
valuedouble
Returns
Holds(double)
Whether a double is within the range of this type (MS-VBAL 5.5.1.2.1): one a value of this type can be made of (CreateValue(double)) without leaving the range.
public virtual bool Holds(double value)
Parameters
valuedoubleThe value.
NaNis within no range.
Returns
Remarks
👉 The base is within ManagedMinValue and ManagedMaxValue, both included, which is right for a type whose bounds are double values. A type whose bound is not one has, as its ManagedMaxValue or ManagedMinValue, the double nearest it, which can be past it: that type overrides this, and leaves out such a bound.
IsWithinRange(double, VBNumericType)
A helper function to test if a given source numeric value is within the range of a destination data type.
public static bool IsWithinRange(double source, VBNumericType destination)
Parameters
sourcedoubleThe managed (.net) numeric source value to validate.
destinationVBNumericTypeThe data type to check conversion eligibility against.
Returns
- bool
trueif the value can legally be used with the destination type,false otherwise.
Remarks
If this function returns false, the caller should throw a VBRuntimeErrorOverflowException.