LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

conversion to integer

The code *almost* works. In the algorithm, after adding 0.5, you need to round down, not up. This is also demonstrated in the link I posted earlier, where it's encapsulated into a subVI.

___________________
Try to take over the world!
0 Kudos
Message 11 of 18
(1,395 Views)

Picky, Picky......Smiley Happy  You are of course correct..........

 

Add 0.5, round toward -Infinity.....

 

Message Edited by tartan5 on 10-08-2008 09:38 AM
0 Kudos
Message 12 of 18
(1,388 Views)

Just out of curiosity, I wonder why there is no "Round toward zero"  (Truncate) function......

 

To be honest, I was a little startled that the "to unsigned word" conversion function actually does implicit rounding.  I understand why it does, it just took me by surprise that it is inherent to the function.

0 Kudos
Message 13 of 18
(1,379 Views)

tartan5 wrote:

Just out of curiosity, I wonder why there is no "Round toward zero"  (Truncate) function......


Well, checking if a number is smaller or larger than 0 and doing the appropriate action is pretty simple. It would probably take longer to do the icon than to write the VI itself. Incidentally, you can also try using the Q&R primitive and divide by 1, but I'm not sure what you'll get with a negative input.


___________________
Try to take over the world!
0 Kudos
Message 14 of 18
(1,353 Views)

tartan5 wrote:

Just out of curiosity, I wonder why there is no "Round toward zero"  (Truncate) function......

 

 


There isn't a "round toward zero" but there is 'round to negative infinity'.  

 

Cory K
0 Kudos
Message 15 of 18
(1,343 Views)
.... and a 'round to nearest'
Cory K
0 Kudos
Message 16 of 18
(1,342 Views)

http://www.pldesignline.com/howto/175801189

 

Good article on different rounding algorithms.........

 

The "round to nearest" should really be called "Round to nearest even", since that is what it does.....

0 Kudos
Message 17 of 18
(1,338 Views)

tartan5 wrote:

 

The "round to nearest" should really be called "Round to nearest even", since that is what it does.....


No, it isn't. It only rounds to the nearest even under these circumstances:

  1. The even number really is the nearest integer.
  2. It's halfway between two integers. This is sometimes refered to as "ties to even", so you could call it "Round to nearest, ties to even".

___________________
Try to take over the world!
0 Kudos
Message 18 of 18
(1,318 Views)