Re: Ghost, here's a softball for ya.



In sci.physics, Jeff?Relf
<Jeff_Relf@xxxxxxxxx>
wrote
on 7 Jun 2007 15:40:24 GMT
<Jeff_Relf_2007_Jun_7__8_40_AW@xxxxxxxxx>:
Here's a softball for ya Ghost...

#include <StdIO.H>
typedef wchar_t * LnP ;
#define Str swprintf

#define LoopTil( StopCond ) Ch = 1, P -- ; \
while ( \
Ch \
&& ! ( Ch = * ++ P, Ch2 = ! Ch ? 0 : P [ 1 ], StopCond ) )

// Shows the first three significant figures
// with or without a comma and/or a dot.
// Removes extraneous zeros on the left or right.
LnP Prn( float X ) { static int I ; static wchar_t B_[ 9 ][ 20 ];
LnP B = B_[ I ++ , I %= 9 ];
Str( B, L"%.3f", X ); if ( * B == '0' ) B ++ ;
LnP P = B ; wchar_t Ch, Ch2 ; int FromLeft = 0, Found_Dot = 0 ;
LoopTil( FromLeft >= 3 && Found_Dot ) {
int Dot = Ch == '.' ; Found_Dot |= Dot ;
if ( ! Dot ) FromLeft ++ ; }

main() { LnP P ; // Single Step in Debugger to see results.
P = Prn( 0 ); // . <-- I prefer this over " 0 ".
P = Prn( .0055 ); // .006 ideally, this'd print " 5.5 milli "
P = Prn( 1.1 ); // 1.1
P = Prn( 10 ); // 10
P = Prn( 21.1 ); // 21.1
P = Prn( 3000 ); // 3,000 ideally, this'd print " 3 kilo "
P = Prn( 4000.6789 ); // 4,000 ideally, this'd print " 4 kilo "
}

Prn() is used to produce reports like
X's list of the " Richest/Poorest Players ", to wit:
" www.Cotse.NET/users/jeffrelf/Phy_R.TXT ".

Speaking of which, I recently changed the scoring to:
" Virtual_Cash / Post / Day " instead of " Virtual_Cash / Post ".

When scoring, multiple crossposts count as multiple posts
and the Age of a player's set of posts is never less than 1.

Some of X's QuickSorts compare multiple floating point fields, to wit:
" float Cmp() " in " www.Cotse.NET/users/jeffrelf/X.CPP ".


Bleah. What is this crap? If you're trying to print a number existing
stuff is just fine (fprintf() or sprintf()):

#include <stdio.h>
void printnum(double v)
{
if(v < 0) { v = -v; putchar('-'); }
if(v > 1e9) { printf("%.5f G", v / 1e9); }
else if(v > 1000000) { printf("%.5f M", v / 1e6); }
else if(v > 1000) { printf("%.5f k", v / 1e3); }
else { printf ("%.5f", v); }
}

This isn't quite right but works as a first approximation.

Or one can get fancier and attempt to calculate log(v)/log(10),
which gives the approximate exponent.

--
#191, ewill3@xxxxxxxxxxxxx
Windows Vista. Because it's time to refresh your hardware. Trust us.

--
Posted via a free Usenet account from http://www.teranews.com

.


Quantcast