-
Notifications
You must be signed in to change notification settings - Fork 751
Fix conversion of 'float' and 'double' values #487
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
Conversation
Fix problem of conversion 'float' and 'double' values in converter.cs. As there was a range check both for 'float' and 'double' values, which are less or greater than its 'MinValue' and 'MaxValue' accordingly, several values like 'float.NegativeInfinity', 'float.PositiveInfinity' and the same 'double' values cannot be converted from Python to .NET values. Add error check after 'PyFloat_AsDouble' call. Due to Python C API documentation, method 'PyFloat_AsDouble' can return '-1.0' upon failure. So it requires error check. This rule forces to check for error and throw exception in case of error. Add tests, which cover problem of conversion 'float' and 'double' values. Resolves: pythonnet#486.
@Konstantin-Posudevskiy in .NET I get overflow exception, but not in python. Also precision in .NET is much less for some reason: Python 2.7.13 |Anaconda custom (32-bit)| (default, Dec 19 2016, 13:36:02) [MSC v
.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> dmax = 1.7976931348623159e308
>>> dmax
inf
>>> dmax = 1.7976931348623156e308
>>> dmax
1.7976931348623155e+308
>>> dmax = 1.7976931348623154e308
>>> dmax
1.7976931348623153e+308
>>> dmax = 1.7976931348624159e308
>>> dmax
inf
>>> dmax+1e308
inf scriptcs (ctrl-c to exit or :help for help)
> double dmax = 1.7976931348623159e308d
* ;
(2,15): error CS0594: Floating-point constant is outside the range of type 'doub
le'
> double dmax = 1.7976931348623156e308d;
> dmax
1.79769313486232E+308
> dmax = 1.7976931348623146e308d;
1.79769313486231E+308 |
@denfromufa, I absolutely agree with you. This pull request addresses another issues. It only
I also checked failing Python tests. Please, take a look at method test_double_conversion. Python output for test values from test method test_double_conversion: >>> dmax = 1.7976931348623159e308
>>> dmax
inf
>>> dmin = -1.7976931348623159e308
>>> dmin
-inf |
@Konstantin-Posudevskiy can you fix this failing test?
OverflowError is not .NET exception, it is Python exception and it should not be expected in this case. |
@denfromufa sure, I will do. |
Fix incorrect part of 'test_double_conversion' test in test_conversion.py. An 'OverflowError' was expected for valid values, which represent Python 'inf' and '-inf'. The problem was identified with support of conversion for Python 'inf' and '-inf' to .NET System.Double PositiveInfinity and NegativeInfinity. See also: pythonnet#487.
Codecov Report
@@ Coverage Diff @@
## master #487 +/- ##
==========================================
+ Coverage 74.23% 74.24% +<.01%
==========================================
Files 64 64
Lines 5562 5564 +2
Branches 894 894
==========================================
+ Hits 4129 4131 +2
Misses 1147 1147
Partials 286 286
Continue to review full report at Codecov.
|
Fix incorrect part of 'test_double_conversion' test in test_conversion.py. An 'OverflowError' was expected for valid values, which represent Python 'inf' and '-inf'. The problem was identified with support of conversion for Python 'inf' and '-inf' to .NET System.Double PositiveInfinity and NegativeInfinity. See also: pythonnet#487.
1545d7c
to
71651fb
Compare
* Fix conversion of 'float' and 'double' values Fix problem of conversion 'float' and 'double' values in converter.cs. As there was a range check both for 'float' and 'double' values, which are less or greater than its 'MinValue' and 'MaxValue' accordingly, several values like 'float.NegativeInfinity', 'float.PositiveInfinity' and the same 'double' values cannot be converted from Python to .NET values. Add error check after 'PyFloat_AsDouble' call. Due to Python C API documentation, method 'PyFloat_AsDouble' can return '-1.0' upon failure. So it requires error check. This rule forces to check for error and throw exception in case of error. Add tests, which cover problem of conversion 'float' and 'double' values. Resolves: pythonnet#486. * Fix failing 'test_double_conversion' test Fix incorrect part of 'test_double_conversion' test in test_conversion.py. An 'OverflowError' was expected for valid values, which represent Python 'inf' and '-inf'. The problem was identified with support of conversion for Python 'inf' and '-inf' to .NET System.Double PositiveInfinity and NegativeInfinity. See also: pythonnet#487.
Fix problem of conversion 'float' and 'double' values in converter.cs.
As there was a range check both for
float
anddouble
values, which are less or greater than itsMinValue
andMaxValue
accordingly,several values like
float.NegativeInfinity
,float.PositiveInfinity
and the same 'double' values cannot be converted from Python to .NET values.Add error check after
PyFloat_AsDouble
callDue to Python C API documentation, method
PyFloat_AsDouble
can return-1.0
upon failure. So it requires error check. This rule forces to check for error and throw exception in case of error.Add tests, which cover problem of conversion
float
anddouble
values.Resolves: #486