Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support casting inf --> System.Double.PositiveInfinity #100

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

Closed
dhirschfeld opened this issue Sep 9, 2015 · 3 comments
Closed

Support casting inf --> System.Double.PositiveInfinity #100

dhirschfeld opened this issue Sep 9, 2015 · 3 comments

Comments

@dhirschfeld
Copy link
Contributor

Unless I'm mistaken there's no way to pass an infinity through to C# from Python?

namespace Demo {
    public static class TestDoubleCast {
        public static double PassThru(double arg) {
            return arg;
        }
    }
}
In [3]: from Demo import TestDoubleCast

In [4]: TestDoubleCast.PassThru(1)
Out[4]: 1.0

In [5]: TestDoubleCast.PassThru(3.14159)
Out[5]: 3.14159

In [6]: TestDoubleCast.PassThru(inf)
Traceback (most recent call last):

  File "<ipython-input-6-b27dffdb9fe9>", line 1, in <module>
    TestDoubleCast.PassThru(inf)

TypeError: No method matches given arguments


In [7]: TestDoubleCast.PassThru(System.Double.PositiveInfinity)
Traceback (most recent call last):

  File "<ipython-input-9-9828c102a734>", line 1, in <module>
    TestDoubleCast.PassThru(System.Double.PositiveInfinity)

TypeError: No method matches given argument


In [10]: System.Double(3.14159)  # works as expected
Out[10]: <System.Double at 0xaf31828>

In [11]: System.Double(inf)  # would like it to return a System.Double
Traceback (most recent call last):

  File "<ipython-input-11-1a15035c8521>", line 1, in <module>
    System.Double(inf)

OverflowError: value too large to convert

It would be very useful if the casting machinery could special case infinities so that you could create them from Python and they could be passed as arguments to methods expecting a System.Double

@den-run-ai
Copy link
Contributor

@dhirschfeld this is because of this code to avoid passing infinite values:

https://github.com/pythonnet/pythonnet/blob/develop/src/runtime/converter.cs#L688
https://github.com/pythonnet/pythonnet/blob/develop/src/runtime/converter.cs#L701

I agree that it is up to the developer to handle this in the user code, not throwing exceptions in pythonnet.

@tonyroberts do you agree?

@den-run-ai
Copy link
Contributor

@dhirschfeld this should now be resolved: #487

@Konstantin-Posudevskiy
Copy link
Contributor

@denfromufa could you close this issue, as it is resolved with #487?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants