www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Runtime unit lib

reply BCS <BCS_member pathlink.com> writes:
I have put together a runtime unit type library. While I was writing the 
unittest I recognized that the most likely error is an error in the convention 
table (something that can't be checked by the person who wrote that part). 
Therefor, Would someone please (without looking at my table of conversion 
factors) finish writing the unittest for the lib?

It shouldn't be hard, just get the file and a units conversion table and add 
some more lines like those around line 644.

here it is:

http://www.webpages.uidaho.edu/~shro8822/unit_.d

ps:

I am submitting this for inclusion in Phobos.
Feb 21 2006
next sibling parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

BCS schrieb am 2006-02-22:
 I have put together a runtime unit type library. While I was writing the 
 unittest I recognized that the most likely error is an error in the convention 
 table (something that can't be checked by the person who wrote that part). 
 Therefor, Would someone please (without looking at my table of conversion 
 factors) finish writing the unittest for the lib?

 It shouldn't be hard, just get the file and a units conversion table and add 
 some more lines like those around line 644.

 here it is:

 http://www.webpages.uidaho.edu/~shro8822/unit_.d
Acre US or international ? Cal international table calorie, thermochemical calorie or ... ? Hp metric, us or ... horsepower? Leter -> Liter? mile, inch british, natic, imperial or ... ? R Rankine, Reaumur or ... ? Fahrenheit and lot's of metric units seem to be missing. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFD/Fgg3w+/yD4P9tIRAmcCAJ0cOnVal+PXaZcCag5MjU1b44Cn8wCguKDf qx9/Ra66opwQBsv3kNVs74s= =UwGB -----END PGP SIGNATURE-----
Feb 22 2006
parent reply BCS <BCS_member pathlink.com> writes:
In article <0q1uc3-rb3.ln1 birke.kuehne.cn>, Thomas Kuehne says...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

BCS schrieb am 2006-02-22:
 I have put together a runtime unit type library. While I was writing the 
 unittest I recognized that the most likely error is an error in the convention 
 table (something that can't be checked by the person who wrote that part). 
 Therefor, Would someone please (without looking at my table of conversion 
 factors) finish writing the unittest for the lib?

 It shouldn't be hard, just get the file and a units conversion table and add 
 some more lines like those around line 644.

 here it is:

 http://www.webpages.uidaho.edu/~shro8822/unit_.d
Acre US or international ? Cal international table calorie, thermochemical calorie or ... ? Hp metric, us or ... horsepower? Leter -> Liter?
oops
mile, inch
british, natic, imperial or ... ?
5280'
R
Rankine, Reaumur or ... ?
Rankine
Fahrenheit and lot's of metric units seem to be missing.
Fahrenheit has an offset so... I didn't put in units like PSI that are named by there definition. I put in all of the units that my table had that looked useful (who besides the GB DMV needs stones?) More units can be added later. non metric units are US (I think). ver 2 fothcoming, several things will change a bit.
Feb 22 2006
parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

BCS schrieb am 2006-02-22:
 In article <0q1uc3-rb3.ln1 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-----
Feb 22 2006
parent reply BCS <BCS_member pathlink.com> writes:
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 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-----
Feb 22 2006
parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

BCS schrieb am 2006-02-23:
 WOW!! Thanks! That is impressive. If I may ask, how did you make that? Some
sort 
 of script I assume?
No script, just one hundred and one monkeys typing all day ;)
 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?
How about 40K? Thomas begin 644 unittest_addon.zip M9%54"0`#Q7?]0\5W_4-5>`0`Z`-D`.U=;6_<-A+^;/\*-D!1&7%8ODI4TA1( M,"]F)7 *#A_ MNFSJA4:^GH[JA9;.]/\CO7VGM]/Y:*+V)XM%H_871:W3G$TKG6)[M>I8;7]> MS4>E4<]7C3Z:+%8Z:^/B0NW>J,V_RO>-N>#X8EZ:TT_4[OEB52UF.JE_R$.M M>E&?:E51J5WY5FW?+BJ=FU<?]%4G. N_%&K[4Z$O]ZS1LO\4C0&>J>W!U-KI MI4GL^4J+_SE?-$M]TDB:Z>A)9^FZ+"I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9",.R7DO9U`:1?2MKG!9!^$6G? M%T#Z):1]8`#I%]`5]0/[Y2-]8 #G%XWQC0'H6M$8'QG`^N6C?64`Z1>1\IF! M2LKG!H!^$4G?&\#Y!:1]<.!!XY>0],4!G%]$RB<' '[Y2-\<P/FEHWQT`.B7 MCO+5`:!?,MIG!Y!^P4C?'<#YY6)\>`#JE\S+8!%2OVB43P\\U_V2,;X]`/4+ MQ_CX`-0O'NWK+R%#SKYU]SL?1X5RG2_^')5GS70Q5['>Z^GRM9)VOM1X8GF9 MIEZ5- %[_O0DL3[]FQ]^?`H01-U94O6-.;-WRO^63]>Y;AD\V/UVF7R[W`./ MI/Q?758VI_O6;'N?SI8Z> Q.%XT\_D26]L%:ZL$L?NR;6VHC_S[N?MS]/U!+ M`0(7`Q0`` `(`(M.5S3SV:_7%PT``&V8```0``T```````$```#M 0````!U ` end -----BEGIN PGP SIGNATURE----- iD8DBQFD/Xmz3w+/yD4P9tIRAognAJ9htrCXzYmDCOjRygLkkMfF3WsJsgCgohwt uSKoGesdYlzAUbGXNBs0qO8= =6E2G -----END PGP SIGNATURE-----
Feb 23 2006
parent reply BCS <BCS_member pathlink.com> writes:
Thomas Kuehne wrote:
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 BCS schrieb am 2006-02-23:
 
