01-07-2016 03:45 PM
I was surprised to notice a broken wire when inserting an Absolute Value Function into an U32 wire:
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:
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.
01-07-2016 04:04 PM - edited 01-07-2016 04:14 PM
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 ...
01-07-2016 04:10 PM
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.
01-07-2016 04:42 PM
More of the same or similar arbitrariness and non-standard behavior:
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?
01-07-2016 04:47 PM
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.
01-07-2016 04:57 PM - edited 01-08-2016 02:48 AM
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.
01-07-2016 05:18 PM
@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:
which gives, for instance:
I guess I will now be banned from the forum to have exposed this blasphematory use of the subtraction operation.
01-07-2016 06:21 PM
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
01-08-2016 02:35 AM
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.
01-08-2016 03:01 AM - edited 01-08-2016 03:14 AM
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!
it still breaks the wire
FLV