Sunday, July 1, 2012

Math programming issues to consider

Two recent issues encountered recently when doing basic math operations and why they might occur:

1.  Division by Zero.  Commonly likely to occur when you are dividing elements of one container set with elements of another, or for something as simple as algorithms pertaining to statistical measures like means.  If you have an empty container set, in this case, you'd have a division by zero error.  Either introduce something like a control statement prior to entering math operation firstly and make sure you account for this if expected returns are to be provided sequentially later, or you could flag the zero set and so forth.  A little bit of added accounting here for this contingency but probably a good thing to have when you couldn't be too self sure about the data fed into your computations.  Any divisions should have some accounting like this I would offer.

2.  Root of negative numbers yielding a completely different return type.  This occurs in the following instance.  B > A where square_root(A - B) leads to a complex number.  This can occur in the case of things like statistical computations.  If for any given set of data the following inequality holds, A > B, then recheck your math formulation to make sure computation is correct otherwise consider this problem, or this could be merely by way of the expression set that you are using, or in other words it maybe possible that the formulas expression were missing something like square_root ( absolute_value(A-B))?  Ways of checking for possible values sets here:  If a formulas equivalent re expression is situated in the following manner where we have:  C, D such that  square_root ( square(C - D))  Irrespective of whether  C < D  , this equivalent re expression of the formula above implies that the term square(C - D) is always a positive number hence its its square root should always be a non complex return type unless  you have already situated the number as a complex number in your mathematical operations.  Checking your formulation by way of re expressing it is also another way to confirm stability in the return of your data type or avoiding cast type conversion problems.  Anytime you perform a square root in a given series of mathematical operations, there maybe the possibility of a complex number return type.

No comments:

Post a Comment

Oblivion

 Between the fascination of an upcoming pandemic ridden college football season, Taylor Swift, and Kim Kardashian, wildfires, crazier weathe...