Skip to content

Wrong behavior in float values using IronPython in a C# application #841

@jandres861

Description

@jandres861

Description

We are running a sandbox in a .NET windows application (.NET framework 4.7.2 and IronPython 2.7).

Once we call the execution of the specific script, they returned to us a DivisionByZero exception, because a normal decimal value we are sending from .NET are being converted to a very small number (1.03e-311), that causes the Zero Division issue.

Steps to Reproduce

  1. Create the Runtime and Scope information
  2. Load the Python code to execute (only has several arithmetic operations, nothing very complex neither using arrays or collections)
  3. We receive the exception of the execution in a Try/Catch block in .NET.
  4. We "debug" the code using a direct RaiseError and we identified the runtime is assuming a very small number tending to zero, that is the reason of the fail.

Error returned:

"An error occured while executing the underlying Python script (Traceback (most recent call last): :: File "", line 98, in GetTheFailureMode :: File "", line 699, in GetMaxFfsLoss :: File "", line 2043, in GetMaxHoopLoss :: File "", line 2197, in GetHoopMsop :: ZeroDivisionError: Attempted to divide by zero.)"

Parameters from .NET:

"
addToIerance = true
depthPercentage = 7
designFactor = 0.72
designPressureInMpa = 14.1
inBend = false
lengthInMeter = 0.0689999999999884
lineType = "Hybrid"
outerDiameterInMeter = 0.1683
pipeGrade = "X60"
pofDefectCIass = "General"
wallThicknessInMeter = 0.0095
widthInMeter = 0.038
"

Values recovered in Python just calling the method:

"
An error occured while executing the underlying Python script (Traceback (most recent call last): :: File "", line 148, in GetMaxIliFfsLoss :: Exception: (

'WT: 6.95238308496e-310',
'Hybrid', <type 'float'>,
'Float Number: ', 1.034294700449062e-311,
'Float Number String', '0.0095',
'Convert From String To Float', 1.034294700449062e-311,
'Culture Number Format', <System.Globalization.NumberFormatInfo object at 0x000000000000002B [System.Globalization.NumberFormatInfo]>, 1.0343456283479938e-311,
False,
'0.0095',
1.034294700449062e-311,
1.0353302339822869e-311,
1.034294700449062e-311,
1.0334119502000876e-311,
True,
1.0338363493581819e-311,
'X60',
1.0349533679427365e-311))
"

Culture info:

NumberFormat
CurrencyDecimaIDigits = 2
CurrencyDecimalSeparator = "."
CurrencyGroupSeparator = ","


Expected behavior: Do not convert the normal float parameters to very small numbers.

Actual behavior: The float values are converted to a very small numbers that causes a Zero Division Exception.

Versions

IronPython 2.7
.NET Framework 4.7.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions