Is the inverse of std::numeric_limits::infinity() zero?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
17
down vote

favorite
3












Is there anything in the C++ standard (or the IEEE 754 floating-point standard) that guarantees that 1./std::numeric_limits<double>::infinity() is zero (or at least a small number)?







share|improve this question






















  • Look into floating-point-gui.de
    – Basile Starynkevitch
    Aug 25 at 9:27










  • Very related.
    – user202729
    Aug 25 at 14:46














up vote
17
down vote

favorite
3












Is there anything in the C++ standard (or the IEEE 754 floating-point standard) that guarantees that 1./std::numeric_limits<double>::infinity() is zero (or at least a small number)?







share|improve this question






















  • Look into floating-point-gui.de
    – Basile Starynkevitch
    Aug 25 at 9:27










  • Very related.
    – user202729
    Aug 25 at 14:46












up vote
17
down vote

favorite
3









up vote
17
down vote

favorite
3






3





Is there anything in the C++ standard (or the IEEE 754 floating-point standard) that guarantees that 1./std::numeric_limits<double>::infinity() is zero (or at least a small number)?







share|improve this question














Is there anything in the C++ standard (or the IEEE 754 floating-point standard) that guarantees that 1./std::numeric_limits<double>::infinity() is zero (or at least a small number)?









share|improve this question













share|improve this question




share|improve this question








edited Aug 26 at 11:03









Peter Mortensen

12.9k1983111




12.9k1983111










asked Aug 25 at 9:25









davidhigh

8,65411843




8,65411843











  • Look into floating-point-gui.de
    – Basile Starynkevitch
    Aug 25 at 9:27










  • Very related.
    – user202729
    Aug 25 at 14:46
















  • Look into floating-point-gui.de
    – Basile Starynkevitch
    Aug 25 at 9:27










  • Very related.
    – user202729
    Aug 25 at 14:46















Look into floating-point-gui.de
– Basile Starynkevitch
Aug 25 at 9:27




Look into floating-point-gui.de
– Basile Starynkevitch
Aug 25 at 9:27












Very related.
– user202729
Aug 25 at 14:46




Very related.
– user202729
Aug 25 at 14:46












4 Answers
4






active

oldest

votes

















up vote
11
down vote



accepted










Yes, according to the GNU C library reference manual (assuming IEEE 754):




Infinities propagate through calculations
as one would expect: for example, 2 + ∞ = ∞, 4/∞ =
0




https://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html



You may want to check if your C++ compiler uses IEEE 754:



How to check if C++ compiler uses IEEE 754 floating point standard






