FloatingPointType
IFloatingPointType is interface for features of real number types.
/// <summary>Description of floating point number type features</summary>
public interface IFloatingPointType : INumberType, IUnitProvider, INumberMinMax<double>
{
/// <summary>
/// Precision of exponent in digits of <see cref="INumberType.Radix"/>.
/// If <see cref="INumberType.Radix"/> 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.Radix"/>.
/// 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.Radix"/>.
/// 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>The number of unique digits in positional number system.</summary>
int? Radix { get; set; }
/// <summary>
/// Precision of significand digits in units of <see cref="Radix"/>.
///
/// This is mantissa for floating point types, and integer digits for integer types.
/// For fixed points, the sum of <see cref="IFloatingPointType.IntegerPrecision"/> and <see cref="IFloatingPointType.FractionPrecision"/>.
///
/// Null if not valid for the number type.
/// </summary>
int? SignificandPrecision { get; set; }
/// <summary>Is number type signed.</summary>
bool Signed { get; set; }
}
/// <summary>Provides Unit property.</summary>
public interface IUnitProvider
{
/// <summary>Unit property, e.g. "m/s".</summary>
string? Unit { get; set; }
}
IDataType └── IValueType └── INumberType └── IFloatingPointType
FloatingPointType is the default implementation.
IFloatingPointType datatype = new FloatingPointType
{
Name = Identities.CreateName("myfloat").SetReadOnly(),
Properties = { },
Description = "",
Unassignable = false,
Referable = false,
MinValue = (double?)0.0,
MaxValue = (double?)65536.0,
Signed = false,
SignificandPrecision = 16,
ExponentPrecision = 4,
FractionPrecision = null,
IntegerPrecision = null,
NaNCapability = false,
InfinityCapability = false,
Radix = 2
}.SetReadOnly();
IFloatingPointType { Name = "myfloat" , ExponentPrecision = 4, NaNCapability = False, InfinityCapability = False, Base = 2, SignificandPrecision = 16, Signed = False, Nullable = False, Referable = False, Description = "", Annotations = [], MinValue = 0, MaxValue = 65536 }
FloatingPointTypeRequest is request for a real type when sub-requests are needed.
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
FloatingPointTypeRequest request = new FloatingPointTypeRequest
{
Name = Identities.CreateName("myfloat").SetReadOnly(),
Properties = new Dictionary<string, string> { { IDataType.Property.Description, "short float" } },
Unassignable = null,
Referable = null,
MinValue = (double?)0,
MaxValue = (double?)65536,
Signed = false,
SignificandPrecision = 16,
ExponentPrecision = 4,
FractionPrecision = null,
IntegerPrecision = null,
NaNCapability = false,
InfinityCapability = false,
Radix = 2
};
// Query
IFloatingPointType datatype = service.GetRequired<IRequestFor<IFloatingPointType>, IFloatingPointType>(request);
DataTypeRequest(DtoTarget.FloatingPoint) is a request for real type by Type. (Avalanche.DataType.Dto.dll)
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
DataTypeRequest request = new(DtoTarget.FloatingPoint(typeof(float)));
// Request record
IFloatingPointType datatype = service.GetRequired<DataTypeRequest, IFloatingPointType>(request);
IFloatingPointType { Name = "float" , ExponentPrecision = 7, NaNCapability = True, InfinityCapability = True, Base = 2, SignificandPrecision = 23, Signed = 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));
IFloatingPointType { Name = "float" , ExponentPrecision = 7, NaNCapability = True, InfinityCapability = True, Base = 2, SignificandPrecision = 23, Signed = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -3,4028234663852886E+38, MaxValue = 3,4028234663852886E+38 } IFloatingPointType { Name = "double" , ExponentPrecision = 10, NaNCapability = True, InfinityCapability = True, Base = 2, SignificandPrecision = 52, Signed = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -1,7976931348623157E+308, MaxValue = 1,7976931348623157E+308 } IFloatingPointType { Name = "decimal" , ExponentPrecision = 8, NaNCapability = False, InfinityCapability = False, Base = 2, SignificandPrecision = 96, Signed = 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 floatingpointtype
{
public static void Run()
{
{
// <01>
IFloatingPointType datatype = new FloatingPointType
{
Name = Identities.CreateName("myfloat").SetReadOnly(),
Properties = { },
Description = "",
Unassignable = false,
Referable = false,
MinValue = (double?)0.0,
MaxValue = (double?)65536.0,
Signed = false,
SignificandPrecision = 16,
ExponentPrecision = 4,
FractionPrecision = null,
IntegerPrecision = null,
NaNCapability = false,
InfinityCapability = false,
Radix = 2
}.SetReadOnly();
// </01>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <03>
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
FloatingPointTypeRequest request = new FloatingPointTypeRequest
{
Name = Identities.CreateName("myfloat").SetReadOnly(),
Properties = new Dictionary<string, string> { { IDataType.Property.Description, "short float" } },
Unassignable = null,
Referable = null,
MinValue = (double?)0,
MaxValue = (double?)65536,
Signed = false,
SignificandPrecision = 16,
ExponentPrecision = 4,
FractionPrecision = null,
IntegerPrecision = null,
NaNCapability = false,
InfinityCapability = false,
Radix = 2
};
// Query
IFloatingPointType datatype = service.GetRequired<IRequestFor<IFloatingPointType>, IFloatingPointType>(request);
// </03>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <04>
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
DataTypeRequest request = new(DtoTarget.FloatingPoint(typeof(float)));
// Request record
IFloatingPointType datatype = service.GetRequired<DataTypeRequest, IFloatingPointType>(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>
}
}
}