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. Math problem with C code

Math problem with C code

Scheduled Pinned Locked Moved C / C++ / MFC
databasegraphicsgame-devregexhelp
4 Posts 3 Posters 2 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.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    Just FYI, this is NOT a repost. As usual I have posted the original in WRONG pew. However, I found another even weirder failure of simple math case and I really do not have a clue what I am doing wrong. Are my local variable assignments incorrect ? Is "printf" lying to me ? Here is the entire test code

    #define MAX_CIRCLES 5

    struct TAG_Circles {
    float radius;
    float center;
    float center_x;
    float center_y;

    } REAL_Circle[MAX_CIRCLES], IMG_Circle[MAX_CIRCLES];

    void OpenGL_Stencil_Circle_Build(void);
    // copy last circle to stencil
    void OpenGL_Stencil_Circle_Build(void) {
    //
    int index = 5;
    {
    // last circle
    float radius = IMG_circle[index].radius;
    float center_x = IMG_circle[index].center_x;
    float center_y = IMG_circle[index].center_y;
    printf("\n Last circle #%i radius struct %f radius %f", index,
    REAL_Circle[index].radius, radius);
    printf("\n Last circle #%i center_x struct %f center_x %f", index,
    REAL_Circle[index].center_x, center_x);
    printf("\n Last circle #%i center_y struct %f center_y %f", index,
    REAL_Circle[index].center_y, center_y);

    }
    

    }

    Here is the output

    Last circle #5 radius struct 0.065789 radius 0.131579
    Last circle #5 center_x struct 0.000000 center_x 0.118421
    Last circle #5 center_y struct 0.000000 center_y 0.000000

    The questions are NOT what I am trying to accomplish with the code , the questions are: 1. why values printed FROM struct DO NOT match assigned values ? 2. why is "radius" TWICE of the value assigned from struct? PS Only

    radius struct 0.065789

    is of correct value. Cheers

    K L 2 Replies Last reply
    0
    • V Vaclav_

      Just FYI, this is NOT a repost. As usual I have posted the original in WRONG pew. However, I found another even weirder failure of simple math case and I really do not have a clue what I am doing wrong. Are my local variable assignments incorrect ? Is "printf" lying to me ? Here is the entire test code

      #define MAX_CIRCLES 5

      struct TAG_Circles {
      float radius;
      float center;
      float center_x;
      float center_y;

      } REAL_Circle[MAX_CIRCLES], IMG_Circle[MAX_CIRCLES];

      void OpenGL_Stencil_Circle_Build(void);
      // copy last circle to stencil
      void OpenGL_Stencil_Circle_Build(void) {
      //
      int index = 5;
      {
      // last circle
      float radius = IMG_circle[index].radius;
      float center_x = IMG_circle[index].center_x;
      float center_y = IMG_circle[index].center_y;
      printf("\n Last circle #%i radius struct %f radius %f", index,
      REAL_Circle[index].radius, radius);
      printf("\n Last circle #%i center_x struct %f center_x %f", index,
      REAL_Circle[index].center_x, center_x);
      printf("\n Last circle #%i center_y struct %f center_y %f", index,
      REAL_Circle[index].center_y, center_y);

      }
      

      }

      Here is the output

      Last circle #5 radius struct 0.065789 radius 0.131579
      Last circle #5 center_x struct 0.000000 center_x 0.118421
      Last circle #5 center_y struct 0.000000 center_y 0.000000

      The questions are NOT what I am trying to accomplish with the code , the questions are: 1. why values printed FROM struct DO NOT match assigned values ? 2. why is "radius" TWICE of the value assigned from struct? PS Only

      radius struct 0.065789

      is of correct value. Cheers

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      Could it be because you're assigning radius from **IMG**_circle but printing the value of **REAL**_circle?

      Keep Calm and Carry On

      V 1 Reply Last reply
      0
      • V Vaclav_

        Just FYI, this is NOT a repost. As usual I have posted the original in WRONG pew. However, I found another even weirder failure of simple math case and I really do not have a clue what I am doing wrong. Are my local variable assignments incorrect ? Is "printf" lying to me ? Here is the entire test code

        #define MAX_CIRCLES 5

        struct TAG_Circles {
        float radius;
        float center;
        float center_x;
        float center_y;

        } REAL_Circle[MAX_CIRCLES], IMG_Circle[MAX_CIRCLES];

        void OpenGL_Stencil_Circle_Build(void);
        // copy last circle to stencil
        void OpenGL_Stencil_Circle_Build(void) {
        //
        int index = 5;
        {
        // last circle
        float radius = IMG_circle[index].radius;
        float center_x = IMG_circle[index].center_x;
        float center_y = IMG_circle[index].center_y;
        printf("\n Last circle #%i radius struct %f radius %f", index,
        REAL_Circle[index].radius, radius);
        printf("\n Last circle #%i center_x struct %f center_x %f", index,
        REAL_Circle[index].center_x, center_x);
        printf("\n Last circle #%i center_y struct %f center_y %f", index,
        REAL_Circle[index].center_y, center_y);

        }
        

        }

        Here is the output

        Last circle #5 radius struct 0.065789 radius 0.131579
        Last circle #5 center_x struct 0.000000 center_x 0.118421
        Last circle #5 center_y struct 0.000000 center_y 0.000000

        The questions are NOT what I am trying to accomplish with the code , the questions are: 1. why values printed FROM struct DO NOT match assigned values ? 2. why is "radius" TWICE of the value assigned from struct? PS Only

        radius struct 0.065789

        is of correct value. Cheers

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Vaclav_ wrote:

        Here is the entire test code

        As usual it is not the entire code, since none of your struct entities have been initialised with values. Please provide the values of all the variables that you are using, explain what you are trying to calculate, and why you consider the results are wrong.

        1 Reply Last reply
        0
        • K k5054

          Could it be because you're assigning radius from **IMG**_circle but printing the value of **REAL**_circle?

          Keep Calm and Carry On

          V Offline
          V Offline
          Vaclav_
          wrote on last edited by
          #4

          I am not so sure how to answer this (honestly). Maybe I should get a different hobby - like basket weaving... For what it is worth I started with IMG and then realized it was wrong struct, but changed only part of the code !

          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