code:rprintf
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
code:rprintf [2008/11/03 20:18] – created laurenceb | code:rprintf [2008/11/06 01:59] (current) – laurenceb | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== floating point print function ====== | ====== floating point print function ====== | ||
- | This is based on the origional rprintf by Pascal Stang. | + | This is based on the origional rprintf by Pascal Stang. |
- | <code c> | + | <code c>void rprintfFloat(char numDigits, double x) |
- | void rprintfFloat(char numDigits, double x) | + | |
{ | { | ||
unsigned char firstplace = FALSE; | unsigned char firstplace = FALSE; | ||
- | unsigned char negative; | + | unsigned char i=25, digit; |
- | unsigned char i=255, digit; | + | double place = 1000000000000000.0; |
- | double place = 1.0; | + | |
- | + | if(x<0) | |
- | // save sign | + | |
- | negative = (x<0); | + | |
- | // convert to absolute value | + | |
- | x = (x> | + | |
- | + | ||
- | // find starting digit place | + | |
- | for(i=0; i<15; i++) | + | |
{ | { | ||
- | if((x/place) < 10.0) | + | rprintfChar(' |
- | break; | + | x=-x; // |
- | else | + | |
- | place *= 10.0; | + | |
} | } | ||
- | // print polarity character | ||
- | if(negative) | ||
- | rprintfChar(' | ||
- | //else | ||
- | // | ||
- | |||
- | // print digits | ||
for(; | for(; | ||
{ | { | ||
- | digit = (x/place); | + | digit=x/ |
- | + | if(digit | firstplace) // | |
- | if(digit | firstplace | + | |
{ | { | ||
- | firstplace = TRUE; | + | firstplace = TRUE; //we have reached the first digit |
rprintfChar(digit+0x30); | rprintfChar(digit+0x30); | ||
} | } | ||
- | else | ||
- | rprintfChar(' | ||
- | |||
if(place == 1.0) | if(place == 1.0) | ||
{ | { | ||
- | rprintfChar(' | + | if(!firstplace) |
- | i=numDigits; | + | rprintfChar(' |
+ | rprintfChar(' | ||
+ | firstplace = TRUE; //we have to print after the decimal place | ||
+ | i=numDigits+1; | ||
} | } | ||
- | + | x-=digit*place; | |
- | x -= (digit*place); | + | place/ |
- | place /= 10.0; | + | |
} | } | ||
- | } | + | }</ |
- | </ | + |
code/rprintf.1225743515.txt.gz · Last modified: 2008/11/03 20:18 by laurenceb