Re: weird problem

From: Kurt Van Samang (dreamchaser1981_at_NOSPAM.hotmail.com)
Date: 03/07/04

  • Next message: David Lowndes: "Re: weird problem"
    Date: Sun, 07 Mar 2004 21:10:16 GMT
    
    

    "Micus" <None@nowhere.com> schreef in bericht
    news:ezmp1JIBEHA.3400@tk2msftngp13.phx.gbl...
    >
    > "Kurt Van Samang" <dreamchaser1981@NOSPAM.hotmail.com> wrote in message
    > news:zuK2c.26390$EZ6.2053146@phobos.telenet-ops.be...
    > > yes there is, that's probably the problem, but how to solve it? Just
    > adding
    > > 1 of course isn't good enough, cause that will also affect the other
    > results
    > > of the function, which are most of the time correct
    > >
    > > int CSegment::GetPhase(int pixelnr)
    > > {
    > > float f=((float)pixelnr)/((float)length);
    > > return
    (int)((1-f)*vertices[0]->GetPhase()+f*vertices[1]->GetPhase());
    >
    > would this or something similar work?
    >
    > return (int)(((1.0-f) * float(vertices[0]->GetPhase()) +
    > f * float(vertices[1]->GetPhase())) +
    > .5);
    > HTH,
    > M
    >
    > > }
    > >
    > > and the call is:
    > > int phase=current->GetPhase(pos);
    > >
    > > So actually I interpolate the phases (which are ints) of the vertices
    > > according to the number of the pixel
    > >
    > > some values in my debugger:
    > >
    > > ->right before the function call
    > > pos =33
    > >
    > > ->in the GetPhase function:
    > > pixelnr =33
    > > f =0.351064
    > > vertices[0]->GetPhase() =7
    > > vertices[1]->GetPhase() =101
    > > (1-f)*vertices[0]->GetPhase()+f*vertices[1]->GetPhase() =40.0000
    > > (int)((1-f)*vertices[0]->GetPhase()+f*vertices[1]->GetPhase()) =40
    > >
    > > ->right after to the function call
    > > phase =39
    > >
    > > the correct value should be 40. This is the value I expect and I also
    get
    > 40
    > > when I calculate it on a calculator
    > >
    > >
    > > "David Lowndes" <davidl@example.invalid> schreef in bericht
    > > news:u2sm40tqn9s5b7shesqkrhp9gspnetfojk@4ax.com...
    > > > >I've got a weird problem
    > > > >
    > > > >I initiate an integer with the result of a function. When I debug, I
    > see
    > > > >that the value is correctly calculated in this function, the result
    is
    > > 40.
    > > > >But the integer gets the value 39 instead of 40.
    > > > >
    > > > >int phase=current->GetPhase(...);
    > > > >
    > > > >How is this possible?
    > > >
    > > > What's the definition/code for GetPhase?
    > > >
    > > > Is there a floating point value/calculation involved anywhere?
    > > >
    > > > Dave
    > > > --
    > > > MVP VC++ FAQ: http://www.mvps.org/vcfaq
    > >
    > >
    >
    >

    that didn't help but i solved the problem. Appearantly the value was rounded
    off to 39.9995 or something, so the debugger displayed 40 but in reality it
    was rounded off to 39 when casted to int. Solved this by adding a small
    value. Thx for your reply


  • Next message: David Lowndes: "Re: weird problem"

    Relevant Pages