public void AsFloatGood() { const double a = 4.5; var i = new PyFloat(a); PyFloat s = PyFloat.AsFloat(i); Assert.True(PyFloat.IsFloatType(s)); // Assert.Assert.AreEqual(i, a.ToInt32()); }
public void AsFloatBad() { var s = new PyString("Foo"); PyFloat a = null; var ex = Assert.Throws <PythonException>(() => a = PyFloat.AsFloat(s)); StringAssert.StartsWith("could not convert string to float", ex.Message); Assert.IsNull(a); }
public static double GetDouble(dynamic dynDoublePyObj, ref double?doubleMember) { if (doubleMember != null) { return((double)doubleMember); } using (Py.GIL()) { var dynDoublePyFloat = PyFloat.AsFloat(dynDoublePyObj); doubleMember = dynDoublePyFloat.As <double>(); return((double)doubleMember); } }