Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. strange realization of StrToD()

strange realization of StrToD()

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    a_matseevsky
    wrote on last edited by
    #1

    Once I have a long file with ascii text- long row of numbers. I used StrToD() to convert text to array of floating point numbers. I couldn't undrestand, why it works so slowly? Running it under debbugger, I realized what was the problem. This stupid function scanned the whole file, looking for null terminator! I think, there is no reason to scan long text string after set of chars, belonging to the first number has been obtained. Finally I had to write my own realisation of this function.

    CPalliniC J 2 Replies Last reply
    0
    • A a_matseevsky

      Once I have a long file with ascii text- long row of numbers. I used StrToD() to convert text to array of floating point numbers. I couldn't undrestand, why it works so slowly? Running it under debbugger, I realized what was the problem. This stupid function scanned the whole file, looking for null terminator! I think, there is no reason to scan long text string after set of chars, belonging to the first number has been obtained. Finally I had to write my own realisation of this function.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      strtod (that is the 'standard' C++ strtod, I never heard about StrToD) is not 'strange': it is a function satisfying its own requirements that are clearly explained, for instance here[^]. If it doesn't fit your needs, then, well, the right way is to write your own one (as you did).

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      A 1 Reply Last reply
      0
      • CPalliniC CPallini

        strtod (that is the 'standard' C++ strtod, I never heard about StrToD) is not 'strange': it is a function satisfying its own requirements that are clearly explained, for instance here[^]. If it doesn't fit your needs, then, well, the right way is to write your own one (as you did).

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        A Offline
        A Offline
        a_matseevsky
        wrote on last edited by
        #3

        You are right about lowercase: strtod(const char *nptr, char **endptr) returns floating point value and a pointer to the first char, that stops scanning. It means, that if I have for example such string "12.3 0.07" and give pointer to this string to strtod for eating, it will return me 12.3 and pointer to the next char after '3'. Thats all right, no objections. But name me one reason to scan THE WHOLE string??? Why do not stop scanning after four first chars? It is my non-humble opinion: it typical left-hand approach.

        C 1 Reply Last reply
        0
        • A a_matseevsky

          You are right about lowercase: strtod(const char *nptr, char **endptr) returns floating point value and a pointer to the first char, that stops scanning. It means, that if I have for example such string "12.3 0.07" and give pointer to this string to strtod for eating, it will return me 12.3 and pointer to the next char after '3'. Thats all right, no objections. But name me one reason to scan THE WHOLE string??? Why do not stop scanning after four first chars? It is my non-humble opinion: it typical left-hand approach.

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          strtod uses strlen, internally - at least in VS2008. but VS2010 fixes this, reportedly.

          image processing toolkits | batch image processing

          A 1 Reply Last reply
          0
          • C Chris Losinger

            strtod uses strlen, internally - at least in VS2008. but VS2010 fixes this, reportedly.

            image processing toolkits | batch image processing

            A Offline
            A Offline
            a_matseevsky
            wrote on last edited by
            #5

            I use VS2005. I like it and this example of strange behavior is the only one what I actually met. No matter, build-in assembler lets me write compact and efficient procedures, when and if I have need in extra performance.

            1 Reply Last reply
            0
            • A a_matseevsky

              Once I have a long file with ascii text- long row of numbers. I used StrToD() to convert text to array of floating point numbers. I couldn't undrestand, why it works so slowly? Running it under debbugger, I realized what was the problem. This stupid function scanned the whole file, looking for null terminator! I think, there is no reason to scan long text string after set of chars, belonging to the first number has been obtained. Finally I had to write my own realisation of this function.

              J Offline
              J Offline
              JackDingler
              wrote on last edited by
              #6

              Looks like you found a bug.

              A 1 Reply Last reply
              0
              • J JackDingler

                Looks like you found a bug.

                A Offline
                A Offline
                a_matseevsky
                wrote on last edited by
                #7

                I wouldn't say so: procedure works correctly. It is only inefficient realization, no more. I met a real bug in VS 6.0, but now it is of no use to speak about such ancient soft. Sometimes VS2005 asks me for confirmation, when I try to close prog, currently running under debugger, but it happens probably due to old age of my particulat exemplar.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups