|
|
View previous topic :: View next topic |
Author |
Message |
rblue Guest
|
negative floating values |
Posted: Wed Apr 04, 2007 12:20 pm |
|
|
hi every one
i have a problem in displaying negative float values...
i am using a Graphic LCD with 160x128 pixels and t6963 controller.
i am displaying a graph with it is a cursor which displays both the values of x and y axis
y axis is no problem as it is a long int and all positive values
x- axis has to be scalled and the resultant values are float
so here is my code...
Code: |
if( !SW3 )
{
x=x-1;// to move cursor left
remove_cursor(x+1,y);// remove old cousor .. i have a routine
cursor(x,y);// place cursor in new position
sprintf( array, "%3.2f",(x-19)/4.0 );//the x-axis value is scalled and string made
glcd_text35( 110,9 , array, 1 );// display the vale at my described location
}
|
now the problem is when value of x falls bellow 19 it should display a negative value instead it is displaying a positive value
that is
63.74 it should show -0.74
63.49 it should show -0.49
63.24 it should show -0.24
any suggestions or help from an expert i want to display negative values |
|
|
Ttelmah Guest
|
|
Posted: Wed Apr 04, 2007 12:44 pm |
|
|
'x' is presumably declared as an integer. Hence it is by default 'unsigned'. The arithmetic (x-19), is performed in integer (since both values are integers). Hence it wraps, giving a positive number 256 greater than the right value. You can correct this a whole number of ways:
(x-19.0) will force this arithmetic to use a 'float' type.
((signed)x-19) will convert x to a signed type, and use signed arithmetic.
((float)x-19) will convert x to a float then perform the arithmetic.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|