RealType
IRealType is interface for features of real number types.
/// <summary>Description of real number type features</summary>
public interface IRealType : INumberType, IUnitProvider, IValueRangeProvider<double>
{
/// <summary>
/// Precision of exponent in digits of <see cref="INumberType.Base"/>.
/// If <see cref="INumberType.Base"/> is two, then represents in number of bits.
///
/// Used for floating points.
///
/// Null if not valid for the number type.
/// </summary>
int? ExponentPrecision { get; set; }
/// <summary>
/// Fraction precision in digits of <see cref="INumberType.Base"/>.
/// Used for fixed points.
/// Null if not valid for the number type.
/// </summary>
int? FractionPrecision { get; set; }
/// <summary>
/// Integer precision in digits of <see cref="INumberType.Base"/>.
/// Used for fixed points.
/// Null if not valid for the number type.
/// </summary>
int? IntegerPrecision { get; set; }
/// <summary>Does the type have NaN capability.</summary>
bool NaNCapability { get; set; }
/// <summary>Does the type have Infinity capability.</summary>
bool InfinityCapability { get; set; }
}
/// <summary>Description of number type features</summary>
public interface INumberType : IValueType
{
/// <summary>
/// Internal base type.
/// 2 for binaries, and 10 for decimal.
/// </summary>
int? Base { get; set; }
/// <summary>
/// Precision of significand digits in units of <see cref="Base"/>.
///
/// This is mantissa for floating point types, and integer digits for integer types.
/// For fixed points, the sum of <see cref="IRealType.IntegerPrecision"/> and <see cref="IRealType.FractionPrecision"/>.
///
/// Null if not valid for the number type.
/// </summary>
int? SignificandPrecision { get; set; }
/// <summary>Does the type have sign feature.</summary>
bool SignCapability { get; set; }
}
/// <summary>Provides Unit property.</summary>
public interface IUnitProvider
{
/// <summary>Unit property, e.g. "m/s".</summary>
string? Unit { get; set; }
}
/// <summary>Interface for min and max value range properties.</summary>
public interface IValueRangeProvider<T> where T : struct
{
/// <summary>Minimum value. Null if not valid for type, assigned or assignable.</summary>
Nullable<T> MinValue { get; set; }
/// <summary>Maximum value. Null if not valid for type, assigned or assignable.</summary>
Nullable<T> MaxValue { get; set; }
}
IDataType └── IValueType └── INumberType └── IRealType
RealType is the default implementation.
IRealType datatype = new RealType
{
Name = Identities.CreateName("myfloat").SetReadOnly(),
Annotations = { },
Description = "",
Unassignable = false,
Referable = false,
MinValue = (double?)0.0,
MaxValue = (double?)65536.0,
SignCapability = false,
SignificandPrecision = 16,
ExponentPrecision = 4,
FractionPrecision = null,
IntegerPrecision = null,
NaNCapability = false,
InfinityCapability = false,
Base = 2
}.SetReadOnly();
IRealType { Name = "myfloat" , ExponentPrecision = 4, NaNCapability = False, InfinityCapability = False, Base = 2, SignificandPrecision = 16, SignCapability = False, Nullable = False, Referable = False, Description = "", Annotations = [], MinValue = 0, MaxValue = 65536 }
RealTypeRequest is request for a real type when sub-requests are needed.
// Create service
IService service = Services.Create(NetTypeHandlers.Instance);
// Create request
RealTypeRequest request = new RealTypeRequest
{
Name = Identities.CreateName("myfloat").SetReadOnly(),
Annotations = new Dictionary<string, string> { { IDataType.Annotation.Description, "short float" } },
Unassignable = null,
Referable = null,
MinValue = (double?)0,
MaxValue = (double?)65536,
SignCapability = false,
SignificandPrecision = 16,
ExponentPrecision = 4,
FractionPrecision = null,
IntegerPrecision = null,
NaNCapability = false,
InfinityCapability = false,
Base = 2
};
// Query
IRealType datatype = service.GetRequired<IRequestFor<IRealType>, IRealType>(request);
DataTypeRequest<NetReal> is a request for real type by Type. (Avalanche.DataType.Net.dll)
// Create service
IService service = Services.Create(NetTypeHandlers.Instance);
// Create request
DataTypeRequest<NetReal> request = new(typeof(float));
// Request record
IRealType datatype = service.GetRequired<DataTypeRequest<NetReal>, IRealType>(request);
IRealType { Name = "float" , ExponentPrecision = 7, NaNCapability = True, InfinityCapability = True, Base = 2, SignificandPrecision = 23, SignCapability = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -3,4028234663852886E+38, MaxValue = 3,4028234663852886E+38 }
DataTypes facade contains type definitions for .NET types.
WriteLine(DataTypes.Float.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Double.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Decimal.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
IRealType { Name = "float" , ExponentPrecision = 7, NaNCapability = True, InfinityCapability = True, Base = 2, SignificandPrecision = 23, SignCapability = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -3,4028234663852886E+38, MaxValue = 3,4028234663852886E+38 } IRealType { Name = "double" , ExponentPrecision = 10, NaNCapability = True, InfinityCapability = True, Base = 2, SignificandPrecision = 52, SignCapability = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -1,7976931348623157E+308, MaxValue = 1,7976931348623157E+308 } IRealType { Name = "decimal" , ExponentPrecision = 8, NaNCapability = False, InfinityCapability = False, Base = 2, SignificandPrecision = 96, SignCapability = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -7,922816251426434E+28, MaxValue = 7,922816251426434E+28 }
Full Example
Full example
using System.Collections.Generic;
using Avalanche.DataType;
using Avalanche.Identity;
using Avalanche.Service;
using Avalanche.Utilities;
using static System.Console;
public class realtype
{
public static void Run()
{
{
// <01>
IRealType datatype = new RealType
{
Name = Identities.CreateName("myfloat").SetReadOnly(),
Annotations = { },
Description = "",
Unassignable = false,
Referable = false,
MinValue = (double?)0.0,
MaxValue = (double?)65536.0,
SignCapability = false,
SignificandPrecision = 16,
ExponentPrecision = 4,
FractionPrecision = null,
IntegerPrecision = null,
NaNCapability = false,
InfinityCapability = false,
Base = 2
}.SetReadOnly();
// </01>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <03>
// Create service
IService service = Services.Create(NetTypeHandlers.Instance);
// Create request
RealTypeRequest request = new RealTypeRequest
{
Name = Identities.CreateName("myfloat").SetReadOnly(),
Annotations = new Dictionary<string, string> { { IDataType.Annotation.Description, "short float" } },
Unassignable = null,
Referable = null,
MinValue = (double?)0,
MaxValue = (double?)65536,
SignCapability = false,
SignificandPrecision = 16,
ExponentPrecision = 4,
FractionPrecision = null,
IntegerPrecision = null,
NaNCapability = false,
InfinityCapability = false,
Base = 2
};
// Query
IRealType datatype = service.GetRequired<IRequestFor<IRealType>, IRealType>(request);
// </03>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <04>
// Create service
IService service = Services.Create(NetTypeHandlers.Instance);
// Create request
DataTypeRequest<NetReal> request = new(typeof(float));
// Request record
IRealType datatype = service.GetRequired<DataTypeRequest<NetReal>, IRealType>(request);
// </04>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <05>
WriteLine(DataTypes.Float.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Double.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Decimal.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
// </05>
}
}
}