Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"not supported" exception with divide by zero in equation #102

Open
PaulSmart73 opened this issue Jul 19, 2023 · 0 comments
Open

"not supported" exception with divide by zero in equation #102

PaulSmart73 opened this issue Jul 19, 2023 · 0 comments

Comments

@PaulSmart73
Copy link

Hi,

I am trying to use the library to parse and the execute some math channels in my C# project. It works very well, but I receive an "not supported" exception which is very slow.

Having looked into the equation and data I have isolated it to effectively a sqrt(1/0) call that is causing the exception.
fpower in the Evaluate module is being used for the division. This is returning PosInf for the 1/0 call and then this is not matched for the sqrt call.

I have found two options for how to remove the exception:

  1. modify the Evaluate to return Undef if a divide by zero is found.
  2. modify the Evaluate to handle PosInf as a match case

For my immediate problem, I have modified the fpower as below with both options, which allows my codes to run without any exceptions being raised

    let fpower u v =
    match u, v with
    | Real x, Real y when x < 0.0 && (y%1.0 <> 0.0) -> Complex (Complex.pow (complex y 0.0) (complex x 0.0))
    | Real x, Real y when x = 0.0 && y < 0 -> Undef
    | Real x, Real y -> Real (Math.Pow(x, y))
    | Complex x, Real y -> Complex (Complex.pow (complex y 0.0) x)
    | Real x, Complex y -> Complex (Complex.pow y (complex x 0.0))
    | Complex x, Complex y -> Complex (Complex.pow y x)
    | Undef, _ | _, Undef -> Undef
    | ComplexInf, Infinity | Infinity, ComplexInf -> ComplexInf
    | Infinity, PosInf -> ComplexInf
    | Infinity, NegInf -> Real (0.0)
    | PosInf, _ | _, PosInf -> PosInf
    | NegInf, _ | _, NegInf -> NegInf
    | _ -> failwith "not supported"

I do not know enough about the library ( or maths...) to understand if this is a valid thing to do though. It certainly works for my use-case.

What is the preferred method of handling divide by zero (undefined or infinity)? What should be the sqrt(PosInf)? I would guess its still PosInf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant