views:

56

answers:

1

I'm writing a genetic program to perform symbolic regression on a formula. I'm using ECJ. See tutorial 4 of the samples that come with ECJ for an example of what this is and the base that I started off of.

The problem comes when implementing division as a function to your genetic program. How do you guard against dividing by zero?

A: 

In Java, the Division Operator throws ArithmeticException for an integer divisor equal to zero. For floating-point operands, "Division of a nonzero finite value by a zero results in a signed infinity. The sign is determined by the [following] rule: ... the sign of the result is positive if both operands have the same sign, negative if the operands have different signs."

So, you either handle the exception or check the results.

trashgod