code:rprintf
This is an old revision of the document!
floating point print function
This is based on the origional rprintf by Pascal Stang. However numDigits now refers to digits after decimal point, and the is no '+' character printed for +ive numbers.
void rprintfFloat(char numDigits, double x) { unsigned char firstplace = FALSE; unsigned char i=255, digit; double place = 1000000000000000.0; if(x<0) { rprintfChar('-'); x=-x; //convert to absolute value } for(;i;i--) { digit=x/place; if(digit | firstplace) //digit>=1 { firstplace = TRUE; //we have reached the first rprintfChar(digit+0x30); if(place == 1.0) { rprintfChar('.'); //the decimal point i=numDigits; } } x-=digit*place; place/=10.0; } }
code/rprintf.1225746729.txt.gz · Last modified: 2008/11/03 21:12 by laurenceb