Table of Contents

Class VBNumericType

Namespace
RDCore.SDK.Model.Types.Abstract
Assembly
RDCore.SDK.dll

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

Name string

The name (token) of the data type.

ManagedType Type

Properties

ManagedMaxValue

Gets the maximum representable managed (.net) value for this data type.

public abstract double ManagedMaxValue { get; }

Property Value

double

ManagedMinValue

Gets the minimum representable managed (.net) value for this data type.

public abstract double ManagedMinValue { get; }

Property Value

double

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

value VBNumericTypedValue

The numeric value to be rounded.

Returns

double

The nearest whole number, as a double.

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

value double

The 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

value double

Returns

VBNumericTypedValue

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

value double

The value. NaN is within no range.

Returns

bool

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

source double

The managed (.net) numeric source value to validate.

destination VBNumericType

The data type to check conversion eligibility against.

Returns

bool

true if the value can legally be used with the destination type, false otherwise.

Remarks

If this function returns false, the caller should throw a VBRuntimeErrorOverflowException.