Show/Hide Toolbars

XSharp

The USUAL type is a datatype that can contain any data type. It consists internally of a type flag and a value. This type can store any value.

The compiler treats this type in a special way. The compiler will not warn you when you assign a value of type USUAL to another type, but will automatically generate the necessary conversion operation.

 

USUAL is provided primarily for compatibility with untyped code. It is not recommended for use in new code because the compiler cannot perform any type checking on expressions where one or more operands are USUAL. Any data type errors will only be discovered at runtime.

 

Locals, parameters and fields declared as USUAL also incur considerably more runtime overhead than strongly typed variables.

 

The literal value NIL may be assigned into any storage location typed as USUAL. The value NIL indicates the absence of any other data type or value, and is conceptually equivalent to storing NULL into a reference type. NIL is the default value for a local USUAL variable that has not been initialized.

 

When the left operand of the ':' operator is a USUAL, the compiler will generate a late bound call to the method, field or property specified as the right operand. This call may fail if the value contained in the USUAL at runtime does not have such a member, the member type is incorrect or inaccessible, or if the name evaluates to a method and the number of parameters or their types is incorrect. The /lb compiler option must be enabled in order to use a USUAL as the left operand of the ':' operator; otherwise, a compile-time error will be raised.

 

Numeric operations and USUAL variables of mixed types.

When you combine two USUAL variables in a numeric operation then the type of the result is derived from the types of operands.
The leading principle has been that we try not to loose decimals.

 

The generic rule is:

When the Left Hand Side (LHS) is fractional, then the result is also fractional of the type of the LHS.

When the LHS is NOT fractional and the Right Hand Side (RHS) is fractional, then the result is the type of the RHS.

When both sides are integral, then the result has the type of the largest of the two.

 

 

LHS        

\ RHS

LONG

INT64

FLOAT

CURRENCY

DECIMAL

LONG


LONG

INT64

FLOAT

CURRENCY

DECIMAL

INT64


INT64

INT64

FLOAT

CURRENCY

DECIMAL

FLOAT


FLOAT

FLOAT

FLOAT

FLOAT

FLOAT

CURRENCY


CURRENCY

CURRENCY

CURRENCY

CURRENCY

CURRENCY

DECIMAL


DECIMAL

DECIMAL

DECIMAL

DECIMAL

DECIMAL

 

Implementation

The USUAL type is implemented in the structure  XSharp.__Usual.