Changeset 458
- Timestamp:
- 10/20/08 20:31:21 (4 years ago)
- Files:
-
- trunk/units/constants.d (modified) (4 diffs)
- trunk/units/rational.d (modified) (3 diffs)
- trunk/units/si.d (modified) (5 diffs)
- trunk/units/types.d (modified) (1 diff)
- trunk/units/unit.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/units/constants.d
r447 r458 14 14 static const Types.Value gamma = { value : 0.577215664901532 }; 15 15 /// good old pi 16 static const Types.Value pi = { value : 3.14159265359};16 static const Types.Value pi = { value : 3.14159265359}; 17 17 /// natural log base 18 static const Types.Value e = { value : 2.718281828459 };18 static const Types.Value e = { value : 2.718281828459 }; 19 19 /// golden ratio 20 static const Types.Value phi = { value : 1.6180339887498948482045868 };20 static const Types.Value phi = { value : 1.6180339887498948482045868 }; 21 21 } 22 22 … … 25 25 { 26 26 /// unified atomic mass 27 static const Types.Mass u= { value : 1.66053873e-27 };27 static const Types.Mass u = { value : 1.66053873e-27 }; 28 28 /// electron mass 29 static const Types.Mass me = { value : 9.109373815276e-31 };29 static const Types.Mass me = { value : 9.109373815276e-31 }; 30 30 /// electron charge 31 static const Types.Charge e = { value : 1.602176462e-16 };31 static const Types.Charge e = { value : 1.602176462e-16 }; 32 32 /// Proton mass 33 static const Types.Mass mp = { value : 1.67262158e-27 };33 static const Types.Mass mp = { value : 1.67262158e-27 }; 34 34 /// Neutron mass 35 static const Types.Mass mn = { value : 1.67492716e-27 };35 static const Types.Mass mn = { value : 1.67492716e-27 }; 36 36 37 37 } … … 40 40 struct Physical 41 41 { 42 /// standard gravity 43 static const Types.Acceleration g = { value : 9.81 }; 42 44 /// Boltzmann constant 43 static const Lit!(2,1,-2,-1,0) k = { value : 1.3806503e-23 };45 static const Lit!(2,1,-2,-1,0) k = { value : 1.3806503e-23 }; 44 46 /// electric field constant / permittivity of free space 45 static const Lit!(-3,-1,4,0,2) e = { value : 8.854187817e-12};47 static const Lit!(-3,-1,4,0,2) e = { value : 8.854187817e-12}; 46 48 /// Gravitational Constant 47 static const Lit!(3,-1,-2,0,0) G = { value : 6.67259 };49 static const Lit!(3,-1,-2,0,0) G = { value : 6.67259 }; 48 50 /// Impedance of free space 49 static const Lit!(2,1,-3,0,-2) Z = { value : 376.731};51 static const Lit!(2,1,-3,0,-2) Z = { value : 376.731}; 50 52 /// speed of light 51 static const Types.Speed c= { value : 2.99792458e8 };53 static const Types.Speed c = { value : 2.99792458e8 }; 52 54 /// magnetic field constant / Permeability of a vacuum 53 static const Lit!(1,1,-2,0,-1) mu = { value : 1.2566370614 };55 static const Lit!(1,1,-2,0,-1) mu = { value : 1.2566370614 }; 54 56 /// Planck constant 55 static const Lit!(2,1,-1,0,0) h= { value : 6.62606876e-34 };57 static const Lit!(2,1,-1,0,0) h = { value : 6.62606876e-34 }; 56 58 /// Stefan-Boltzmann constant 57 59 static const Lit!(4,-3,1,-4,0) sigma = { value : 5.670400e-8 }; 58 59 60 } 60 61 … … 65 66 static const Types.Distance AU = { value :149.59787e11 }; 66 67 } 68 69 /// 70 struct Chemistry 71 { 72 /// 73 static const Types.MassDensity rhoH2O = { value : 1000 }; 74 /// 75 static const Types.Viscosity muH2O = { value : 0.89e-3 }; 76 77 } trunk/units/rational.d
r447 r458 3 3 template Tpl(T...){alias T Tpl;} 4 4 5 /// 5 6 uint gcd(int n, uint d) 6 7 { … … 16 17 static assert(7 == gcd(14,21)); 17 18 19 /// 18 20 template Reduce(int n, uint d) 19 21 { … … 37 39 static assert(!Reduce!(-14,21).Reduced); 38 40 static assert( Reduce!(-16,21).Reduced); 39 40 //pragma(msg, Reduce!(-14,21).N.stringof~"/"~Reduce!(-14,21).D.stringof);trunk/units/si.d
r447 r458 61 61 /// The set of unit defs 62 62 alias Tpl!( 63 `"value", 1.0, 0,0,0,0,0`, 63 64 `"meter", 1.0, 1,0,0,0,0`, 64 65 `"kilogram", 1.0, 0,1,0,0,0`, … … 80 81 81 82 /// Mass Unit Types 82 `"gram", 1e-3, 0,1,0,0,0`,83 `"lb", 4.5359 e-1,0,1,0,0,0`,84 `"Ounce", 2.83495 e-2, 0,1,0,0,0`,83 `"gram", 1e-3, 0,1,0,0,0`, 84 `"lb", 4.5359237e-1,0,1,0,0,0`, 85 `"Ounce", 2.834952e-2, 0,1,0,0,0`, 85 86 86 87 /// Time Unit Types … … 112 113 `"Joule", 1.0, 2,1,-2,0,0`, 113 114 `"Erg", 1e-7L, 2,1,-2,0,0`, 114 `" Cal", 4.1868L, 2,1,-2,0,0`,115 `"cal", 4.1868L, 2,1,-2,0,0`, 115 116 `"eV", 1.602176462e-19L, 2,1,-2,0,0`, 116 117 … … 125 126 126 127 /// Pressure Unit Types 127 `"Pa", 1.0, -1,1,-2,0,0`,128 `"Bar", 1e5L, -1,1,-2,0,0`,129 `"Atm", 1.01325e5L, -1,1,-2,0,0`,130 `"psi", 6.89 5e3,-1,1,-2,0,0`,128 `"Pa", 1.0, -1,1,-2,0,0`, 129 `"Bar", 1e5L, -1,1,-2,0,0`, 130 `"Atm", 1.01325e5L, -1,1,-2,0,0`, 131 `"psi", 6.89475729e3,-1,1,-2,0,0`, 131 132 132 133 /// Viscosity … … 138 139 /// Power Unit Types 139 140 `"Watt", 1.0, 2,1,-3,0,0`, 140 `"Hp", 745.69987 L,2,1,-3,0,0`,141 `"Hp", 745.69987158L,2,1,-3,0,0`, 141 142 142 143 /// Volume Unit Types 143 144 `"Steres", 1.0, 3,0,0,0,0`, 144 145 `"Liter", 0.001L, 3,0,0,0,0`, 145 `"Gal", 0.0037854 L,3,0,0,0,0`,146 `"Cup", 0.00023658 75,3,0,0,0,0`,146 `"Gal", 0.0037854120L,3,0,0,0,0`, 147 `"Cup", 0.0002365883L,3,0,0,0,0`, 147 148 148 149 /// volume rate 149 `"gpm", 6.309 e-5L,3,0,-1,0,0`,150 `"cfm", 4.719 e-4L,3,0,-1,0,0`,150 `"gpm", 6.30901995e-5L, 3,0,-1,0,0`, 151 `"cfm", 4.71947443e-4L, 3,0,-1,0,0`, 151 152 152 153 /// Speed Unit Types 153 `"Knots", 1.5144L, 1,0,-1,0,0`, 154 `"mph", 0.447L, 1,0,-1,0,0`, 155 `"kph", 0.278L, 1,0,-1,0,0`, 154 `"mps", 1L, 1,0,-1,0,0`, 155 `"Knots", 1.51444L, 1,0,-1,0,0`, 156 `"mph", 0.44704L, 1,0,-1,0,0`, 157 `"kph", 0.27778L, 1,0,-1,0,0`, 158 `"fps", 0.3048L, 1,0,-1,0,0`, 156 159 157 160 /// Capacitance Unit Types trunk/units/types.d
r447 r458 9 9 10 10 11 11 /// 12 12 public struct Types 13 13 { 14 alias Lit!( 0, 0, 0, 0, 0) Value; 15 alias Lit!( 1, 0, 0, 0, 0) Distance; 16 alias Lit!( 0, 1, 0, 0, 0) Mass; 17 alias Lit!( 0, 0, 1, 0, 0) Time; 18 alias Lit!( 0, 0, 0, 1, 0) Temp; 19 alias Lit!( 0, 0, 0, 0, 1) Current; 14 alias Lit!( 0, 0, 0, 0, 0) Value; /// 15 alias Lit!( 1, 0, 0, 0, 0) Distance; /// 16 alias Lit!( 0, 1, 0, 0, 0) Mass; /// 17 alias Lit!( 0, 0, 1, 0, 0) Time; /// 18 alias Lit!( 0, 0, 0, 1, 0) Temp; /// 19 alias Lit!( 0, 0, 0, 0, 1) Current; /// 20 20 21 alias Lit!(-2,-1, 3, 0, 2) Resistance; 22 alias Lit!(-2,-1, 4, 0, 2) Capacitance; 21 alias Lit!(-3, 1, 0, 0, 0) MassDensity; /// 23 22 24 alias Lit!(-1, 1,-2, 0, 0) Pressure; 23 alias Lit!(-2,-1, 3, 0, 2) Resistance; /// 24 alias Lit!(-2,-1, 4, 0, 2) Capacitance; /// 25 25 26 alias Lit!( 0, 0,-1, 0, 0) Frequency;27 alias Lit!( 0, 0, 1, 0, 1) Charge;26 alias Lit!(-1, 1,-2, 0, 0) Pressure; /// 27 alias Lit!(-1, 1,-1, 0, 0) Viscosity; /// 28 28 29 alias Lit!( 1, 1,-2, 0, 0) Force; 30 alias Lit!( 1, 0,-2, 0, 0) Acceleration; 31 alias Lit!( 1, 0,-1, 0, 0) Speed; 29 alias Lit!( 0, 0,-1, 0, 0) Frequency; /// 30 alias Lit!( 0, 0, 1, 0, 1) Charge; /// 32 31 33 alias Lit!( 2, 1,-3, 0,-1) Voltage; 34 alias Lit!( 2, 1,-3, 0, 0) Power; 35 alias Lit!( 2, 1,-2, 0,-2) Inductance; 36 alias Lit!( 2, 1,-2, 0, 0) Energy; 37 alias Lit!( 2, 0, 0, 0, 0) Area; 32 alias Lit!( 1, 1,-2, 0, 0) Force; /// 33 alias Lit!( 1, 0,-2, 0, 0) Acceleration;/// 34 alias Lit!( 1, 0,-1, 0, 0) Speed; /// 38 35 39 alias Lit!( 3, 0,-1, 0, 0) VolumeFlow; 40 alias Lit!( 3, 0, 0, 0, 0) Volume; 36 alias Lit!( 2, 1,-3, 0,-1) Voltage; /// 37 alias Lit!( 2, 1,-3, 0, 0) Power; /// 38 alias Lit!( 2, 1,-2, 0,-2) Inductance; /// 39 alias Lit!( 2, 1,-2, 0, 0) Energy; /// 40 alias Lit!( 2, 0, 0, 0, 0) Area; /// 41 42 alias Lit!( 3, 0,-1, 0, 0) VolumeFlow; /// 43 alias Lit!( 3, 0, 0, 0, 0) Volume; /// 41 44 42 45 } trunk/units/unit.d
r447 r458 83 83 } 84 84 85 This opNeg() { This ret; ret.value = - this.value; return ret; } 86 This opPos() { return *this; } 87 85 88 This opAdd(This that) { This ret; ret.value = this.value + that.value; return ret; } 86 89 This opSub(This that) { This ret; ret.value = this.value - that.value; return ret; } 90 This opAddAssign(This that) { this.value += that.value; return *this; } 91 This opSubAssign(This that) { this.value -= that.value; return *this; } 92 93 int opCmp(This that) 94 { 95 if(this.value < that.value) return -1; 96 if(this.value > that.value) return +1; 97 return 0; 98 } 87 99 88 100 static if(LengthN == 0 && MassN == 0 && TimeN == 0 && TempN == 0 && CurrentN == 0) … … 90 102 This opAdd(real that) { This ret; ret.value = this.value + that; return ret; } 91 103 This opSub(real that) { This ret; ret.value = this.value - that; return ret; } 104 This opAddAssign(real that) { this.value += that; return *this; } 105 This opSubAssign(real that) { this.value -= that; return *this; } 92 106 This opAdd_r(real that) { This ret; ret.value = that + this.value; return ret; } 93 107 This opSub_r(real that) { This ret; ret.value = that - this.value; return ret; }
