Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: init problem

  1. #1
    Intern Contributor
    Join Date
    Mar 2003
    Location
    Slovakia
    Posts
    78

    init problem

    i have a problem with initialization i have a array of points[9][2] i'm doing initialization on the x axis like this
    for(i=0;i<10;i++)
    for(j=0;j<=2;j++)
    point[i][j].x=-1+((2/3)*j);
    the results are:
    for j=0 point[i][0].x=-1 correct
    for j=1 point[i][1].x=-1 not correct !!!
    for j=2 point[i][2].x=-0.333333 again not correct except for point[9][2].x which is correct (0.33333) where is the problem ?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: init problem

    Use 2.0/3.0 instead of 2/3. Without '.0', you get integer division.

  3. #3
    Intern Contributor
    Join Date
    Mar 2003
    Location
    Slovakia
    Posts
    78

    Re: init problem

    Done that but still it isn't working

  4. #4
    Intern Contributor
    Join Date
    Mar 2003
    Location
    Slovakia
    Posts
    78

    Re: init problem

    ok i have done some debugging and it seems that the problem is only with the last row (i mean point[i][2]) which is -1.0f when it should be 0.03333f

    for(i=0to9)
    for(j=0to2)
    {
    point[i][j].x=.....
    *
    }
    ~

    when i added printf at * point everything was OK but at ~ point it has shown incorrect values(-1 it should be 0.33333) except for that point[9][2] which is ok can someone help me with that

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2002
    Location
    Columbus, OH
    Posts
    2

    Re: init problem

    When I run the following code, it gives the correct results. You should check your code for typing mistakes. For example, I have a tendency to swap i's and j's.

    struct Point
    {
    double x, y;
    };

    Point point[10][3];
    int i, j;
    // init
    for(i=0;i<10;i++)
    {
    for(j=0;j<=2;j++)
    point[i][j].x=-1+((2.0/3.0)*j);
    }
    // print
    for(i=0;i<10;i++)
    {
    for(j=0;j<=2;j++)
    printf("point[%d][%d].x=%f\n", i, j,
    point[i][j].x);
    }

  6. #6

    Re: init problem

    for (j=0;j<2;j++)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •