Skip to content

Formulas in which we divide by x throws an exception when x = 0 #707

@aidbal

Description

@aidbal

Hey @angularsen, I have recently published a pr to create a new Fuel Efficiency unit (#703).

In one of the formulas, there is a division by zero. It happens, that sometimes in our code we have the following call FuelEfficiency.ToUnit(FuelEfficiencyUnit) which throws an exception.

After inspecting the generated code, I have found that nowhere it checks for division by zero, thus the formula 100/x becomes 100/0 and it throws an exception.

I am not sure how propose fixes for this problem, that's why I am writing it here. Right now, I have created an extension method, which first, checks for initial value, and then, if it's non-zero, it calls it's base method.

One more thing, you cannot apply check by zero to all values, because 0 Celsius is not 0 Kelvins and vice versa.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions