LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How does one perform operator overloading in LabVIEW?

I would like to create an arbitrary-length integer in LabVIEW.

I actually don't know where to begin, but I would like to know that down the road I will be able to overload the operators in the numeric function pallet.

 

Any pointers?

0 Kudos
Message 1 of 9
(3,588 Views)

Search for the Coding Challenge from a few years ago on Factoring Prime Numbers or something similar.  Some of the solutions included means of handling numbers with more significant digits than can be represented by the native data types.

 

Lynn

0 Kudos
Message 2 of 9
(3,571 Views)

Thanks for your reply!

 

I found the challange, the discussion about it and the winner's solution...

I couldn't find an example for operator overloading nor an example for a class of 'very' long integers...

 

 

0 Kudos
Message 3 of 9
(3,545 Views)

Sorry.  I guess my memory is not too good.  Or maybe I was thinking about ideas I had had for the challenge which never were implemented.

 

Some ideas: Develop digit by digit algorithms and represent your numbers as string characters.  This would be similar to the BCD arithmetic performed by early electronic calculators.

 

Develop your own base 256 arithmetic and use arrays of U8 as your numbers.

 

Regardless of the method you choose, you will need to define how you will represent numbers larger than the largest native numeric representations.  The best way to do that may well depend on what you intend to do with the numbers and how fast you need to do it.

 

Lynn

Message 4 of 9
(3,533 Views)

LabVIEW doesn't support operator overloading.  Unless NI adds that feature, you will never be able to use the Add primitive on your class and get it to perform code that you have written.  You have to write your own

myclass.lvclass:Add.vi and use it instead of the Add primitive.

 

Operator Overloading is not a great idea anyway.  I hope NI is never going to add it to the language.

0 Kudos
Message 5 of 9
(3,513 Views)

 Hello scf1984

 

Can you please let me know if the following user comments have been helpful to you?  If not, I will be happy to address this issue further for you.  Thank you very much for supporting National Instruments!

Sincerely,

Greg S.
0 Kudos
Message 6 of 9
(3,482 Views)

Hi Greg

 

Well, jdunham's reply discouraged me from further attempting to overload operators.

 

All I want to do is to be able to use LabVIEW's numerical functions (e.g. multiply, add etc.) by wiring in my own numeric class, which by polymorphism (or some other mechanism i may not be aware of) will call my multiply/add function.

 

However I understand that this is not possible, meaning that I will have to have a special functions pallete for each class I make in the future.

 

Of course, if you have pointers about how to do it wisely (I am unexperianced in this kind of programming) I would love to hear them.

 

Thanks!

0 Kudos
Message 7 of 9
(3,479 Views)

LV doesn't have to directly support operator overloading for it to be used. Its possible to write your own overloading functions (for + - * / |...) to mimic C++ and the like. There is not 1 way to do this, there are many when when dropping LV icons. No different if you were writing C code and you required overloaded operator but C doesn't directly support overloading.

0 Kudos
Message 8 of 9
(3,463 Views)

 


@scf1984 wrote:

Hi Greg

 

Well, jdunham's reply discouraged me from further attempting to overload operators.

 

All I want to do is to be able to use LabVIEW's numerical functions (e.g. multiply, add etc.) by wiring in my own numeric class, which by polymorphism (or some other mechanism i may not be aware of) will call my multiply/add function.

 

However I understand that this is not possible, meaning that I will have to have a special functions pallete for each class I make in the future.

 

Of course, if you have pointers about how to do it wisely (I am unexperianced in this kind of programming) I would love to hear them.

 

Thanks!


If you plan to use this type of functionality often I would recommend that you create a base class which defines the API for your operations. Using dynamic dispatch you can derive specific child classes for these operations. These would most likely need to be friends of your actual classes in order to access their data. By using this approach you create a generic way of doing it that you tailor for specific uses.

 



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 9
(3,447 Views)