UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


code:rprintf

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
code:rprintf [2008/11/03 20:18] laurencebcode:rprintf [2008/11/06 01:59] (current) laurenceb
Line 4: Line 4:
  
  
-<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>0)?(x):(-x); +
-  +
- // find starting digit place +
- for(i=0; i<15; i++)+
  {  {
- if((x/place< 10.0) + rprintfChar('-'); 
- break+ x=-x; //convert to absolute value
- else +
- place *10.0;+
  }  }
- // print polarity character 
- if(negative) 
- rprintfChar('-'); 
- //else 
- // rprintfChar('+'); 
- 
- // print digits 
  for(;i;i--)  for(;i;i--)
  {  {
- digit = (x/place); + digit=x/place; 
- + if(digit | firstplace) //digit>=1
- if(digit | firstplace | (place == 1.0))+
  {  {
- 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('0'); //always zero before the decimal point 
 + rprintfChar('.'); //the decimal point 
 + firstplace = TRUE; //we have to print after the decimal place 
 + i=numDigits+1;
  }  }
-  + x-=digit*place; 
- x -= (digit*place)+ place/=10.0;
- place /= 10.0;+
  }  }
-} +}</code>
-</code>+
code/rprintf.1225743533.txt.gz · Last modified: 2008/11/03 20:18 by laurenceb

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki