Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
            }
        }