share|improve this answer





























    up vote
    15
    down vote













    Any finite number divided by infinity results in zero under IEEE 754 (and therefore the same in most typical C++ implementations).



    If the sign of the of numerator and denominator differ, the result will be negative zero, which is equal to zero.






    share|improve this answer


















    • 3




      Uhm, no, not exactly: if the finite number is negative it returns -0, which is not the same thing as 0 (although it compares equal).
      – Federico Poloni
      Aug 25 at 12:31






    • 6




      Yeah, the proper wording would be "results in a zero" :)
      – Ruslan
      Aug 25 at 13:09






    • 2




      @FedericoPoloni: Both +0 and −0 in IEEE 754 specification level 2 (floating-point data) represent zero in level 1 (extended real numbers).
      – Eric Postpischil
      Aug 25 at 17:46


















    up vote
    4
    down vote













    IEEE 754-2008 6.1 says:




    The behavior of infinity in floating-point arithmetic is derived from the limiting cases of real arithmetic with operands of arbitrarily large magnitude, when such a limit exists. Infinities shall be interpreted in the affine sense, that is: −∞ < every finite number < +∞.



    Operations on infinite operands are usually exact and therefore signal no exceptions,…




    Since the limit of 1/x as x increases without bound is zero, a consequence of this clause is that 1/∞ is zero.



    Clause 6.3 tells us the sign of the result is +:




    When neither the inputs nor result are NaN, the sign of a product or quotient is the exclusive OR of the operands’ signs;…







    share|improve this answer



























      up vote
      0
      down vote













      if(std::numeric_limits<double>::is_iec559)
      yes();
      else
      no();



      (see 18.3.2.4)



      IEC 559, which is identical with IEEE 754, guarantees that to be the case. However, C++ does not guarantee in any way that IEC 559 is in place (although 99.99% of the time that's just what happens to be the case, you still need to verify to be sure).






      share|improve this answer
















      • 1




        Since nobody is likely to bother implementing and testing non-IEEE 754 platforms, one might as well static_assert(std::numeric_limits<double>::is_iec559).
        – John Zwinck
        Aug 26 at 2:01










      • @JohnZwinck: That's actually a good point. If your code relies on IEEE 754 particulars, then it won't work if these aren't present. So static_assert is a very valid option (possibly, probably, even the better one).
        – Damon
        Aug 26 at 12:26










      Your Answer





      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52015831%2fis-the-inverse-of-stdnumeric-limitsinfinity-zero%23new-answer', 'question_page');

      );

      Post as a guest






























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      11
      down vote



      accepted










      Yes, according to the GNU C library reference manual (assuming IEEE 754):




      Infinities propagate through calculations
      as one would expect: for example, 2 + ∞ = ∞, 4/∞ =
      0




      https://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html



      You may want to check if your C++ compiler uses IEEE 754:



      How to check if C++ compiler uses IEEE 754 floating point standard






      share|improve this answer


























        up vote
        11
        down vote



        accepted










        Yes, according to the GNU C library reference manual (assuming IEEE 754):




        Infinities propagate through calculations
        as one would expect: for example, 2 + ∞ = ∞, 4/∞ =
        0




        https://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html



        You may want to check if your C++ compiler uses IEEE 754:



        How to check if C++ compiler uses IEEE 754 floating point standard






        share|improve this answer
























          up vote
          11
          down vote



          accepted







          up vote
          11
          down vote



          accepted






          Yes, according to the GNU C library reference manual (assuming IEEE 754):




          Infinities propagate through calculations
          as one would expect: for example, 2 + ∞ = ∞, 4/∞ =
          0




          https://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html



          You may want to check if your C++ compiler uses IEEE 754:



          How to check if C++ compiler uses IEEE 754 floating point standard






          share|improve this answer














          Yes, according to the GNU C library reference manual (assuming IEEE 754):




          Infinities propagate through calculations
          as one would expect: for example, 2 + ∞ = ∞, 4/∞ =
          0




          https://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html



          You may want to check if your C++ compiler uses IEEE 754:



          How to check if C++ compiler uses IEEE 754 floating point standard







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 26 at 11:05









          Peter Mortensen

          12.9k1983111




          12.9k1983111










          answered Aug 25 at 9:43









          Gonen I

          1,4841025




          1,4841025






















              up vote
              15
              down vote













              Any finite number divided by infinity results in zero under IEEE 754 (and therefore the same in most typical C++ implementations).



              If the sign of the of numerator and denominator differ, the result will be negative zero, which is equal to zero.






              share|improve this answer


















              • 3




                Uhm, no, not exactly: if the finite number is negative it returns -0, which is not the same thing as 0 (although it compares equal).
                – Federico Poloni
                Aug 25 at 12:31






              • 6




                Yeah, the proper wording would be "results in a zero" :)
                – Ruslan
                Aug 25 at 13:09






              • 2




                @FedericoPoloni: Both +0 and −0 in IEEE 754 specification level 2 (floating-point data) represent zero in level 1 (extended real numbers).
                – Eric Postpischil
                Aug 25 at 17:46















              up vote
              15
              down vote













              Any finite number divided by infinity results in zero under IEEE 754 (and therefore the same in most typical C++ implementations).



              If the sign of the of numerator and denominator differ, the result will be negative zero, which is equal to zero.






              share|improve this answer


















              • 3




                Uhm, no, not exactly: if the finite number is negative it returns -0, which is not the same thing as 0 (although it compares equal).
                – Federico Poloni
                Aug 25 at 12:31






              • 6




                Yeah, the proper wording would be "results in a zero" :)
                – Ruslan
                Aug 25 at 13:09






              • 2




                @FedericoPoloni: Both +0 and −0 in IEEE 754 specification level 2 (floating-point data) represent zero in level 1 (extended real numbers).
                – Eric Postpischil
                Aug 25 at 17:46













              up vote
              15
              down vote










              up vote
              15
              down vote









              Any finite number divided by infinity results in zero under IEEE 754 (and therefore the same in most typical C++ implementations).



              If the sign of the of numerator and denominator differ, the result will be negative zero, which is equal to zero.






              share|improve this answer














              Any finite number divided by infinity results in zero under IEEE 754 (and therefore the same in most typical C++ implementations).



              If the sign of the of numerator and denominator differ, the result will be negative zero, which is equal to zero.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Aug 26 at 2:03

























              answered Aug 25 at 9:34









              John Zwinck

              141k16171279




              141k16171279







              • 3




                Uhm, no, not exactly: if the finite number is negative it returns -0, which is not the same thing as 0 (although it compares equal).
                – Federico Poloni
                Aug 25 at 12:31






              • 6




                Yeah, the proper wording would be "results in a zero" :)
                – Ruslan
                Aug 25 at 13:09






              • 2




                @FedericoPoloni: Both +0 and −0 in IEEE 754 specification level 2 (floating-point data) represent zero in level 1 (extended real numbers).
                – Eric Postpischil
                Aug 25 at 17:46













              • 3




                Uhm, no, not exactly: if the finite number is negative it returns -0, which is not the same thing as 0 (although it compares equal).
                – Federico Poloni
                Aug 25 at 12:31






              • 6




                Yeah, the proper wording would be "results in a zero" :)
                – Ruslan
                Aug 25 at 13:09






              • 2




                @FedericoPoloni: Both +0 and −0 in IEEE 754 specification level 2 (floating-point data) represent zero in level 1 (extended real numbers).
                – Eric Postpischil
                Aug 25 at 17:46








              3




              3




              Uhm, no, not exactly: if the finite number is negative it returns -0, which is not the same thing as 0 (although it compares equal).
              – Federico Poloni
              Aug 25 at 12:31




              Uhm, no, not exactly: if the finite number is negative it returns -0, which is not the same thing as 0 (although it compares equal).
              – Federico Poloni
              Aug 25 at 12:31




              6




              6




              Yeah, the proper wording would be "results in a zero" :)
              – Ruslan
              Aug 25 at 13:09




              Yeah, the proper wording would be "results in a zero" :)
              – Ruslan
              Aug 25 at 13:09




              2




              2




              @FedericoPoloni: Both +0 and −0 in IEEE 754 specification level 2 (floating-point data) represent zero in level 1 (extended real numbers).
              – Eric Postpischil
              Aug 25 at 17:46





              @FedericoPoloni: Both +0 and −0 in IEEE 754 specification level 2 (floating-point data) represent zero in level 1 (extended real numbers).
              – Eric Postpischil
              Aug 25 at 17:46











              up vote
              4
              down vote













              IEEE 754-2008 6.1 says:




              The behavior of infinity in floating-point arithmetic is derived from the limiting cases of real arithmetic with operands of arbitrarily large magnitude, when such a limit exists. Infinities shall be interpreted in the affine sense, that is: −∞ < every finite number < +∞.



              Operations on infinite operands are usually exact and therefore signal no exceptions,…




              Since the limit of 1/x as x increases without bound is zero, a consequence of this clause is that 1/∞ is zero.



              Clause 6.3 tells us the sign of the result is +:




              When neither the inputs nor result are NaN, the sign of a product or quotient is the exclusive OR of the operands’ signs;…







              share|improve this answer
























                up vote
                4
                down vote













                IEEE 754-2008 6.1 says:




                The behavior of infinity in floating-point arithmetic is derived from the limiting cases of real arithmetic with operands of arbitrarily large magnitude, when such a limit exists. Infinities shall be interpreted in the affine sense, that is: −∞ < every finite number < +∞.



                Operations on infinite operands are usually exact and therefore signal no exceptions,…




                Since the limit of 1/x as x increases without bound is zero, a consequence of this clause is that 1/∞ is zero.



                Clause 6.3 tells us the sign of the result is +:




                When neither the inputs nor result are NaN, the sign of a product or quotient is the exclusive OR of the operands’ signs;…







                share|improve this answer






















                  up vote
                  4
                  down vote










                  up vote
                  4
                  down vote









                  IEEE 754-2008 6.1 says:




                  The behavior of infinity in floating-point arithmetic is derived from the limiting cases of real arithmetic with operands of arbitrarily large magnitude, when such a limit exists. Infinities shall be interpreted in the affine sense, that is: −∞ < every finite number < +∞.



                  Operations on infinite operands are usually exact and therefore signal no exceptions,…




                  Since the limit of 1/x as x increases without bound is zero, a consequence of this clause is that 1/∞ is zero.



                  Clause 6.3 tells us the sign of the result is +:




                  When neither the inputs nor result are NaN, the sign of a product or quotient is the exclusive OR of the operands’ signs;…







                  share|improve this answer












                  IEEE 754-2008 6.1 says:




                  The behavior of infinity in floating-point arithmetic is derived from the limiting cases of real arithmetic with operands of arbitrarily large magnitude, when such a limit exists. Infinities shall be interpreted in the affine sense, that is: −∞ < every finite number < +∞.



                  Operations on infinite operands are usually exact and therefore signal no exceptions,…




                  Since the limit of 1/x as x increases without bound is zero, a consequence of this clause is that 1/∞ is zero.



                  Clause 6.3 tells us the sign of the result is +:




                  When neither the inputs nor result are NaN, the sign of a product or quotient is the exclusive OR of the operands’ signs;…








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 25 at 17:52









                  Eric Postpischil

                  64.8k872145




                  64.8k872145




















                      up vote
                      0
                      down vote













                      if(std::numeric_limits<double>::is_iec559)
                      yes();
                      else
                      no();



                      (see 18.3.2.4)



                      IEC 559, which is identical with IEEE 754, guarantees that to be the case. However, C++ does not guarantee in any way that IEC 559 is in place (although 99.99% of the time that's just what happens to be the case, you still need to verify to be sure).






                      share|improve this answer
















                      • 1




                        Since nobody is likely to bother implementing and testing non-IEEE 754 platforms, one might as well static_assert(std::numeric_limits<double>::is_iec559).
                        – John Zwinck
                        Aug 26 at 2:01










                      • @JohnZwinck: That's actually a good point. If your code relies on IEEE 754 particulars, then it won't work if these aren't present. So static_assert is a very valid option (possibly, probably, even the better one).
                        – Damon
                        Aug 26 at 12:26














                      up vote
                      0
                      down vote













                      if(std::numeric_limits<double>::is_iec559)
                      yes();
                      else
                      no();



                      (see 18.3.2.4)



                      IEC 559, which is identical with IEEE 754, guarantees that to be the case. However, C++ does not guarantee in any way that IEC 559 is in place (although 99.99% of the time that's just what happens to be the case, you still need to verify to be sure).






                      share|improve this answer
















                      • 1




                        Since nobody is likely to bother implementing and testing non-IEEE 754 platforms, one might as well static_assert(std::numeric_limits<double>::is_iec559).
                        – John Zwinck
                        Aug 26 at 2:01










                      • @JohnZwinck: That's actually a good point. If your code relies on IEEE 754 particulars, then it won't work if these aren't present. So static_assert is a very valid option (possibly, probably, even the better one).
                        – Damon
                        Aug 26 at 12:26












                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      if(std::numeric_limits<double>::is_iec559)
                      yes();
                      else
                      no();



                      (see 18.3.2.4)



                      IEC 559, which is identical with IEEE 754, guarantees that to be the case. However, C++ does not guarantee in any way that IEC 559 is in place (although 99.99% of the time that's just what happens to be the case, you still need to verify to be sure).






                      share|improve this answer












                      if(std::numeric_limits<double>::is_iec559)
                      yes();
                      else
                      no();



                      (see 18.3.2.4)



                      IEC 559, which is identical with IEEE 754, guarantees that to be the case. However, C++ does not guarantee in any way that IEC 559 is in place (although 99.99% of the time that's just what happens to be the case, you still need to verify to be sure).







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Aug 25 at 16:50









                      Damon

                      49.2k1492151




                      49.2k1492151







                      • 1




                        Since nobody is likely to bother implementing and testing non-IEEE 754 platforms, one might as well static_assert(std::numeric_limits<double>::is_iec559).
                        – John Zwinck
                        Aug 26 at 2:01










                      • @JohnZwinck: That's actually a good point. If your code relies on IEEE 754 particulars, then it won't work if these aren't present. So static_assert is a very valid option (possibly, probably, even the better one).
                        – Damon
                        Aug 26 at 12:26












                      • 1




                        Since nobody is likely to bother implementing and testing non-IEEE 754 platforms, one might as well static_assert(std::numeric_limits<double>::is_iec559).
                        – John Zwinck
                        Aug 26 at 2:01










                      • @JohnZwinck: That's actually a good point. If your code relies on IEEE 754 particulars, then it won't work if these aren't present. So static_assert is a very valid option (possibly, probably, even the better one).
                        – Damon
                        Aug 26 at 12:26







                      1




                      1




                      Since nobody is likely to bother implementing and testing non-IEEE 754 platforms, one might as well static_assert(std::numeric_limits<double>::is_iec559).
                      – John Zwinck
                      Aug 26 at 2:01




                      Since nobody is likely to bother implementing and testing non-IEEE 754 platforms, one might as well static_assert(std::numeric_limits<double>::is_iec559).
                      – John Zwinck
                      Aug 26 at 2:01












                      @JohnZwinck: That's actually a good point. If your code relies on IEEE 754 particulars, then it won't work if these aren't present. So static_assert is a very valid option (possibly, probably, even the better one).
                      – Damon
                      Aug 26 at 12:26




                      @JohnZwinck: That's actually a good point. If your code relies on IEEE 754 particulars, then it won't work if these aren't present. So static_assert is a very valid option (possibly, probably, even the better one).
                      – Damon
                      Aug 26 at 12:26

















                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52015831%2fis-the-inverse-of-stdnumeric-limitsinfinity-zero%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      List of Gilmore Girls characters

                      Confectionery