Блог пользователя naevis

Автор naevis, история, 6 лет назад, По-английски

If double can store larger value than long long, then why everyone rarely used double?

  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится +71 Проголосовать: не нравится

Because double can't accurately store integers whose absolute value exceeds $$$2^{53}$$$. Take a look at this:

cout << (long long)(double)123451234512345677LL << '\n';

This will not print what you might expect. To avoid such situations, double should be avoided in favor of long long when an exact algorithm is needed and all input/output/intermediate variables can be represented as integers. Also, integer types tend to be significantly faster.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    This is not entirely true, double can store accurately integers over 2^53 as long as the integer can be represented with 53 bits multiplied by a power of two (within 11 bits). For example, 2^100 has only 1 bit and a power of two of 100 that can fit with 11 bits, so it can be stored without a loss of precision and can be tested for direct equality without abs(num1-num2)<epsilon trick.

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +32 Проголосовать: не нравится

      I didn't say that all such integers can't be represented, the point is that some can't.

      • »
        »
        »
        »
        6 лет назад, # ^ |
        Rev. 4   Проголосовать: нравится -17 Проголосовать: не нравится

        Downvote me, please, but choose one :)

        • "double can't accurately store integers whose absolute value exceeds 2^53"

        • "I didn't say that all such integers can't be represented"

        Formally, your first statement states that if an integer is above 2^53, it can't be represented correctly, so any such integer being represented correctly contradicts your statement, so the "all" is implied here.

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
            Проголосовать: нравится +11 Проголосовать: не нравится

          If you can't accurately hit a target that doesn't mean that you will never hit it. The negation of accurate is not "always misses" but "does not always hit" — look up negation of logic quantifiers.

          • »
            »
            »
            »
            »
            »
            6 лет назад, # ^ |
            Rev. 4   Проголосовать: нравится -8 Проголосовать: не нравится

            accuracy (n) — the quality or state of being correct or precise.

            not accurate — not being correct or precise, NOT low % of being correct or precise :)

            • »
              »
              »
              »
              »
              »
              »
              6 лет назад, # ^ |
                Проголосовать: нравится +8 Проголосовать: не нравится

              I give up, check back in a year

              • »
                »
                »
                »
                »
                »
                »
                »
                6 лет назад, # ^ |
                  Проголосовать: нравится 0 Проголосовать: не нравится

                Appreciated, thanks, you gave hope to all the blues :)

            • »
              »
              »
              »
              »
              »
              »
              6 лет назад, # ^ |
                Проголосовать: нравится +3 Проголосовать: не нравится

              That's where you're wrong. Let accuracy(n) be $$$A$$$ and the quality or state of being correct be $$$C$$$. Then $$$A \rightarrow C$$$ $$$\equiv$$$ $$$\neg C \rightarrow \neg A$$$, but it is not the same as $$$\neg A \rightarrow \neg C$$$.

              That is, accuracy implies it is correct, and not correct implies that is is not accurate, but not accurate does not imply it is not correct.

              It may be correct or may not be, but it is in no way a guarentee.

              • »
                »
                »
                »
                »
                »
                »
                »
                6 лет назад, # ^ |
                  Проголосовать: нравится 0 Проголосовать: не нравится

                You are mistaking definition (iff) with implication.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  6 лет назад, # ^ |
                  Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

                  The thing is it is not a bi-implication(iff), but an implication. If it is correct, it in no way means it is accurate. Maybe it was correct with very low probability on that experiment, and thus has low accuracy, ie not accurate.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  6 лет назад, # ^ |
                  Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

                  So in your logic if something is not white, it may or may not be white :D

                  I'm giving up now too, back in a year.