crowlogic / arb4j

arb4j is a Java API for the arbitrary precision ball arithmetic library found at http://arblib.org
Other
1 stars 0 forks source link

add parent expression input field to list of fields checked for non-nullness in the initialize() method of subexressions #358

Closed crowlogic closed 5 months ago

crowlogic commented 5 months ago

for instance, here, $n$ should be asserted to not be null when initialize() is called where presenty it is only checking the α variable registered via a context. this isnt strictly a bug but ensuring these are validated once with initialize has a much greater likelihood of catching a tracking down problems before they occur or figuring out why something aint working

package arb.functions.real;

import arb.Integer;
import arb.Real;
import arb.functions.Function;

public class factorℝ1 implements
                      Function<Integer, Real>
{
  private boolean isInitialized;
  public Integer  n;
  public Integer  p;
  public Integer  q;
  public Real     α;
  public Real     β;
  public Real     z;

  public Real evaluate(Integer in, int order, int bits, Real result)
  {
    if (!isInitialized)
    {
      initialize();
    }

    return α.get(in).risingFactorial(n, bits, result);
  }

  public void initialize()
  {
    if (isInitialized)
    {
      throw new AssertionError("Already initialized");
    }
    else if (α == null)
    {
      throw new AssertionError("α is null");
    }
    else
    {
      isInitialized = true;
    }
  }
}
crowlogic commented 5 months ago

if someone sends null input they can figure it out themselves