Skip to content

DivideByZeroException in fpmath.normalizesafe #30

Description

@orreborre2k

Hello!
Maybe normalizesafe isn't that safe after all! ;)
Running
fpmath.normalizesafe(new fp2(0,0), new fp2(0,0));
causes a DivideByZeroException in fpmath.rsqrt.
It seems fpmath.select is what causes the call to fpmath.rsqrt.
If I replace the call to fpmath.select it works as intended, like so:

static public fp2 normalizesafe(fp2 x, fp2 defaultvalue = new fp2())
{
  fp len = fpmath.dot(x, x);
  // return fpmath.select(defaultvalue, x * fpmath.rsqrt(len), len > 0.00000001m);
  return len > 0.00000001m ? x * fpmath.rsqrt(len) : defaultvalue;
}

Not sure if something can be done with fpmath.select or if my fix is an ok way to solve this?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions