• Avalanche.Core
Search Results for

    Show / Hide Table of Contents
    • Avalanche.Accessor
      • Introduction
      • IAccessor
        • IAccessor
        • IListAccessor
        • IMapAccessor
        • IRecordAccessor
        • IContentAccessor
        • IOneOfAccessor
        • IAnyAccessor
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • Dependency Injection
        • AccessorMessages
    • Avalanche.Binding
      • Introduction
    • Avalanche.Configuration
      • Introduction
      • Configuration Binding
      • ConfigurationExtensions
      • MemoryConfiguration
      • PrintTree
      • Saving IOptions
      • Yaml
    • Avalanche.Converter
      • Introduction
      • EnumConverter
      • Func<,>
      • HexConverter
      • PrimitiveConverter
      • StringConverter
    • Avalanche.Core
      • License
    • Avalanche.DataType
      • Introduction
      • DataType
        • IDataType
        • IListType
        • IMapType
        • IRecordType
        • IFieldType
        • IOneOfType
        • IAnyType
        • IStringType
        • IValueType
        • IIntegerType
        • IEnumerationType
        • IRealType
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • Enum
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • DataTypeRequest
        • PrintTree
        • DataTypeMessages
    • Avalanche.Emit
      • Introduction
      • TypeBuilder
      • ConstructorBuilder
      • MethodBuilder
      • PropertyBuilder
      • FieldBuilder
      • Emit
      • Utilities
    • Avalanche.FileSystem
      • Introduction
      • Abstractions
        • IFileSystem
          • IFileSystemBrowse
          • IFileSystemCreateDirectory
          • IFileSystemDelete
          • IFileSystemFileAttribute
          • IFileSystemMount
          • IFileSystemMove
          • IFileSystemObserve
          • IFileSystemOpen
        • IEvent
        • IEntry
        • IOption
        • IToken
      • FileSystem
      • VirtualFileSystem
      • MemoryFileSystem
      • EmbeddedFileSystem
      • HttpFileSystem
      • Decoration
      • IFileProvider
      • Events
      • Utilities
        • Dispose
        • File Scanner
        • Visit Tree
        • File Operation
        • FilterEnumerable
        • PollingFilterWatchToken
    • Avalanche.Identity
      • Introduction
      • Identity
      • IdentityParts
      • IdentityInterner
      • IdentityComparer
      • Print Tree
      • IdentityAccessors
        • Introduction
        • TypeName
    • Avalanche.Localization
      • Introduction
      • Localization
      • LocalizationFile
      • LocalizationFiles
      • LocalizationFileSystem
      • LocalizationFileFormat
      • LocalizationLine
      • LocalizationLines
      • TemplateFormat
      • CultureProvider
      • FallbackCultureProvider
      • ResourceManager
      • LocalizationError
      • Microsoft.Extensions
        • Introduction
        • DependencyInjection
        • FileProvider
        • Logging
        • ITextLocalizer
        • IFileLocalizer
        • Localization
      • Asp.Net
        • Introduction
        • Supplying localization
        • Inject to pages
        • Culture Assigned
        • Minimalistic Api
        • Diagnostics
      • Pluralization
        • Introduction
        • Multiple plural parameters
        • Custom PluralRules
        • Invariant Culture
        • Unit Prefix
        • IPluralRule
        • IPluralNumber
        • IPluralRules
        • CLDRs
        • Unicode.CLDR40
        • Unicode.CLDR41
        • Unicode.CLDR42
      • Articles
        • Alphabet localization
        • Benchmarks
        • Caching
        • Class Library
        • Demo
        • Diagnostics
        • Embedded resources
        • Emplacement
        • File localization
        • Text localization
        • Printing templates
    • Avalanche.Message
      • Introduction
      • IMessage
      • IMessageProvider
      • IMessageDescription
      • IMessageDescriptions
      • MessageLevel
      • Message printing
      • Messages and Exceptions
      • Microsoft.Extensions
        • DependencyInjection
      • Articles
        • Aggregate Messages
        • Localization
        • Logging
        • Validation
    • Avalanche.Options
      • Introduction
      • OptionsExtensions
      • OptionsMonitorCast
    • Avalanche.Service
      • Introduction
      • Service
        • Introduction
        • IService
        • IServiceDisposable
        • IServiceDecoration
        • IServiceCast
        • IServiceObservable
        • IServiceContainer
        • Construction
        • Query
        • CancellationToken
        • CachePolicy
        • Scope
      • Handler
        • Introduction
        • IHandler
        • IHandlerCast
        • IHandlerDecoration
        • IHandlerWithOrder
        • CancellationToken
        • Cyclicity
        • Delegates
        • Invokable
        • ExportAttribute
        • OrderAttribute
        • PrintTree
        • Recursion
      • Query
        • Introduction
        • IQuery
        • IQueryCast
        • IQueryDecoration
      • Entry
        • Introduction
        • IEntry
        • IEntryCast
        • IEntryDecoration
        • IEntryObservable
        • IEntryVisitable
        • EntryState
      • Request
        • Introduction
        • IRequest
        • IRequestFor
        • IRequestToBeCached
        • IRequestToBeDisposed
        • RequestAttribute
        • ContextParameterAttribute
        • Print Tree
      • Dependency Injection
        • Introduction
        • Asp.Net
        • ServiceRequest<T>
        • Decorating a service
        • Handler
        • CachePolicy
        • CancellationToken
        • QueryLogger
        • IHostBuilder
      • Examples
        • NodeCount
        • Expression
        • Mapper
      • Articles
        • Benchmarks
        • Error Handling
        • ServiceMessages
    • Avalanche.StatusCode
      • Introduction
      • HResult
        • Introduction
        • HResult.Facilities
        • BasicMessages
        • RpcMessages
        • DispatchMessages
        • StorageMessages
        • ItfMessages
        • Win32Messages
        • WindowsMessages
        • SspiMessages
        • CertMessages
        • MediaServerMessages
        • SetupApiMessages
        • ScardMessages
        • ComPlusMessages
        • ClrMessages
        • UserModeFilterManagerMessages
        • GraphicsMessages
        • TpmServicesMessages
        • TpmSoftwareMessages
        • PlaMessages
        • FveMessages
        • FwpMessages
        • NdisMessages
        • DltMessages
      • System
        • Introduction
        • AccessControlMessages
        • AggregateMessages
        • AppDomainMessages
        • ArgumentMessages
        • ArgumentNullMessages
        • ArgumentOutOfRangeMessages
        • ArithmeticMessages
        • ArrayMessages
        • AssemblyMessages
        • BadImageFormatMessages
        • CodeContractMessages
        • CodePageMessages
        • CollectionsMessages
        • CompilerServiceMessages
        • CryptographyMessages
        • CultureMessages
        • DiagnosticsMessages
        • EventSourceMessages
        • ExecutionEngineMessages
        • FormatMessages
        • HostProtectionMessages
        • IOMessages
        • IndexOutOfRangeMessages
        • InteropServiceMessages
        • InvalidCastMessages
        • InvalidOperationMessages
        • IsolatedStorageMessages
        • LazyMessages
        • MarshalerMessages
        • MemoryMessages
        • MiscellaneousMessages
        • NotImplementedMessages
        • NotSupportedMessages
        • ObjectDisposedMessages
        • OperationCanceledMessages
        • OverflowMessages
        • PlatformMessages
        • PolicyMessages
        • PrincipalMessages
        • ProgramMessages
        • ReferenceMessages
        • ReflectionMessages
        • RegionMessages
        • RemotingMessages
        • ResourcesMessages
        • SecurityMessages
        • SerializationMessages
        • StackMessages
        • TaskMessages
        • TextMessages
        • ThreadingMessages
        • TimeZoneMessages
        • TypeMessages
        • XmlMessages
      • HttpStatusCode
      • OpcUaStatusCode
    • Avalanche.Template
      • Introduction
      • TemplateFormats
      • ITemplatePrintable
      • ITemplateFormatPrintable
      • ITemplateText
      • ITemplateBreakdown
      • ITemplateFormat
      • ITemplateFormats
      • Extract Arguments
      • Emplacement
    • Avalanche.Tokenizer
      • Introduction
      • IToken
      • ITokenizer
      • Tokenizers
    • Avalanche.Utilities
      • Introduction
      • Collections
        • Tuples
        • StructList
        • ArrayList
        • BijectionMap
        • LocakableDictionary
        • LockableList
        • MapList
        • Pipe
        • RingQueue
        • EnumerableExtensions
        • TupleUtilities
        • ArrayUtilities
      • Comparers
        • IGraphComparer
        • IGraphComparable
        • AlphaNumericComparer
        • EnumerableComparer
        • EnumerableGraphComparer
        • ReferenceComparer
        • KeyValuePairComparer
        • DefaultComparerProvider
        • RecordComparer
      • Cloners
        • ICloner
        • IGraphCloner
        • IGraphCloneable
        • ListCloner
        • DictionaryCloner
        • FieldCloner
        • PassthroughCloner
        • RecordCloner
        • ClonerProvider
      • Dispose
        • IDisposeAttachable
        • IDisposeBelatable
      • Provider
        • Introduction
        • ProviderBase
        • Delegate
        • Pipe
        • Cache
        • ResultCapture
        • AsReadOnly
        • AsService
        • IProviderEvent
      • Record
        • IRecordDescription
        • IFieldDescription
        • IConstructorDescription
        • IConstructionDescription
        • IParameterDescription
        • IRecordProviders
        • RecordDelegates
          • RecordCreate
          • RecordClone
          • RecordCopy
          • IRecordDelegates
        • FieldDelegates
          • FieldRead
          • FieldWrite
          • RecreateWith
          • IFieldDelegates
      • Reflection
        • EnumDescription
      • String
        • IEscaper
        • UnicodeString
        • Hex
      • Miscellaneous
        • IIdGenerator
        • Permutation
        • IReadOnly
        • IUserDataContainer
        • ITreeNode
        • Void
    • Avalanche.Writer
      • Introduction
      • ConstantWriter
      • Context
      • ConvertWriter
      • DefaultConstructor
      • DelegateWriter
      • PassthroughWriter
      • Referer
      • TypeCast
      • Writer
      • WriterPipe
      • WriterMessages

    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>
            }
        }
    }
    
    In This Article
    Back to top Copyright © Toni Kalajainen