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. Simple divison has GONE MAD!

Simple divison has GONE MAD!

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 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.
  • S Offline
    S Offline
    Selevercin
    wrote on last edited by
    #1

    I have a variable int that when I divide by 2, it all on it's own it divides by 4. By playing with it, I figured out that if I mulitply by about the square root of 2 / 2 the computer simply divides by two. I've even rebuilt the whole project. The int is normally around 3,000,000 and the only thing I can think is that maybe it's larger than it may legally be. So I tried casting it to double, but I got the same responce. Any and all help is greatly appreciated. If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.

    P 1 Reply Last reply
    0
    • S Selevercin

      I have a variable int that when I divide by 2, it all on it's own it divides by 4. By playing with it, I figured out that if I mulitply by about the square root of 2 / 2 the computer simply divides by two. I've even rebuilt the whole project. The int is normally around 3,000,000 and the only thing I can think is that maybe it's larger than it may legally be. So I tried casting it to double, but I got the same responce. Any and all help is greatly appreciated. If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.

      P Offline
      P Offline
      Phil Martin
      wrote on last edited by
      #2

      This is mighty weird. What are the exact lines of code that are doing the division?

      S 1 Reply Last reply
      0
      • P Phil Martin

        This is mighty weird. What are the exact lines of code that are doing the division?

        S Offline
        S Offline
        Selevercin
        wrote on last edited by
        #3

        int iDecryptID = m_iID; iDecryptID /= 2; return iDecryptID; By returning m_iID I know that it is, in fact, the divison that is the problem. If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.

        T P 2 Replies Last reply
        0
        • S Selevercin

          int iDecryptID = m_iID; iDecryptID /= 2; return iDecryptID; By returning m_iID I know that it is, in fact, the divison that is the problem. If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.

          T Offline
          T Offline
          Tim Smith
          wrote on last edited by
          #4

          Nope, the division is working properly. The chance of a compiler error is very very very small. If the output isn't matching the expected value, then the input isn't what you think it is or something else is going on. With strange problems like this, 99.9999% of the time it is the programmer who is making assumptions that are wrong. Tim Smith I'm going to patent thought. I have yet to see any prior art.

          1 Reply Last reply
          0
          • S Selevercin

            int iDecryptID = m_iID; iDecryptID /= 2; return iDecryptID; By returning m_iID I know that it is, in fact, the divison that is the problem. If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.

            P Offline
            P Offline
            Paul Ranson
            wrote on last edited by
            #5

            Can you post more context? I'm quite sure that,

            #include <iostream%gt;
            int Bogus ( int nTest )
            {
            int iPart = nTest ;
            iPart /= 2 ;
            return iPart ;
            }

            int main ()
            {
            std::cout << "Result of Bogus ( 3000000 ) = " << Bogus ( 3000000 ) << std::endl ;
            return 0 ;
            }

            will be as expected.

            Paul

            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