This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

about float operation


#include "absacc.h"
#include "math.h"
#include <intrins.h>
#include <reg51.h>
#include "stdio.h"
//-------------------------------------------------------------------------------

//&#21010;&#32447;&#20989;&#25968;
void Line( unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, bit Mode)
{unsigned char x,y;
double k,b;
unsigned i;

if( 1) // |k|<=1
{k=(float)(y2-y1) / (float)(x2-x1) ;
b=y1-k*x1;
if( x1 <= x2 )
{for(x=x1;x<=x2;x++)
{i=i+2.7;
}
}

}
}

void main()
{unsigned i;

Line(0,0,23,34,1);
P1=34;
jj:goto jj;
}

This programme can run well in Keil UV2 ,but can't run along in my target board.
But I revised the state i=i+2.7; to i=i+2;,and the programme can run well.
why?

  • You seem to have managed to use the HTML tags for bold and italic, so why not the 'pre' tag for your code - like it said in the instructions?!

    "But I revised the state i=i+2.7; to i=i+2;"

    Your i is an integer - why were you incrementing it by 2.7?!
    What were you expecting to happen?