+/-infinity in Python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andreas Neudecker

    +/-infinity in Python?

    Hi.

    Is there anything like +infinity and -infinity available in Python, and
    can it be used in comparisons together with int or float numbers?

    Regards


    Andreas


  • Peter Otten

    #2
    Re: +/-infinity in Python?

    Andreas Neudecker wrote:
    [color=blue]
    > Is there anything like +infinity and -infinity available in Python, and
    > can it be used in comparisons together with int or float numbers?[/color]

    To lazy to look it up, so let's try:
    [color=blue][color=green][color=darkred]
    >>> oo = float("infinity ")
    >>> noo = float("-infinity")
    >>> oo/noo[/color][/color][/color]
    nan[color=blue][color=green][color=darkred]
    >>> oo/2[/color][/color][/color]
    inf[color=blue][color=green][color=darkred]
    >>> noo/2[/color][/color][/color]
    -inf[color=blue][color=green][color=darkred]
    >>> 10e10 > oo[/color][/color][/color]
    False[color=blue][color=green][color=darkred]
    >>> 10e10 < oo[/color][/color][/color]
    True[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    :-)

    Peter

    Comment

    • Magnus Lie Hetland

      #3
      Re: +/-infinity in Python?

      In article <bp5tl4$r2t$03$ 1@news.t-online.com>, Peter Otten wrote:[color=blue]
      >Andreas Neudecker wrote:
      >[color=green]
      >> Is there anything like +infinity and -infinity available in Python, and
      >> can it be used in comparisons together with int or float numbers?[/color]
      >
      >To lazy to look it up, so let's try:[/color]
      [snip]

      Looking it up might be good, though... See, for example, PEP 754,
      "IEEE 754 Floating Point Special Values":

      This PEP proposes an API and a provides a reference module that generates and tests for IEEE 754 double-precision special values: positive infinity, negative infinity, and not-a-number (NaN).


      The problem is that the expression float('infinity ') works on some
      platforms, along with float('Inf'), but, as the PEP points out, on
      many systems you'll just get an error. You could also try stuff like
      float(1e3000).

      So, my response to the original question would be "sort of" -- since
      it's there, but it's not particularly reliable. Let's just hope that
      PEP 754 (or something similar) is accepted; infinity _is_ certainly
      useful...

      --
      Magnus Lie Hetland "In this house we obey the laws of
      http://hetland.org thermodynamics! " Homer Simpson

      Comment

      • Alexander Schmolck

        #4
        Re: +/-infinity in Python?

        Andreas Neudecker <a.neudecker@un i-bonn.de> writes:
        [color=blue]
        > Hi.
        >
        > Is there anything like +infinity and -infinity available in Python, and can it
        > be used in comparisons together with int or float numbers?[/color]

        The newest version of numarray and scipy should offer the functionality you
        want (at least for supported platforms).

        'as

        Comment

        • Andreas Neudecker

          #5
          Re: +/-infinity in Python?

          Hello Peter, Magnus,

          thanks for your hints.

          I will read the PEPs first, because I need compatibility at least for
          Linux and Windows ...

          Kind regards


          Andreas


          Andreas Neudecker wrote:[color=blue]
          > Hi.
          >
          > Is there anything like +infinity and -infinity available in Python, and
          > can it be used in comparisons together with int or float numbers?
          >
          > Regards
          >
          >
          > Andreas
          >
          >[/color]

          Comment

          Working...