
adccommunitymod (AutomationDirect) asked a question.
Dividing by zero?
Created Date: August 18,2010
Created By: trevorstripling
**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****
I HAVE SOME MATH IN A DL06 THAT MAY END UP DIVIDING A NUMBER BY ZERO. WILL THIS CAUSE A PROBLEM OR ERROR OR JUST RESULT IN ZERO? Trevor
Created Date: August 18,2010
Created by: bcarlton
1. Make a program with one rung doing a divide by zero and see what happens.
2. 'divide By Zero ' doesn't show up in errors for the DL06 and doesn't show as a reason for a bit after a DIV instruction.
Created Date: August 18,2010
Created by: milldrone
1. Make a program with one rung doing a divide by zero and see what happens.
Just tried on an 06, with single registers and double numbers. It just gives zero as a result. Unit is still in run.
Created Date: August 18,2010
Created by: bfitz
Just tried on an 06, with single registers and double numbers. It just gives zero as a result. Unit is still in run.
How about reals? If memory serves, floats are supposed to have some sort of support for displaying an error when divided by zero.
Brian
Created Date: August 18,2010
Created by: milldrone
How about reals? If memory serves, floats are supposed to have some sort of support for displaying an error when divided by zero.
Brian
Ok Brian,
I just tested some reals. SP63 turns on when dividing by zero. The description for SP63 is "on when the result of the instruction causes the value in the accumulator to be zero ". So It seems to work correctly.
Here is a quote from the 06 manual
SP63 On when the result of the instruction causes the value in the accumulator to be zero.
SP70 On anytime the value in the accumulator is negative.
SP71 On anytime the V-memory specified by a pointer (P) is not valid.
SP72 On anytime the value in the accumulator is an invalid floating point number.
SP73 On when a signed addition or subtraction results in a incorrect sign bit.
SP74 On anytime a floating point math operation results in an underflow error.
SP75 On when a real number instruction is executed and a non-real number was encountered.
Created Date: August 19,2010
Created by: bfitz
Did you happen to store the result in a double Vmem? I did some more research tonight and I am curious as to the bit pattern of the result.
According to IEEE 754 (floating point specification), dividing by zero should result in infinity, either positive or negative. 0/0 should equal NaN.
http://en.wikipedia.org/wiki/Division_by_zero
shows the IEEE defined results for division by zero in the "In computer arithmetic " section.
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
and
http://www.psc.edu/general/software/packages/ieee/ieee.php
show the bit patterns of positive and negative infinity and NaN. NaN actually takes two forms, which are mentioned in the first link.
In any case, the result of a divide by zero should not be simply zero if I am reading the references correctly.
Brian
Created Date: August 19,2010
Created by: milldrone
Did you happen to store the result in a double Vmem? I did some more research tonight and I am curious as to the bit pattern of the result.
I stored the result in a double, the result I received from the PLC right or wrong was zero in both Vmem.
Created Date: August 19,2010
Created by: trevorstripling
I would have tested it, but did not have easy access to an offline system.
Thanks for the info.
Trevor
Created Date: August 19,2010
Created by: bfitz
I stored the result in a double, the result I received from the PLC right or wrong was zero in both Vmem.
Interesting, thanks for testing it out.
I wonder if this is a bug in their implementation of the IEEE standard, or just the way they chose to deal with these edge cases. I imagine that in a PLC, some design compromises have to be made.
Brian
Created Date: August 18,2010
Created by: trevorstripling
I HAVE SOME MATH IN A DL06 THAT MAY END UP DIVIDING A NUMBER BY ZERO. WILL THIS CAUSE A PROBLEM OR ERROR OR JUST RESULT IN ZERO?
Trevor