02-20-2012 04:11 AM - edited 02-20-2012 04:14 AM
Beware if you multiply two integers in the straightforward way. The result may not be as expected! See attachment.
02-20-2012 04:25 AM
It always happens when the result of your multiplied value exceeds the represented memory. My earlier post is somewhat similar to this.
02-20-2012 05:02 AM
Its out of range right? What is the solution for this?
02-20-2012 05:12 AM
The solution is of course to use DBLs in stead, but my (hidden) point in the original post was that this should be unnecessary. We should expect LabVIEW to be able to multiply two integers in a straightforward way.
02-20-2012 05:20 AM - edited 02-20-2012 05:20 AM
From what I see, 4000 * 10 falls out of range for I16 datatype.....
4000*16 overflows inside the memory and hence the wrong result
The solution is using DBL datatype while multiplying
02-20-2012 05:31 AM
From users' perspective, the solution is to improve the pertinent basic math functions so the results are as expected.
02-20-2012 05:34 AM
I differ, if the coder is changing the default datatype of controls, he must know the consequences of overflow for wrong value entry.
Not only LabVIEW, but all other programming languages exhibit this behaviour, since the concept is first multiplying and then casting to other datatype, rather than vice versa.
02-20-2012 05:54 AM
02-20-2012 06:18 AM
02-20-2012 06:18 AM
@finnh wrote:
From users' perspective, the solution is to improve the pertinent basic math functions so the results are as expected.
In a perfect world, there would probably be a single numeric data type and that would solve that, but we're not in a perfect world - if I multiply 6 (U8) by 9 (U8), I expect to get 54 (U8). In the same way, multiplying 6 (U8) by 90 (U8) should return a U8 even though 540 can't be represented as a U8, because the decision is an edit time decision, when we don't know the values.
If you want, you can go into the multiply primitive's properties by right clicking it and change the output to be an I32 or I64. This should automatically coerce the inputs the well.