Runtime unit lib

BCS BCS_member at pathlink.com
Wed Feb 22 17:04:33 PST 2006


WOW!! Thanks! That is impressive. If I may ask, how did you make that? Some sort 
of script I assume? I ask because the Phobos source en-total is 1MB and 647k is 
kinda large. Can you think of any way to cut down the code size using a data 
table of some kind?

e.g.

enum Types {Foot, Inch, Pound, ...)

real[Types.max][Types.max] test_values;

test_values[Types.Foot][Types.Foot] = 1;	// real value is convrtion
test_values[Types.Foot][Types.Inch] = 12;
test_values[Types.Foot][Types.Pound] = real.nan; //nan on no convertion
...


Unit u;
real v;
foreach(int from, real[] ra; test_values)
foreach(int to, real r; test_values)
{
	switch(from)
	{
		case Type.Foot: u = Foot(1);	break;
		case Type.Inch: u = Inch(1);	break;
		case Type.Pound: u = Pound(1);	break;
...
	}

	try
	switch(from)
	{
		case Type.Foot: v = u.Foot();	break;
		case Type.Inch: v = u.Inch();	break;
		case Type.Pound: v =u.Pound();	break;
...
	}
	catch (ExceptionUnitMisMatch)
	{
		assert(isnan(r));
		continue;
	}
	assert(!isnan(r));
}




Thomas Kuehne wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> BCS schrieb am 2006-02-22:
> 
>>In article <0q1uc3-rb3.ln1 at birke.kuehne.cn>, Thomas Kuehne says...
> 
> 
> [snip]
> 
> 
>>>mile, inch
>>>british, natic, imperial or ... ?
>>
>>5280'
> 
> 
> [snip]
> 
> 
>>non metric units are US (I think).
> 
> 
> Except for inch, all conversions seem to be correct.
> 
> Could you please send me your email - the basic 
> conversion unittest is rather large for posting (ca. 647K).
> 
> Thomas
> 
> 
> -----BEGIN PGP SIGNATURE-----
> 
> iD8DBQFD/NoA3w+/yD4P9tIRAgr+AKCEHKUcwpu+m2FvmOQlWJowjYMCgwCfZQR8
> IFJFE9kXLfgLQSWrHSvOdrI=
> =kJBv
> -----END PGP SIGNATURE-----



More information about the Digitalmars-d mailing list