LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any good reason why the Absolute Value Function doesn't accept U32 values?

I was surprised to notice a broken wire when inserting an Absolute Value Function into an U32 wire:

 

Screen Shot 2016-01-07 at 13.43.34.png

 

After all, an unsigned integer is positive, so there is no problem with determining what its absolute value is (itself).

However, the help for that function specifically forbids it:

 

Screen Shot 2016-01-07 at 13.45.16.png

 

I don't know of any programming language that has this arbitrary limitation, even less justified by such a non-sensical explanation.

I'd call that a bug, but before I jump guns, I'd thought I'd ask the question.

0 Kudos
Message 1 of 19
(4,574 Views)

Well, let's be Charitable and say that NI doesn't want us to use a function that, by definition, does nothing (for that particular input), so to avoid "wasting CPU cycles" and our time, they (a) forbid it in the Documentation, and (b) "show us the folly of our ways" by throwing an error.

 

Note that to implement this and really have it "do nothing", code would need to be inserted to test for this particular "exception" input type.  For all other data types, the code is the same -- if negative, negate, else pass through.

 

Bob Schor

 

P.S. -- I don't use "single-letter languages" (even with ++ after them), but when I tried to get a straight answer on the Web for Abs of an unsigned Int, the answer was not 100% unambiguous or clear ...  

0 Kudos
Message 2 of 19
(4,554 Views)

I wouldn't call it a bug if it is documented. Datatypes have to be defined at runtime, as far as i can tell, so i don't see a reason to allow unsigned integers.  My $0.02.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 3 of 19
(4,543 Views)

More of the same or similar arbitrariness and non-standard behavior:

 

Screen Shot 2016-01-07 at 14.44.52.png

 

Notice that it is perfectly fine to substract a U32 from another one and request a U32 result, but negating a U32 (which WILL return a I32 by construction of the function) is forbidden with the same justification as above.

Why can ask for the sign of U32 when this should be flagged as anathema by the NI guardians of positiveness?

 

0 Kudos
Message 4 of 19
(4,522 Views)

Because the values are not evaluated until runtime.  The compiler doesn't know or care what values are in your constant, as long as the datatype is correct.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 19
(4,516 Views)

I agree that wiring an unsigned integer (U8...U64) to an absolute value function should NOT break the wire.

 

This is a real inconvenience!

 

It also breaks the wires for hierachical structures. For example if we have a large numeric cluster of various signed integers, floating point numbers, etc. and and at least one unsigned integer, and we try to apply the absolute value function, we cannot do it, even though the result is well defined. This should be corrected.

0 Kudos
Message 6 of 19
(4,510 Views)

@aputman wrote:

Because the values are not evaluated until runtime.  The compiler doesn't know or care what values are in your constant, as long as the datatype is correct.


Right. So it is perfectly fine to obtain the value of 0 - X at runtime, where 0 and X are both U32:

 

0minusx.png

 

which gives, for instance:

 

Screen Shot 2016-01-07 at 15.21.25.png

 

I guess I will now be banned from the forum to have exposed this blasphematory use of the subtraction operation.

 

Message 7 of 19
(4,495 Views)

I also agree that this is not appropriate behavior, even if documented. 

 


     "I guess I will now be banned from the forum to have exposed this blasphematory use of the subtraction operation."


 

 

I think "X." is a great user name signifiying all the corner cases you have identified. I certainly appreciate the efforts you put into finding, verifying, and documenting these errors.  While most of them may never affect my code, it is important to have confidence that a programming language does mathematics right.  Keep up the good work.

 

Lynn

0 Kudos
Message 8 of 19
(4,465 Views)

Having not run into this myself I can't say I find it to be inconveniencing. I think it's fairly obvious that this was done to alert the user "hey, be aware that what you asked for doesn't do anything. Check your code". In that sense, it's similar to breaking a for loop with no indexing inputs, although I agree it's not as neccessary and is an exteme application of the principle and would become a problem in the combined data structure altenbach mentioned. I don't particularly care how it behaves, but I would tend to allow it too.


___________________
Try to take over the world!
0 Kudos
Message 9 of 19
(4,407 Views)

Hi

 

Now that it is mentioned, I checked and found that "Negate" function also does not allow an unsigned integer connected to the input.

Edit: I also agree that its an inconvenience to break the wire.

 

I tried wiring an I32 to the Negate input and then inserting "to U32" function in between! Smiley Wink

it still breaks the wire

 

 

FLV

Regards
Freelance_LV
TestAutomation Consultant
0 Kudos
Message 10 of 19
(4,392 Views)