Divide By Zero Errors in Input Fields

In some cases, you may enter an expression into an input field such as X/Y where at some point during the simulation, both X and Y are zero.  In most instances, when GoldSim encounters zero in the denominator of an expression, it will display a fatal error and stop the simulation.  However, if both the numerator and the denominator are zero, GoldSim will not display a fatal error; instead, the resulting expression will be set to zero and the simulation will continue.  This can be very convenient, as it allows you to avoid adding complex logic to check for such cases.

Note, however, that GoldSim only sets the expression to zero if both the numerator and denominator are zero.  To understand this, consider an example where A and C are equal to zero, and B is non-zero.  In this case, the following two expressions would be treated differently by GoldSim:

   A*B/C: would return zero, as A*B would be evaluated first (and considered to be the numerator for C.

   A*(B/C) would result in a fatal error, as B/C would be evaluated first, and B is non-zero.

Related Topics…