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. Calc can, but my code can't

Calc can, but my code can't

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 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.
  • W Offline
    W Offline
    Waldermort
    wrote on last edited by
    #1

    After a user click, I am pulling a value from a control, converting this into a decimal value and relaying it to another control. The theory is correct, but I just cannot get my code to produce the correct value. This is the formula: double dZoomFactor = 1 / ( 1 << ( 16 - dwId ) ); where dwId is an integer value between 1 and 16; In theory: dZoomFactor = 1 / ( 1 << ( 16 - 1 ) ); dZoomFactor = 1 / ( 1 << 15 ); dZoomFactor = 1 / 32768; dZoomFactor = 0.000030517578125; But, the output is always a flat '0.0'. What am I missing?

    Waldermort

    L D 2 Replies Last reply
    0
    • W Waldermort

      After a user click, I am pulling a value from a control, converting this into a decimal value and relaying it to another control. The theory is correct, but I just cannot get my code to produce the correct value. This is the formula: double dZoomFactor = 1 / ( 1 << ( 16 - dwId ) ); where dwId is an integer value between 1 and 16; In theory: dZoomFactor = 1 / ( 1 << ( 16 - 1 ) ); dZoomFactor = 1 / ( 1 << 15 ); dZoomFactor = 1 / 32768; dZoomFactor = 0.000030517578125; But, the output is always a flat '0.0'. What am I missing?

      Waldermort

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      double dZoomFactor = 1.0 / 32768.0;

      led mike

      W 1 Reply Last reply
      0
      • L led mike

        double dZoomFactor = 1.0 / 32768.0;

        led mike

        W Offline
        W Offline
        Waldermort
        wrote on last edited by
        #3

        That comes out as 3.0517578125000000e-005. Wish I payed more attention to maths back in school. Right now I'm trying to find out what that e-005 means.

        Waldermort

        C L 2 Replies Last reply
        0
        • W Waldermort

          That comes out as 3.0517578125000000e-005. Wish I payed more attention to maths back in school. Right now I'm trying to find out what that e-005 means.

          Waldermort

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          WalderMight now I'm trying to find out what that e-005 means.

          It means 10^-5, i.e.

          3.0517578125000000e-005 = 0.000030517578125000000

          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

          W 1 Reply Last reply
          0
          • C CPallini

            WalderMight now I'm trying to find out what that e-005 means.

            It means 10^-5, i.e.

            3.0517578125000000e-005 = 0.000030517578125000000

            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

            W Offline
            W Offline
            Waldermort
            wrote on last edited by
            #5

            Thankyou thankyou thankyou. I have been on google for the last hour trying to find the meaning of that, but every page seems to think it's a universally understood system, kinda makes me feel stupid :sigh: Anyway, my code is now working. Thanks for the help guys :-D

            Waldermort

            1 Reply Last reply
            0
            • W Waldermort

              After a user click, I am pulling a value from a control, converting this into a decimal value and relaying it to another control. The theory is correct, but I just cannot get my code to produce the correct value. This is the formula: double dZoomFactor = 1 / ( 1 << ( 16 - dwId ) ); where dwId is an integer value between 1 and 16; In theory: dZoomFactor = 1 / ( 1 << ( 16 - 1 ) ); dZoomFactor = 1 / ( 1 << 15 ); dZoomFactor = 1 / 32768; dZoomFactor = 0.000030517578125; But, the output is always a flat '0.0'. What am I missing?

              Waldermort

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              WalderMouble wrote:

              dZoomFactor = 1 / ( 1 << ( 16 - dwId ) ); dZoomFactor = 1 / ( 1 << ( 16 - 1 ) ); dZoomFactor = 1 / ( 1 << 15 ); dZoomFactor = 1 / 32768; dZoomFactor = 0.000030517578125;

              You should probably be using double constants (e.g., 1.0, 16.0), so that the math library is properly initialized. BTW, your name wreaks havoc in the Quote Selected Text feature. It inserts a malformed </b> tag.

              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              W 1 Reply Last reply
              0
              • W Waldermort

                That comes out as 3.0517578125000000e-005. Wish I payed more attention to maths back in school. Right now I'm trying to find out what that e-005 means.

                Waldermort

                L Offline
                L Offline
                led mike
                wrote on last edited by
                #7

                http://en.wikipedia.org/wiki/Scientific_notation[^]

                led mike

                W 1 Reply Last reply
                0
                • D David Crow

                  WalderMouble wrote:

                  dZoomFactor = 1 / ( 1 << ( 16 - dwId ) ); dZoomFactor = 1 / ( 1 << ( 16 - 1 ) ); dZoomFactor = 1 / ( 1 << 15 ); dZoomFactor = 1 / 32768; dZoomFactor = 0.000030517578125;

                  You should probably be using double constants (e.g., 1.0, 16.0), so that the math library is properly initialized. BTW, your name wreaks havoc in the Quote Selected Text feature. It inserts a malformed </b> tag.

                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  W Offline
                  W Offline
                  Waldermort
                  wrote on last edited by
                  #8

                  That's exactly what I was doing wrong, but that exponent was giving me a real headache, I thought the wrong values were coming out. I hate floating point maths!

                  Waldermort

                  1 Reply Last reply
                  0
                  • L led mike

                    http://en.wikipedia.org/wiki/Scientific_notation[^]

                    led mike

                    W Offline
                    W Offline
                    Waldermort
                    wrote on last edited by
                    #9

                    Thanks for the link, but the 'great firewall of china' prevents me from accessing wikipedia :((

                    Waldermort

                    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