LabVIEW NXG - Simple Data Types and Type Coercion

This is the third article in the LabVIEW NXG series in which we look at simple data types and simple conversions between them.



The LabVIEW type system is very similar to the "classic" programming languages. In this article we will consider the basic types - numerical, Boolean, and strings (although formally strings do not belong to simple scalar types).


The easiest way to understand the type system is to make a small tool with controls and indicators of different types:



and connect them on the diagram like this:



, " In" " Out". LabVIEW, , ( ).


โ€” , 8, 16, 32 64 , ( 4 8 ), โ€” . :



:



( , ). , ? :



"" ( Coercion Dots), , .


SGL DBL , , U8 I32, , DBL->SGL, DBL->I32 I32->U8 , :



"" LabVIEW Coercion Dots , :



, ? , Data Types->Numeric->Conversion:



:



Coercion Dot, .



, , , DBL, :



, , ( LabVIEW Compound Arithmetic):



LabVIEW . , :


double res;
res = 5/3;
Console.WriteLine(res);

"1".


LabVIEW , 1,66 (1,66666666666667 ):



, LabVIEW , , , C# ( "" ).


, , :



, . , , , :



C# ( , int, , :


        static void Main(string[] args)
        {
        byte x_U8 = 200, y_U8 = 200, res_U8;

        res_U8 = x_U8 + y_U8;

            Console.WriteLine(res_U8);
        }

:


        res_U8 = (byte)(x_U8 + y_U8);

, LabVIEW, , LabVIEW , , ( ):



, , :



LabVIEW ( "" ) โ€” .


LabVIEW C# Microsoft, :


class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(5.0/0.0);
    }
}

"8". , , "", "Infinity", . , .NET Core โ€” , ( , , " " Windows 10 2004). , , , , , , , .


, , LabVIEW:



โ€” . :



, NaN (Not a Number):



NaN Not a Number? :



โ€” .


.


# :


static void Main(string[] args)
{
    Console.WriteLine(5/0);
}

...


static void Main(string[] args)
{
    int zero = 0; 
    Console.WriteLine(5/zero);
}

โ€ฆ System.DivideByZeroException, LabVIEW โ€” , .




() :



Conversions :



:



, , :



:



, , :


    static void Main(string[] args)
    {
    string hello = "Hello, ";
    string habr = "Habr!";

        Console.WriteLine(hello + habr);
    }

LabVIEW " " , :




. , Boolean to Integer :



LabVIEW. False:



, :



Type Cast


"Type Cast", . :



"Type", . "by flattening it and unflattening". "/".


, SGL I32:



output? "1040187392". ?


:



This is 0x3E000000. Here the following happens - four bytes of a floating-point number are reinterpreted as a four-byte integer. I intentionally took the number 0.125, because if you look at the representation of 0.125 according to IEEE754, you will see that there are only five bits of the mantissa set - this gives us the value 3E in the high byte.


After three articles, we should work fairly confidently with three types of data:



If you have any questions about the material presented, ask in the comments, and in the next article we will consider arrays.


All Articles