prinft implementation for %f
prinft implementation for %f
Anyone implemented %f (float) for printf??
-
Thomas
-
Thomas
Last edited by mutex on Sat Jul 14, 2007 5:05 am, edited 1 time in total.
- AndrewAPrice
- Member
- Posts: 2309
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Print it as an integer, the add a '.' then subtract the integer from the float, and multiply the float until all digits are left of the decimal point, and print that as an integer. It's easier with C++ since you can just add an "operator<<(float data)" to your console class.thomasnilsen wrote:Anyway... Im interessted in decimal numbers from fpu and how you show them with printf..
-
Thomas
My OS is Perception.
I think this is more of what they were saying. Note print is just a function that will take a integer and print it.
Something like that should work.
Code: Select all
void Print_Float( float value )
{
// print the integral part
print( (int)value );
// now get rid of the integral part
value -= ((int)value);
// print the decimal point
printchar( '.' );
// now the decimal part, make sure everything is to the left
// of the decimal point.
// NOTE: You may want to make a cut off after so many tries since this
// would lock up on numbers like 1/3
while( value != (int)value )
{
value *= 10;
} // end while
// now print it
print( (int)value );
} // end Print_Float
Its not from my kernel but check this from Tornado OS
http://www.koders.com/info.aspx?c=Proje ... PT8XHKR43D
check ftoa() & sprintf() :
http://www.koders.com/c/fid9E7E7B85C9A3 ... FBAA8.aspx
http://www.koders.com/c/fid88201E3F09A1 ... D2F85.aspx
http://www.koders.com/info.aspx?c=Proje ... PT8XHKR43D
check ftoa() & sprintf() :
http://www.koders.com/c/fid9E7E7B85C9A3 ... FBAA8.aspx
http://www.koders.com/c/fid88201E3F09A1 ... D2F85.aspx
Systems and Computer Engineering Researcher
"Do you pine for the nice days of Minix-1.1, when men were men and wrote their own device drivers?" -- Linus Torvalds
http://sce.carleton.ca/~maslan
"Do you pine for the nice days of Minix-1.1, when men were men and wrote their own device drivers?" -- Linus Torvalds
http://sce.carleton.ca/~maslan