[Ironpython-users] Implicit conversion of objects to float

Jeff Hardy jdhardy at gmail.com
Fri Feb 24 20:20:26 CET 2012

On Fri, Feb 24, 2012 at 10:54 AM, Cesar Mello <cmello at gmail.com> wrote:
> Is there a way to satisfy both scenarios? So that the object could also be
> evaluated implicitly as a float?
> My first thought was to use a coercion, but the documentation does not
> recommend it. Any other suggestions please?

You didn't specify if the objects are Python or C#, but I'm assuming C#.

You'll need to overload + - * / on the objects to behave as you want,
to cover basic math, and
add an impilcit conversion to float ('implicit operator float()' in
C#, __float__ in Python) if they decide to call sqrt() or similar.

I'm assuming IronPython will handle the conversions properly; if not,
file a bug because it's a pretty big problem if it doesn't.

- Jeff

More information about the Ironpython-users mailing list