WOW!! Thanks! That is impressive. If I may ask, how did you make that? Some
sort 
of script I assume?
No script, just one hundred and one monkeys typing all day ;)
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?
How about 40K? Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFD/Xmz3w+/yD4P9tIRAognAJ9htrCXzYmDCOjRygLkkMfF3WsJsgCgohwt uSKoGesdYlzAUbGXNBs0qO8= =6E2G -----END PGP SIGNATURE-----
Sweet!!! That's about what I was expecting. Thanks!! Two things (more curiosity than anything): -> How long did the first version take to compile for you? On my box (Linux 550MHz P-III) DMD ran for ~ 70 sec. -> What did you use for a convention table? I want to pout that in the doc comments. A fixed version (inch, cal and hp corrected) of the lib will be up in a few minutes.
Feb 23 2006
parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

BCS schrieb am 2006-02-23:

[snip]

 Two things (more curiosity than anything):
 -> How long did the first version take to compile for you? On my box (Linux 
 550MHz P-III) DMD ran for ~ 70 sec.
ca. 29 sec (with some backround activity)
 -> What did you use for a convention table? I want to put that in the doc
comments.
units version 1.80 the data file lists following sources: Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFD/haw3w+/yD4P9tIRAg9YAJ4sdDt8Sbdgn+UyR+fAGAMZzy3GxwCgqQSa 6j6MksKajqf4g4aUCf50T3E= =ydtA -----END PGP SIGNATURE-----
Feb 23 2006
parent reply BCS <BCS_member pathlink.com> writes:
In article <geh1d3-v56.ln1 birke.kuehne.cn>, Thomas Kuehne says...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

BCS schrieb am 2006-02-23:

[snip]

 Two things (more curiosity than anything):
 -> How long did the first version take to compile for you? On my box (Linux 
 550MHz P-III) DMD ran for ~ 70 sec.
ca. 29 sec (with some backround activity)
what kind of system?
 -> What did you use for a convention table? I want to put that in the doc
comments.
units version 1.80
Crumbs! That's where I got the _new_ valuse for the convertions from. Now I have to find a new scource.
the data file lists following sources:





























Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFD/haw3w+/yD4P9tIRAg9YAJ4sdDt8Sbdgn+UyR+fAGAMZzy3GxwCgqQSa
6j6MksKajqf4g4aUCf50T3E=
=ydtA
-----END PGP SIGNATURE-----
Feb 23 2006
parent reply BCS <BCS_member pathlink.com> writes:
A new version of the units lib is up at

http://www.webpages.uidaho.edu/~shro8822/unit.d

Several other libs are also up at:

http://www.webpages.uidaho.edu/~shro8822/point_math.d
http://www.webpages.uidaho.edu/~shro8822/point_lib.d

I would like to submit them all for inclusion in Phobos
Feb 24 2006
parent reply Sai <Sai_member pathlink.com> writes:
Great, I always wanted to write one! Actually I already have one but it is more
like an units interpreter. However, my library has an additional feature, it can
take fractional powers of dimensions in p/q form where p and q are integers.

I am interested in adding this feature to your library, its easy. This feature
is very useful for engineers, especially mechanical engineers where fractional
power of dimensions appear every where. eg. time period of a simple pendulum.

So, do you mind if I take a whack at it ?

One question, why you left out angle and candela from fundamental units ? later
one is used a lot in optics.

my units interpreter is at:
http://mechsys4.me.udel.edu/home/banala/units.html

its not very userfriendly as of yet, just ported it to D and DWT.

Sai

In article <dto5k2$10iq$1 digitaldaemon.com>, BCS says...
A new version of the units lib is up at

http://www.webpages.uidaho.edu/~shro8822/unit.d

Several other libs are also up at:

http://www.webpages.uidaho.edu/~shro8822/point_math.d
http://www.webpages.uidaho.edu/~shro8822/point_lib.d

I would like to submit them all for inclusion in Phobos
Feb 25 2006
parent BCS <BCS_member pathlink.com> writes:
In article <dtprks$1m30$1 digitaldaemon.com>, Sai says...
Great, I always wanted to write one! Actually I already have one but it is more
like an units interpreter. However, my library has an additional feature, it 
can take fractional powers of dimensions in p/q form where p and q are 
 integers.

I am interested in adding this feature to your library, its easy. This feature
is very useful for engineers, especially mechanical engineers where fractional
power of dimensions appear every where. eg. time period of a simple pendulum.
Go ahead, fine by me. I was thinking of adding integer powers my self. One request, I have tried to keep the unit control part as separable as possible so that it would be easy to strip out for performance reasons.
So, do you mind if I take a whack at it ?

