05-25-2018 02:32 AM
the file is picture
this program's purpose is showing the flight time money and flight distance
i want to operate the distance by scaling the picture length to real length so i multiple 37.7
the problem is in root[(a-b)^2+(c-d)^2] when operating (a-b)^2, the number is not exactly operate x^2 for example, 240^2=7364...
please help what's wrong this program...
05-25-2018 09:21 PM
Please attach your file again, but don't name it with Japanese (?) characters. We can't open it.
05-25-2018 09:31 PM
Also try to downconvert before attaching (file...save for previous). At this moment, virtually nobody is using LabVIEW 2018 because it just came out less than a week ago.
05-26-2018 07:35 AM - edited 05-26-2018 07:48 AM
This Snippet shows (part of) the code you submitted:
There are many things that are not exactly "wrong", but that contain "traps" and "mistakes". The heart of your calculation is to find the distance between two points represented by a cluster of 2 I16 coordinates (conveniently called "x" and "y"). For convenience, I'm going to call the two points P1 and P2. Here are some things to consider:
Try rewriting your routine, once you understand what I'm trying to say, above. I've deliberately not provided a Block Diagram, as I think you will learn and understand better if you read what I wrote and then try "doing it yourself".
Bob Schor
05-26-2018 08:07 AM
@Bob_Schor
- You do not need any Absolute Value functions in this calculation.
Bob Schor
You don't take the absolute value of a square, especially after ensuring the input to the square function is positive by using an absolute value? You must hate math 😮
05-26-2018 09:31 AM - edited 05-27-2018 11:23 AM
Since the result is floating point anyway, converting the two points to complex would make things even simpler. No need for squares or square-roots. (The absolute value of a CDB is r in DBL).
And yes, as bob said, if you square an integer having a limited number of bits, the result is arbitrary if it does not fit in the valid range and can even be negative. If it is negative, you are definitely getting a wraparound and taking the absolute value will not be the correct value. Even if the square value is positive it is not guaranteed to be the right value. For example 32764² calculated in I16 results in 16, definitely not right even though it is positive. As a rule of thumb, to safely square an integer, the result needs up to twice as many bits used by the input.
(Hey, now we suddenly need the absolute value function after all! :D)
or alternatively (but watch out for wraparound in the subtraction!):
05-26-2018 12:19 PM
Nice
05-26-2018 12:29 PM
@natasftw:
If you read the first sentence and the last sentence of my post, you would see that (a) the Snippet was that of the OP, which I was criticizing, and (b) I said "I've deliberately not provided a Block Diagram ...".
I have been a dues-paying member of the Mathematical Association of America for several decades. Just so 'ya know ...
Bob "I Love Math" Schor