| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bfce5e2 commit d39f9f6
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,7 @@ | |||
| 27 | 27 | - Joe Frayne ([@jfrayne](https://github.com/jfrayne)) | |
| 28 | 28 | - John Burnett ([@johnburnett](https://github.com/johnburnett)) | |
| 29 | 29 | - Luke Stratman ([@lstratman](https://github.com/lstratman)) | |
| 30 | + - Konstantin Posudevskiy ([@konstantin-posudevskiy](https://github.com/konstantin-posudevskiy)) | ||
| 30 | 31 | - Matthias Dittrich ([@matthid](https://github.com/matthid)) | |
| 31 | 32 | - Patrick Stewart ([@patstew](https://github.com/patstew)) | |
| 32 | 33 | - Raphael Nestler ([@rnestler](https://github.com/rnestler)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 20 | 20 | - Fixed crash on exit of the Python interpreter if a python class | |
| 21 | 21 | derived from a .NET class has a `__namespace__` or `__assembly__` | |
| 22 | 22 | attribute (#481) | |
| 23 | + - Fixed conversion of 'float' and 'double' values (#486) | ||
| 24 | + | ||
| 23 | 25 | ||
| 24 | 26 | ## [2.3.0][] - 2017-03-11 | |
| 25 | 27 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,6 +84,7 @@ | |||
| 84 | 84 | <Compile Include="pyimport.cs" /> | |
| 85 | 85 | <Compile Include="pyinitialize.cs" /> | |
| 86 | 86 | <Compile Include="pyrunstring.cs" /> | |
| 87 | + <Compile Include="TestConverter.cs" /> | ||
| 87 | 88 | <Compile Include="TestCustomMarshal.cs" /> | |
| 88 | 89 | <Compile Include="TestExample.cs" /> | |
| 89 | 90 | <Compile Include="TestPyAnsiString.cs" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,48 @@ | |||
| 1 | + using NUnit.Framework; | ||
| 2 | + using Python.Runtime; | ||
| 3 | + | ||
| 4 | + namespace Python.EmbeddingTest | ||
| 5 | + { | ||
| 6 | + public class TestConverter | ||
| 7 | + { | ||
| 8 | + [OneTimeSetUp] | ||
| 9 | + public void SetUp() | ||
| 10 | + { | ||
| 11 | + PythonEngine.Initialize(); | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + [OneTimeTearDown] | ||
| 15 | + public void Dispose() | ||
| 16 | + { | ||
| 17 | + PythonEngine.Shutdown(); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + [Test] | ||
| 21 | + public void TestConvertSingleToManaged( | ||
| 22 | + [Values(float.PositiveInfinity, float.NegativeInfinity, float.MinValue, float.MaxValue, float.NaN, | ||
| 23 | + float.Epsilon)] float testValue) | ||
| 24 | + { | ||
| 25 | + var pyFloat = new PyFloat(testValue); | ||
| 26 | + | ||
| 27 | + object convertedValue; | ||
| 28 | + var converted = Converter.ToManaged(pyFloat.Handle, typeof(float), out convertedValue, false); | ||
| 29 | + | ||
| 30 | + Assert.IsTrue(converted); | ||
| 31 | + Assert.IsTrue(((float) convertedValue).Equals(testValue)); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + [Test] | ||
| 35 | + public void TestConvertDoubleToManaged( | ||
| 36 | + [Values(double.PositiveInfinity, double.NegativeInfinity, double.MinValue, double.MaxValue, double.NaN, | ||
| 37 | + double.Epsilon)] double testValue) | ||
| 38 | + { | ||
| 39 | + var pyFloat = new PyFloat(testValue); | ||
| 40 | + | ||
| 41 | + object convertedValue; | ||
| 42 | + var converted = Converter.ToManaged(pyFloat.Handle, typeof(double), out convertedValue, false); | ||
| 43 | + | ||
| 44 | + Assert.IsTrue(converted); | ||
| 45 | + Assert.IsTrue(((double) convertedValue).Equals(testValue)); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -770,10 +770,14 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo | |||
| 770 | 770 | goto type_error; | |
| 771 | 771 | } | |
| 772 | 772 | double dd = Runtime.PyFloat_AsDouble(op); | |
| 773 | + Runtime.CheckExceptionOccurred(); | ||
| 773 | 774 | Runtime.XDecref(op); | |
| 774 | 775 | if (dd > Single.MaxValue || dd < Single.MinValue) | |
| 775 | 776 | { | |
| 776 | - goto overflow; | ||
| 777 | + if (!double.IsInfinity(dd)) | ||
| 778 | + { | ||
| 779 | + goto overflow; | ||
| 780 | + } | ||
| 777 | 781 | } | |
| 778 | 782 | result = (float)dd; | |
| 779 | 783 | return true; | |
@@ -785,11 +789,8 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo | |||
| 785 | 789 | goto type_error; | |
| 786 | 790 | } | |
| 787 | 791 | double d = Runtime.PyFloat_AsDouble(op); | |
| 792 | + Runtime.CheckExceptionOccurred(); | ||
| 788 | 793 | Runtime.XDecref(op); | |
| 789 | - if (d > Double.MaxValue || d < Double.MinValue) | ||
| 790 | - { | ||
| 791 | - goto overflow; | ||
| 792 | - } | ||
| 793 | 794 | result = d; | |
| 794 | 795 | return true; | |
| 795 | 796 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -466,17 +466,6 @@ def test_double_conversion(): | |||
| 466 | 466 | with pytest.raises(TypeError): | |
| 467 | 467 | ConversionTest().DoubleField = None | |
| 468 | 468 | ||
| 469 | - with pytest.raises(OverflowError): | ||
| 470 | - ConversionTest().DoubleField = 1.7976931348623159e308 | ||
| 471 | - | ||
| 472 | - with pytest.raises(OverflowError): | ||
| 473 | - ConversionTest().DoubleField = -1.7976931348623159e308 | ||
| 474 | - | ||
| 475 | - with pytest.raises(OverflowError): | ||
| 476 | - _ = System.Double(1.7976931348623159e308) | ||
| 477 | - | ||
| 478 | - with pytest.raises(OverflowError): | ||
| 479 | - _ = System.Double(-1.7976931348623159e308) | ||
| 480 | 469 | ||
| 481 | 470 | ||
| 482 | 471 | def test_decimal_conversion(): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments