digitalmars.D - Boost.units ported to D
- Arlen (36/36) Feb 11 2013 Greetings,
- David (1/6) Feb 11 2013 You could make: to!unit(12) possible (to from std.conv)
- bearophile (25/27) Feb 11 2013 It seems a lot of work.
- FG (3/5) Feb 11 2013 Nah, it's quite digestible after replacing "Quantity" with "Q".
- Michael (1/3) Feb 11 2013
- Arlen (16/20) Feb 11 2013 Yes because typeof(2.0 * si.newton) is Quantity!(si.Force) and typeof(fo...
- develop32 (2/2) Feb 11 2013 How about something like meters!15 or newtons!30? For me it is
- Arlen (7/9) Feb 11 2013 'meters!15' is supposed to be '15 * meters', right? Then how would you
- develop32 (5/14) Feb 11 2013 Oh, somehow that skipped my mind.
- Era Scarecrow (8/18) Feb 11 2013 It does if you have a universal base you are working from. Like
- Dicebot (2/7) Feb 11 2013 What is the problem with "15 / meters!1" ?
Greetings, source: https://github.com/Arlen/phobos/blob/std_units/std/units.d docs: http://arlen.github.com/phobos/std_units.html you will also need the rational module, source: https://github.com/Arlen/phobos/blob/std_rational/std/rational.d docs: http://arlen.github.com/phobos/std_rational.html There is still some work to be done, so I'm calling it an alpha release. I don't know if it belongs in Phobos or not, but I hope others will find it useful as I have. External Issues: 1. Many of the definitions of the systems have been commented out (starting line 3217) because during compilation DMD runs out of memory. As it is, on my system DMD consume nearly 2GB of ram. As a side note, the definitions should be in their own separate modules, but for now they are placed in structs. 2. Very long and not so helpful error messages. When I say long I'm talking hundreds and sometimes thousands of lines of error messages produced by DMD. Bugs in D: If you grep for "D_BUG_" you will find several potential bugs that I've marked. I would appreciate it if someone could take a look. FIXMEs: There are a number of FIXMEs, and at the moment I don't have the best solution for them. You will find them if you grep for "FIXME_", with FIXME_6 being the most important one. And then there are the potential bugs in Boost.units, which you will find in the very last part of the units.d module. I have posted several of them on stackoverflow. I have also emailed the original authors and waiting to affect Quantity. I'm considering removing Absolute altogether. And finally, there is the function convert (line 3666). It needs some cleanup, but this is the function used to explicitly convert from a quantity to another. I haven't decided on the actual syntax yet, but in Boost.units casting is used (e.g., quantity<cgs::length> L1 = static_cast<quantity<cgs::length> >(L2)). Any ideas? Arlen
Feb 11 2013
And finally, there is the function convert (line 3666). It needs some cleanup, but this is the function used to explicitly convert from a quantity to another. I haven't decided on the actual syntax yet, but in Boost.units casting is used (e.g., quantity<cgs::length> L1 = static_cast<quantity<cgs::length> >(L2)). Any ideas?You could make: to!unit(12) possible (to from std.conv)
Feb 11 2013
Arlen:https://github.com/Arlen/phobos/blob/std_units/std/units.d docs: http://arlen.github.com/phobos/std_units.htmlIt seems a lot of work. But code like this is not encouraging: Quantity!(si.Energy) work(Quantity!(si.Force) F, Quantity!(si.Length) dx) { return F * dx; } void main() { Quantity!(si.Force) F = 2.0 * si.newton; Quantity!(si.Length) dx = 2.0 * si.meter; Quantity!(si.Energy) E = work(F, dx); writefln("F = %s\ndx = %s\nE = %s\n", F, dx, E); alias Complex!double ComplexType; Quantity!(si.ElectricPotential, ComplexType) v = complex(12.5, 0) * si.volts; Quantity!(si.Current, ComplexType) i = complex(3, 4) * si.amperes; Quantity!(si.Resistance, ComplexType) z = complex(1.5, -2) * si.ohms; I think units are something that needs a good syntax to have a chance to be used :-( Bye, bearophile
Feb 11 2013
On 2013-02-11 20:08, bearophile wrote:It seems a lot of work. But code like this is not encouragingNah, it's quite digestible after replacing "Quantity" with "Q". But would anyone doing numerical processing ever use typed units?
Feb 11 2013
It is possible write something like?auto force = 2.0 * SI.Newton; auto energy = force * 2.0 * SI.Meter;
Feb 11 2013
On Mon, Feb 11, 2013 at 1:19 PM, Michael <pr m1xa.com> wrote:It is possible write something like? auto force = 2.0 * SI.Newton;Yes because typeof(2.0 * si.newton) is Quantity!(si.Force) and typeof(force * 2.0 * si.meter) is Quantity!(si.Energy). In the future when the unit systems are placed in their own modules, you could alias away and say: auto force = 2.0 * newton; auto energy = force * 2.0 * meters; Also note, 'newton' and 'meter' are instances of Unit. You could define your own and give whatever name you like. For example: si.Length myMeter; auto x = 3.0 * myMeter; writeln(x); // prints '3 m' In std.units I had to make the instances manifest constants (using instanceOf mixin) because they are in structs. That will probably change in the future if each system is placed in its own module. In that case std.unit will have to become a package, and I'm not sure if packages are allowed in Phobos. Anyone know?auto energy = force * 2.0 * SI.Meter;
Feb 11 2013
How about something like meters!15 or newtons!30? For me it is more pleasing and shorter than multiplication.
Feb 11 2013
On Mon, Feb 11, 2013 at 4:18 PM, develop32 <develop32 gmail.com> wrote:How about something like meters!15 or newtons!30? For me it is more pleasing and shorter than multiplication.'meters!15' is supposed to be '15 * meters', right? Then how would you express '15 / meters' ? You cannot; therefore, 'meters!15' doesn't make sense. 15 * meters, has an outupt '15 m' which is short for '15 m^1'. The exponent is not shown when it's 1. 15 / meters, has an output '15 m^-1'
Feb 11 2013
On Monday, 11 February 2013 at 22:33:02 UTC, Arlen wrote:'meters!15' is supposed to be '15 * meters', right? Then how would you express '15 / meters' ? You cannot; therefore, 'meters!15' doesn't make sense. 15 * meters, has an outupt '15 m' which is short for '15 m^1'. The exponent is not shown when it's 1. 15 / meters, has an output '15 m^-1'Oh, somehow that skipped my mind. But 15 / meters could be meters!(15, -1). It suits me more as it stands out of the whole expression and I would less likely make a mistake while writing it.
Feb 11 2013
On Monday, 11 February 2013 at 22:33:02 UTC, Arlen wrote:On Mon, Feb 11, 2013 at 4:18 PM, develop32 <develop32 gmail.com> wrote:It does if you have a universal base you are working from. Like converting currency you convert most likely from the one currency to an intermediate, then the intermediate to your desired currency, that way you only have 2 steps and a small table vs making the ratios for every possible type. So if 1 meter suddenly is say 100,000, then 15 * meter and meters!15 / meter (or feet!100 / meters) makes perfect sense!How about something like meters!15 or newtons!30? For me it is more pleasing and shorter than multiplication.'meters!15' is supposed to be '15 * meters', right? Then how would you express '15 / meters' ? You cannot; therefore, 'meters!15' doesn't make sense.15 * meters, has an output '15 m' which is short for '15 m^1'. The exponent is not shown when it's 1. 15 / meters, has an output '15 m^-1'
Feb 11 2013
On Monday, 11 February 2013 at 22:33:02 UTC, Arlen wrote:'meters!15' is supposed to be '15 * meters', right? Then how would you express '15 / meters' ? You cannot; therefore, 'meters!15' doesn't make sense.What is the problem with "15 / meters!1" ?
Feb 11 2013