One question, why you left out angle and candela from fundamental units ? later
one is used a lot in optics.
Each fundamental unit used adds a int to the struct and adds more overhead to programs using this library. While not quite as handy, angles can be treated as unit-less (IIRC SI does this) and the candela can be treated as power per area (CGS, US and MKS do this).
my units interpreter is at:
http://mechsys4.me.udel.edu/home/banala/units.html

its not very userfriendly as of yet, just ported it to D and DWT.

Sai
This whole lib is rely a bit of a kluge because most of the time units can be determined statically and should be checked statically. I have plans for a template to do this but it will require implicit template specialization, so that's on hold for now.
In article <dto5k2$10iq$1 digitaldaemon.com>, BCS says...
A new version of the units lib is up at

http://www.webpages.uidaho.edu/~shro8822/unit.d

Several other libs are also up at:

http://www.webpages.uidaho.edu/~shro8822/point_math.d
http://www.webpages.uidaho.edu/~shro8822/point_lib.d

I would like to submit them all for inclusion in Phobos
Feb 25 2006
prev sibling next sibling parent reply "Charles" <noone nowhere.com> writes:
This looks sweet.

Sorry for my ignorance but what does feqrel() do ?

Charlie


"BCS" <BCS_member pathlink.com> wrote in message
news:dtgd32$407$1 digitaldaemon.com...
 I have put together a runtime unit type library. While I was writing the
 unittest I recognized that the most likely error is an error in the
convention
 table (something that can't be checked by the person who wrote that part).
 Therefor, Would someone please (without looking at my table of conversion
 factors) finish writing the unittest for the lib?

 It shouldn't be hard, just get the file and a units conversion table and
add
 some more lines like those around line 644.

 here it is:

 http://www.webpages.uidaho.edu/~shro8822/unit_.d

 ps:

 I am submitting this for inclusion in Phobos.
Feb 22 2006
parent reply BCS <BCS_member pathlink.com> writes:
"to how many bit are the args the same?"  its in std.math

In article <dti61k$2gpd$1 digitaldaemon.com>, Charles says...
This looks sweet.

Sorry for my ignorance but what does feqrel() do ?

Charlie


"BCS" <BCS_member pathlink.com> wrote in message
news:dtgd32$407$1 digitaldaemon.com...
 I have put together a runtime unit type library. While I was writing the
 unittest I recognized that the most likely error is an error in the
convention
 table (something that can't be checked by the person who wrote that part).
 Therefor, Would someone please (without looking at my table of conversion
 factors) finish writing the unittest for the lib?

 It shouldn't be hard, just get the file and a units conversion table and
add
 some more lines like those around line 644.

 here it is:

 http://www.webpages.uidaho.edu/~shro8822/unit_.d

 ps:

 I am submitting this for inclusion in Phobos.
Feb 22 2006
parent reply Sai <Sai_member pathlink.com> writes:
http://www.gnu.org/software/units/units.html

Above tool seem to have a pretty good collection of units.

It would be nice if the 'runtime unit lib' in discussion can generate
arbitrary fundamental units and user defined conversions at runtime (like
currency, steradian, bit, music_note etc).

Sai
Feb 22 2006
parent BCS <BCS_member pathlink.com> writes:
Sai wrote:
 http://www.gnu.org/software/units/units.html
 
 Above tool seem to have a pretty good collection of units.
 
 It would be nice if the 'runtime unit lib' in discussion can generate
 arbitrary fundamental units and user defined conversions at runtime (like
 currency, steradian, bit, music_note etc).
 
 Sai
 
 
 
I'll check that out
Feb 22 2006
prev sibling parent reply Chris Lajoie <ctlajoie___remove___this___ ___gmail.com> writes:
BCS wrote:
 I have put together a runtime unit type library. While I was writing the 
 unittest I recognized that the most likely error is an error in the 
 convention table (something that can't be checked by the person who 
 wrote that part). Therefor, Would someone please (without looking at my 
 table of conversion factors) finish writing the unittest for the lib?
 
 It shouldn't be hard, just get the file and a units conversion table and 
 add some more lines like those around line 644.
 
 here it is:
 
 http://www.webpages.uidaho.edu/~shro8822/unit_.d
 
While I'm sure your units code will be great as part of phobos, I'm actually more interested (surprised rather) in where your file is hosted. I believe we go to school in the same state. :) I'm in the middle of my second year at Boise State University. Chris
Feb 24 2006
parent BCS <BCS_member pathlink.com> writes:
Chris Lajoie wrote:
 BCS wrote:
 
 http://www.webpages.uidaho.edu/~shro8822/unit_.d
While I'm sure your units code will be great as part of phobos, I'm actually more interested (surprised rather) in where your file is hosted. I believe we go to school in the same state. :) I'm in the middle of my second year at Boise State University. Chris
I found a while ago that one of the contributers to another (internet wide) project I'm ocationaly involved in works right here in town. "It's a small world after all ..."
Feb 27 2006