Changeset 783

Show
Ignore:
Timestamp:
08/24/10 19:10:20 (1 year ago)
Author:
BCS
Message:

retabed and added boost license

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/units/rational.d

    r458 r783  
     1/************************ 
     2 
     3Boost Software License - Version 1.0 - August 17th, 2003 
     4 
     5Permission is hereby granted, free of charge, to any person or organization 
     6obtaining a copy of the software and accompanying documentation covered by 
     7this license (the "Software") to use, reproduce, display, distribute, 
     8execute, and transmit the Software, and to prepare derivative works of the 
     9Software, and to permit third-parties to whom the Software is furnished to 
     10do so, all subject to the following: 
     11 
     12The copyright notices in the Software and this entire statement, including 
     13the above license grant, this restriction and the following disclaimer, 
     14must be included in all copies of the Software, in whole or in part, and 
     15all derivative works of the Software, unless such copies or derivative 
     16works are solely in the form of machine-executable object code generated by 
     17a source language processor. 
     18 
     19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
     20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
     21FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 
     22SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 
     23FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 
     24ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
     25DEALINGS IN THE SOFTWARE. 
     26 
     27****************/ 
     28 
    129module rational; 
    230 
  • trunk/units/si2.d

    r697 r783  
    44This is a unit bearing type that handles unit conversion and uses compile time  
    55checks to protect against errors like adding distance and time value. 
     6 
     7************************ 
     8 
     9Boost Software License - Version 1.0 - August 17th, 2003 
     10 
     11Permission is hereby granted, free of charge, to any person or organization 
     12obtaining a copy of the software and accompanying documentation covered by 
     13this license (the "Software") to use, reproduce, display, distribute, 
     14execute, and transmit the Software, and to prepare derivative works of the 
     15Software, and to permit third-parties to whom the Software is furnished to 
     16do so, all subject to the following: 
     17 
     18The copyright notices in the Software and this entire statement, including 
     19the above license grant, this restriction and the following disclaimer, 
     20must be included in all copies of the Software, in whole or in part, and 
     21all derivative works of the Software, unless such copies or derivative 
     22works are solely in the form of machine-executable object code generated by 
     23a source language processor. 
     24 
     25THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
     26IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
     27FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 
     28SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 
     29FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 
     30ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
     31DEALINGS IN THE SOFTWARE. 
     32 
    633************************/ 
    734 
     
    1643template T(Tp...){alias Tp T;} 
    1744 
    18 version(FullSI) 
    19 { 
    20  
    21    private alias T!(0,0) extra; 
    22    private alias T!(0,1,0,1) extra2; 
    23  
    24    template Batch( 
    25                int LengthN,  int LengthD, 
    26                int MassN,    int MassD, 
    27                int TimeN,    int TimeD, 
    28                int TempN,    int TempD, 
    29                int CurrentN, int CurrentD, 
    30                int LumiN,    int LumiD, 
    31                int MoleN,    int MoleD 
    32                
    33    
    34        // sanity check 
    35        static assert (Reduce!(LengthN,  LengthD).Reduced, "Length must be in reduced form"); 
    36        static assert (Reduce!(MassN,    MassD).Reduced,   "Mass must be in reduced form"); 
    37        static assert (Reduce!(TimeN,    TimeD).Reduced,   "Time must be in reduced form"); 
    38        static assert (Reduce!(TempN,    TempD).Reduced,   "Temp must be in reduced form"); 
    39        static assert (Reduce!(CurrentN, CurrentD).Reduced,"Current must be in reduced form"); 
    40        static assert (Reduce!(LumiN,    LumiD).Reduced,   "Luminous intensity must be in reduced form"); 
    41        static assert (Reduce!(MoleN,    MoleD).Reduced,   "Quantity must be in reduced form"); 
    42  
    43        /// visable units 
    44        enum LenN = LengthN,  LenD = LengthD; 
    45        enum MasN = MassN,    MasD = MassD;     /// 
    46        enum TimN = TimeN,    TimD = TimeD;     /// 
    47        enum TmpN = TempN,    TmpD = TempD;     /// 
    48        enum CurN = CurrentN, CurD = CurrentD;  /// 
    49        enum LumN = LumiN,    LumD = LumiD;     /// 
    50        enum MolN = MoleN,    MolD = MoleD;     /// 
    51    
    52  
    53    template SI(int LengthN, int MassN, int TimeN, int TempN, int CurrentN, int LumiN, int MoleN, T = real) 
    54    
    55        alias SIB!(Batch!( 
    56                /// visable units 
    57                LengthN,  1, 
    58                MassN,    1, 
    59                TimeN,    1, 
    60                TempN,    1, 
    61                CurrentN, 1, 
    62                LumiN,    1, 
    63                MoleN,    1 
    64                ), T) SI; 
    65    
    66    template SI( 
    67                int LengthN,  int LengthD, 
    68                int MassN,    int MassD, 
    69                int TimeN,    int TimeD, 
    70                int TempN,    int TempD, 
    71                int CurrentN, int CurrentD, 
    72                int LuminN,   int LuminD, 
    73                int MoleN,    int MoleD, 
    74                T = real 
    75                
    76    
    77        alias SIB!(Batch!( 
    78                /// visable units 
    79                LengthN,  LengthD,  
    80                MassN,    MassD, 
    81                TimeN,    TimeD, 
    82                TempN,    TempD, 
    83                CurrentN, CurrentD, 
    84                LuminN,   LuminD, 
    85                MoleN,    MoleD 
    86                ), T ) SI; 
    87    
     45version(FullSI) /// For most cases Lumins and Moles are not needed and just add bulk 
     46{ 
     47 
     48    private alias T!(0,0) extra; 
     49    private alias T!(0,1,0,1) extra2; 
     50 
     51    template Batch( 
     52                int LengthN,  int LengthD, 
     53                int MassN,    int MassD, 
     54                int TimeN,    int TimeD, 
     55                int TempN,    int TempD, 
     56                int CurrentN, int CurrentD, 
     57                int LumiN,    int LumiD, 
     58                int MoleN,    int MoleD 
     59               
     60   
     61        // sanity check 
     62        static assert (Reduce!(LengthN,  LengthD).Reduced, "Length must be in reduced form"); 
     63        static assert (Reduce!(MassN,    MassD).Reduced,   "Mass must be in reduced form"); 
     64        static assert (Reduce!(TimeN,    TimeD).Reduced,   "Time must be in reduced form"); 
     65        static assert (Reduce!(TempN,    TempD).Reduced,   "Temp must be in reduced form"); 
     66        static assert (Reduce!(CurrentN, CurrentD).Reduced,"Current must be in reduced form"); 
     67        static assert (Reduce!(LumiN,    LumiD).Reduced,   "Luminous intensity must be in reduced form"); 
     68        static assert (Reduce!(MoleN,    MoleD).Reduced,   "Quantity must be in reduced form"); 
     69 
     70        /// visable units 
     71        enum LenN = LengthN,  LenD = LengthD; 
     72        enum MasN = MassN,    MasD = MassD;        /// 
     73        enum TimN = TimeN,    TimD = TimeD;        /// 
     74        enum TmpN = TempN,    TmpD = TempD;        /// 
     75        enum CurN = CurrentN, CurD = CurrentD;    /// 
     76        enum LumN = LumiN,    LumD = LumiD;        /// 
     77        enum MolN = MoleN,    MolD = MoleD;        /// 
     78   
     79 
     80    template SI(int LengthN, int MassN, int TimeN, int TempN, int CurrentN, int LumiN, int MoleN, T = real) 
     81   
     82        alias SIB!(Batch!( 
     83                /// visable units 
     84                LengthN,  1, 
     85                MassN,    1, 
     86                TimeN,    1, 
     87                TempN,    1, 
     88                CurrentN, 1, 
     89                LumiN,    1, 
     90                MoleN,    1 
     91                ), T) SI; 
     92   
     93    template SI( 
     94                int LengthN,  int LengthD, 
     95                int MassN,    int MassD, 
     96                int TimeN,    int TimeD, 
     97                int TempN,    int TempD, 
     98                int CurrentN, int CurrentD, 
     99                int LuminN,   int LuminD, 
     100                int MoleN,    int MoleD, 
     101                T = real 
     102               
     103   
     104        alias SIB!(Batch!( 
     105                /// visable units 
     106                LengthN,  LengthD,  
     107                MassN,    MassD, 
     108                TimeN,    TimeD, 
     109                TempN,    TempD, 
     110                CurrentN, CurrentD, 
     111                LuminN,   LuminD, 
     112                MoleN,    MoleD 
     113                ), T ) SI; 
     114   
    88115} 
    89116else 
    90117{ 
    91     private alias T!() extra; 
    92     private alias T!() extra2; 
    93     template Batch( 
    94                 int LengthN,  int LengthD, 
    95                 int MassN,    int MassD, 
    96                 int TimeN,    int TimeD, 
    97                 int TempN,    int TempD, 
    98                 int CurrentN, int CurrentD 
    99                 ) 
    100     { 
    101         // sanity check 
    102         static assert (Reduce!(LengthN,  LengthD).Reduced, "Length must be in reduced form"); 
    103         static assert (Reduce!(MassN,    MassD).Reduced,   "Mass must be in reduced form"); 
    104         static assert (Reduce!(TimeN,    TimeD).Reduced,   "Time must be in reduced form"); 
    105         static assert (Reduce!(TempN,    TempD).Reduced,   "Temp must be in reduced form"); 
    106         static assert (Reduce!(CurrentN, CurrentD).Reduced,"Current must be in reduced form"); 
    107  
    108         /// visable units 
    109         enum LenN = LengthN,  LenD = LengthD; 
    110         enum MasN = MassN,    MasD = MassD;     /// 
    111         enum TimN = TimeN,    TimD = TimeD;     /// 
    112         enum TmpN = TempN,    TmpD = TempD;     /// 
    113         enum CurN = CurrentN, CurD = CurrentD;  /// 
    114     } 
    115  
    116     template SI(int LengthN, int MassN, int TimeN, int TempN, int CurrentN, T = real) 
    117     { 
    118         alias SIB!(Batch!( 
    119                 /// visable units 
    120                 LengthN,  1, 
    121                 MassN,    1, 
    122                 TimeN,    1, 
    123                 TempN,    1, 
    124                 CurrentN, 1 
    125                 ), T ) SI; 
    126     } 
    127     template SI( 
    128                 int LengthN,  int LengthD, 
    129                 int MassN,    int MassD, 
    130                 int TimeN,    int TimeD, 
    131                 int TempN,    int TempD, 
    132                 int CurrentN, int CurrentD, 
    133                 T = real 
    134                 ) 
    135     { 
    136  
    137         alias SIB!(Batch!( 
    138                 /// visable units 
    139                 LengthN,  LengthD, 
    140                 MassN,    MassD, 
    141                 TimeN,    TimeD, 
    142                 TempN,    TempD, 
    143                 CurrentN, CurrentD 
    144                 ), T ) SI; 
    145     } 
    146 
     118    private alias T!() extra; 
     119    private alias T!() extra2; 
     120    template Batch( 
     121                int LengthN,  int LengthD, 
     122                int MassN,    int MassD, 
     123                int TimeN,    int TimeD, 
     124                int TempN,    int TempD, 
     125                int CurrentN, int CurrentD 
     126                ) 
     127    { 
     128        // sanity check 
     129        static assert (Reduce!(LengthN,  LengthD).Reduced, "Length must be in reduced form"); 
     130        static assert (Reduce!(MassN,    MassD).Reduced,   "Mass must be in reduced form"); 
     131        static assert (Reduce!(TimeN,    TimeD).Reduced,   "Time must be in reduced form"); 
     132        static assert (Reduce!(TempN,    TempD).Reduced,   "Temp must be in reduced form"); 
     133        static assert (Reduce!(CurrentN, CurrentD).Reduced,"Current must be in reduced form"); 
     134 
     135        /// visable units 
     136        enum LenN = LengthN,  LenD = LengthD; 
     137        enum MasN = MassN,    MasD = MassD;        /// 
     138        enum TimN = TimeN,    TimD = TimeD;        /// 
     139        enum TmpN = TempN,    TmpD = TempD;        /// 
     140        enum CurN = CurrentN, CurD = CurrentD;    /// 
     141    } 
     142 
     143    template SI(int LengthN, int MassN, int TimeN, int TempN, int CurrentN, T = real) 
     144    { 
     145        alias SIB!(Batch!( 
     146                /// visable units 
     147                LengthN,  1, 
     148                MassN,    1, 
     149                TimeN,    1, 
     150                TempN,    1, 
     151                CurrentN, 1 
     152                ), T ) SI; 
     153    } 
     154    template SI( 
     155                int LengthN,  int LengthD, 
     156                int MassN,    int MassD, 
     157                int TimeN,    int TimeD, 
     158                int TempN,    int TempD, 
     159                int CurrentN, int CurrentD, 
     160                T = real 
     161                ) 
     162    { 
     163 
     164        alias SIB!(Batch!( 
     165                /// visable units 
     166                LengthN,  LengthD, 
     167                MassN,    MassD, 
     168                TimeN,    TimeD, 
     169                TempN,    TempD, 
     170                CurrentN, CurrentD 
     171                ), T ) SI; 
     172    } 
     173
     174 
    147175struct SIB(alias Exp_, U) 
    148176{ 
    149177 
    150    alias Exp_ Exp; 
    151  
    152  
    153    // generate a usable name string 
    154    static if(Exp.LenD == 1) private enum sLen = Exp.LenN.stringof; else private enum sLen = Exp.LenN.stringof~"/"~Exp.LenD.stringof; 
    155    static if(Exp.MasD == 1) private enum sMas = Exp.MasN.stringof; else private enum sMas = Exp.MasN.stringof~"/"~Exp.MasD.stringof; 
    156    static if(Exp.TimD == 1) private enum sTim = Exp.TimN.stringof; else private enum sTim = Exp.TimN.stringof~"/"~Exp.TimD.stringof; 
    157    static if(Exp.TmpD == 1) private enum sTmp = Exp.TmpN.stringof; else private enum sTmp = Exp.TmpN.stringof~"/"~Exp.TmpD.stringof; 
    158    static if(Exp.CurD == 1) private enum sCur = Exp.CurN.stringof; else private enum sCur = Exp.CurN.stringof~"/"~Exp.CurD.stringof; 
    159    /// The type name 
    160     version(FullSI)  
    161    
    162    static if(Exp.LumD == 1) private enum sLum = Exp.LumN.stringof; else private enum sLum = Exp.LumN.stringof~"/"~Exp.LumD.stringof; 
    163    static if(Exp.MolD == 1) private enum sMol = Exp.MolN.stringof; else private enum sMol = Exp.MolN.stringof~"/"~Exp.MolD.stringof; 
    164    public enum Stringof = "SI!("~sLen~","~sMas~","~sTim~","~sTmp~","~sCur~","~sLum~","~sMol~","~U.stringof~")"; 
    165    
    166    else public enum Stringof = "SI!("~sLen~","~sMas~","~sTim~","~sTmp~","~sCur~","~U.stringof~")"; 
    167  
    168    /// the value 
    169    private U value; 
    170  
    171    /// a more meaningful name 
    172    private alias SIB This; 
    173  
    174    // check to make shure it's right! 
    175    static assert(is(SIB!(Exp,U) == This)); 
    176  
    177    template Using(V) { alias SIB!(Exp,V) Using; } 
    178  
    179    template Alike2(V) 
    180    
    181        version(FullSI) enum bool Alike2 =  
    182                    Exp.LumN == V.Exp.LumN && Exp.LumD == V.Exp.LumD && 
    183                    Exp.MolN == V.Exp.MolN && Exp.MolD == V.Exp.MolD; 
    184        else enum bool Alike2 = true; 
    185    
    186    template Alike(V) 
    187    
    188        enum bool Alike = Alike2!(V) && 
    189            Exp.LenN == V.Exp.LenN && Exp.LenD == V.Exp.LenD && 
    190            Exp.MasN == V.Exp.MasN && Exp.MasD == V.Exp.MasD && 
    191            Exp.TimN == V.Exp.TimN && Exp.TimD == V.Exp.TimD && 
    192            Exp.TmpN == V.Exp.TmpN && Exp.TmpD == V.Exp.TmpD && 
    193            Exp.CurN == V.Exp.CurN && Exp.CurD == V.Exp.CurD; 
    194    
    195  
    196  
    197    /// find the type of "This * T" 
    198    private template Mul2(U) 
    199    
    200        version(FullSI) alias T!( 
    201                Reduce!(Exp.LumN*U.Exp.LumD + Exp.LumD*U.Exp.LumN, Exp.LumD*U.Exp.LumD).V, 
    202                Reduce!(Exp.MolN*U.Exp.MolD + Exp.MolD*U.Exp.MolN, Exp.MolD*U.Exp.MolD).V) Mul2; 
    203        else alias T!() Mul2; 
    204    
    205    private template Mul(T) 
    206    
    207        static if(is(T : U)) 
    208            alias This Mul; 
    209        else 
    210            alias SIB!(Batch!( 
    211                        Reduce!(Exp.LenN*T.Exp.LenD + Exp.LenD*T.Exp.LenN, Exp.LenD*T.Exp.LenD).V, 
    212                        Reduce!(Exp.MasN*T.Exp.MasD + Exp.MasD*T.Exp.MasN, Exp.MasD*T.Exp.MasD).V, 
    213                        Reduce!(Exp.TimN*T.Exp.TimD + Exp.TimD*T.Exp.TimN, Exp.TimD*T.Exp.TimD).V, 
    214                        Reduce!(Exp.TmpN*T.Exp.TmpD + Exp.TmpD*T.Exp.TmpN, Exp.TmpD*T.Exp.TmpD).V, 
    215                        Reduce!(Exp.CurN*T.Exp.CurD + Exp.CurD*T.Exp.CurN, Exp.CurD*T.Exp.CurD).V, 
    216                        Mul2!(T)), 
    217                        
    218                    ) Mul; 
    219    
    220  
    221    /// find the type of "This / T" 
    222    private template Div2(U) 
    223    
    224        version(FullSI) alias T!( 
    225                Reduce!(Exp.LumN*U.Exp.LumD - Exp.LumD*U.Exp.LumN, Exp.LumD*U.Exp.LumD).V, 
    226                Reduce!(Exp.MolN*U.Exp.MolD - Exp.MolD*U.Exp.MolN, Exp.MolD*U.Exp.MolD).V) Div2; 
    227        else alias T!() Div2; 
    228    
    229    private template Div(T) 
    230    
    231        static if(is(T : U)) 
    232            alias This Div; 
    233        else 
    234            alias SIB!(Batch!( 
    235                        Reduce!(Exp.LenN*T.Exp.LenD - Exp.LenD*T.Exp.LenN, Exp.LenD*T.Exp.LenD).V, 
    236                        Reduce!(Exp.MasN*T.Exp.MasD - Exp.MasD*T.Exp.MasN, Exp.MasD*T.Exp.MasD).V, 
    237                        Reduce!(Exp.TimN*T.Exp.TimD - Exp.TimD*T.Exp.TimN, Exp.TimD*T.Exp.TimD).V, 
    238                        Reduce!(Exp.TmpN*T.Exp.TmpD - Exp.TmpD*T.Exp.TmpN, Exp.TmpD*T.Exp.TmpD).V, 
    239                        Reduce!(Exp.CurN*T.Exp.CurD - Exp.CurD*T.Exp.CurN, Exp.CurD*T.Exp.CurD).V, 
    240                        Div2!(T)), 
    241                        
    242                    ) Div; 
    243    
    244  
    245    /// find the type of "This ^ 1/i" 
    246    private template Root2(int i) 
    247    
    248        version(FullSI) alias T!( 
    249                Reduce!(Exp.LumN,Exp.LumD*i).V, 
    250                Reduce!(Exp.MolN,Exp.MolD*i).V) Root2; 
    251        else alias T!() Root2; 
    252    
    253    private static template RootT(int i) 
    254    
    255        alias SIB!(Batch!( 
    256            Reduce!(Exp.LenN, Exp.LenD*i).V, 
    257            Reduce!(Exp.MasN, Exp.MasD*i).V, 
    258            Reduce!(Exp.TimN, Exp.TimD*i).V, 
    259            Reduce!(Exp.TmpN, Exp.TmpD*i).V, 
    260            Reduce!(Exp.CurN, Exp.CurD*i).V, 
    261            Root2!(i) 
    262            ), 
    263            U) RootT; 
    264    
    265  
    266    /// find the type of "This ^ i" 
    267    private template Power2(int i) 
    268    
    269        version(FullSI) alias T!( 
    270                Reduce!(Exp.LumN*i,Exp.LumD).V, 
    271                Reduce!(Exp.MolN*i,Exp.MolD).V) Power2; 
    272        else alias T!() Power2; 
    273    
    274    private template Power(int i) 
    275    
    276        alias SIB!(Batch!( 
    277            Reduce!(Exp.LenN*i, Exp.LenD).V, 
    278            Reduce!(Exp.MasN*i, Exp.MasD).V, 
    279            Reduce!(Exp.TimN*i, Exp.TimD).V, 
    280            Reduce!(Exp.TmpN*i, Exp.TmpD).V, 
    281            Reduce!(Exp.CurN*i, Exp.CurD).V, 
    282            Power2!(i) 
    283            ), 
    284            U) Power; 
    285    
    286  
    287    // I don't think I need this anymore 
    288    //This opCall(This ret) { return ret; } 
    289  
    290  
    291    private this(U u) { value = u; } 
    292  
    293    int opCmp(This that)  
    294    
    295        if(this.value < that.value) return -1; 
    296        if(this.value > that.value) return +1; 
    297        return 0; 
    298    
    299  
    300    int opCmp(U that)  
    301    
    302        if(this.value < that) return -1; 
    303        if(this.value > that) return +1; 
    304        return 0; 
    305    
    306  
    307    /// Homomorphic math operators 
    308    This opNeg() { return This(- this.value);} 
    309    This opPos() { return this; }   /// 
    310  
    311    This opAdd(This that) { return This(this.value + that.value);}  /// 
    312    This opSub(This that) { return This(this.value - that.value);}  /// 
    313    This opAddAssign(This that) { this.value += that.value; return this; }  /// 
    314    This opSubAssign(This that) { this.value -= that.value; return this; }  /// 
    315  
    316    This opMulAssign(U r) { this.value *= r; return this; } 
    317    This opDivAssign(U r) { this.value /= r; return this; } /// 
    318      
    319    This opMul_r(U that) { return This(this.value * that); }    /// 
    320  
    321        /// non-Homomorphic math operators 
    322    auto opDiv_r(U that) { return Power!(-1)(that / this.value); }  /// 
    323  
    324    version(FullSI) private enum unitless2 = Exp.LumN == 0 && Exp.MolN == 0; 
    325    else private enum unitless2 = true; 
    326    static if(Exp.LenN == 0 && Exp.MasN == 0 && Exp.TimN == 0 && Exp.TmpN == 0 && Exp.CurN == 0 && unitless2) 
    327        alias value this; 
    328    else 
    329    
    330        // these conflict if the "alias value this" is in effect 
    331  
    332        /// non-Homomorphic math operators 
    333        auto opMul(T)(T that) 
    334        
    335            static if(is(T : U)) return Mul!(T)(this.value * that); 
    336            else return Mul!(T)(this.value * that.value); 
    337        
    338        auto opDiv(T)(T that)   /// 
    339        
    340            static if(is(T : U)) return Div!(T)(this.value / that); 
    341            else return Div!(T)(this.value / that.value); 
    342        
    343    
    344  
    345    /// test if these are close enough 
    346    bool Near(This that, int count = 5) 
    347    
    348        static if(isFloatingPoint!(U)) 
    349            return std.math.feqrel!(U)(this.value,that.value) + count >= U.mant_dig; 
    350        else 
    351            return this.value == that.value; 
    352    
    353  
    354    /// common math functions 
    355    auto Root(int i)(){return RootT!(i)(std.math.sqrt(this.value));} 
    356    auto Pow(int i)(){return Power!(i)(std.math.pow(this.value,i));}    /// 
    357    This Abs() { return This(std.math.abs(this.value)); }   /// 
    358  
    359  
    360    /// convert to real from type "s" 
    361    U opDispatch(string s)() 
    362    
    363        static if(!is(Unit!(s).type)) static assert(false, "SI has no member named "~s~" nor is it a known type"); 
    364        else 
    365        
    366            static assert(This.Alike!(Unit!(s).type), "Can't convert type "~This.Stringof~" to \""~s~"\" of type "~Unit!(s).type.Stringof); 
    367            return value / Unit!(s).mul; 
    368        
    369    
     178    alias Exp_ Exp; 
     179 
     180 
     181    // generate a usable name string 
     182    static if(Exp.LenD == 1) private enum sLen = Exp.LenN.stringof; else private enum sLen = Exp.LenN.stringof~"/"~Exp.LenD.stringof; 
     183    static if(Exp.MasD == 1) private enum sMas = Exp.MasN.stringof; else private enum sMas = Exp.MasN.stringof~"/"~Exp.MasD.stringof; 
     184    static if(Exp.TimD == 1) private enum sTim = Exp.TimN.stringof; else private enum sTim = Exp.TimN.stringof~"/"~Exp.TimD.stringof; 
     185    static if(Exp.TmpD == 1) private enum sTmp = Exp.TmpN.stringof; else private enum sTmp = Exp.TmpN.stringof~"/"~Exp.TmpD.stringof; 
     186    static if(Exp.CurD == 1) private enum sCur = Exp.CurN.stringof; else private enum sCur = Exp.CurN.stringof~"/"~Exp.CurD.stringof; 
     187    /// The type name 
     188    version(FullSI)     
     189   
     190    static if(Exp.LumD == 1) private enum sLum = Exp.LumN.stringof; else private enum sLum = Exp.LumN.stringof~"/"~Exp.LumD.stringof; 
     191    static if(Exp.MolD == 1) private enum sMol = Exp.MolN.stringof; else private enum sMol = Exp.MolN.stringof~"/"~Exp.MolD.stringof; 
     192    public enum Stringof = "SI!("~sLen~","~sMas~","~sTim~","~sTmp~","~sCur~","~sLum~","~sMol~","~U.stringof~")"; 
     193   
     194    else public enum Stringof = "SI!("~sLen~","~sMas~","~sTim~","~sTmp~","~sCur~","~U.stringof~")"; 
     195 
     196    /// the value 
     197    private U value; 
     198 
     199    /// a more meaningful name 
     200    private alias SIB This; 
     201 
     202    // check to make shure it's right! 
     203    static assert(is(SIB!(Exp,U) == This)); 
     204 
     205    template Using(V) { alias SIB!(Exp,V) Using; } 
     206 
     207    template Alike2(V) 
     208   
     209        version(FullSI) enum bool Alike2 =  
     210                    Exp.LumN == V.Exp.LumN && Exp.LumD == V.Exp.LumD && 
     211                    Exp.MolN == V.Exp.MolN && Exp.MolD == V.Exp.MolD; 
     212        else enum bool Alike2 = true; 
     213   
     214    template Alike(V) 
     215   
     216        enum bool Alike = Alike2!(V) && 
     217            Exp.LenN == V.Exp.LenN && Exp.LenD == V.Exp.LenD && 
     218            Exp.MasN == V.Exp.MasN && Exp.MasD == V.Exp.MasD && 
     219            Exp.TimN == V.Exp.TimN && Exp.TimD == V.Exp.TimD && 
     220            Exp.TmpN == V.Exp.TmpN && Exp.TmpD == V.Exp.TmpD && 
     221            Exp.CurN == V.Exp.CurN && Exp.CurD == V.Exp.CurD; 
     222   
     223 
     224 
     225    /// find the type of "This * T" 
     226    private template Mul2(U) 
     227   
     228        version(FullSI) alias T!( 
     229                Reduce!(Exp.LumN*U.Exp.LumD + Exp.LumD*U.Exp.LumN, Exp.LumD*U.Exp.LumD).V, 
     230                Reduce!(Exp.MolN*U.Exp.MolD + Exp.MolD*U.Exp.MolN, Exp.MolD*U.Exp.MolD).V) Mul2; 
     231        else alias T!() Mul2; 
     232   
     233    private template Mul(T) 
     234   
     235        static if(is(T : U)) 
     236            alias This Mul; 
     237        else 
     238            alias SIB!(Batch!( 
     239                        Reduce!(Exp.LenN*T.Exp.LenD + Exp.LenD*T.Exp.LenN, Exp.LenD*T.Exp.LenD).V, 
     240                        Reduce!(Exp.MasN*T.Exp.MasD + Exp.MasD*T.Exp.MasN, Exp.MasD*T.Exp.MasD).V, 
     241                        Reduce!(Exp.TimN*T.Exp.TimD + Exp.TimD*T.Exp.TimN, Exp.TimD*T.Exp.TimD).V, 
     242                        Reduce!(Exp.TmpN*T.Exp.TmpD + Exp.TmpD*T.Exp.TmpN, Exp.TmpD*T.Exp.TmpD).V, 
     243                        Reduce!(Exp.CurN*T.Exp.CurD + Exp.CurD*T.Exp.CurN, Exp.CurD*T.Exp.CurD).V, 
     244                        Mul2!(T)), 
     245                       
     246                    ) Mul; 
     247   
     248 
     249    /// find the type of "This / T" 
     250    private template Div2(U) 
     251   
     252        version(FullSI) alias T!( 
     253                Reduce!(Exp.LumN*U.Exp.LumD - Exp.LumD*U.Exp.LumN, Exp.LumD*U.Exp.LumD).V, 
     254                Reduce!(Exp.MolN*U.Exp.MolD - Exp.MolD*U.Exp.MolN, Exp.MolD*U.Exp.MolD).V) Div2; 
     255        else alias T!() Div2; 
     256   
     257    private template Div(T) 
     258   
     259        static if(is(T : U)) 
     260            alias This Div; 
     261        else 
     262            alias SIB!(Batch!( 
     263                        Reduce!(Exp.LenN*T.Exp.LenD - Exp.LenD*T.Exp.LenN, Exp.LenD*T.Exp.LenD).V, 
     264                        Reduce!(Exp.MasN*T.Exp.MasD - Exp.MasD*T.Exp.MasN, Exp.MasD*T.Exp.MasD).V, 
     265                        Reduce!(Exp.TimN*T.Exp.TimD - Exp.TimD*T.Exp.TimN, Exp.TimD*T.Exp.TimD).V, 
     266                        Reduce!(Exp.TmpN*T.Exp.TmpD - Exp.TmpD*T.Exp.TmpN, Exp.TmpD*T.Exp.TmpD).V, 
     267                        Reduce!(Exp.CurN*T.Exp.CurD - Exp.CurD*T.Exp.CurN, Exp.CurD*T.Exp.CurD).V, 
     268                        Div2!(T)), 
     269                       
     270                    ) Div; 
     271   
     272 
     273    /// find the type of "This ^ 1/i" 
     274    private template Root2(int i) 
     275   
     276        version(FullSI) alias T!( 
     277                Reduce!(Exp.LumN,Exp.LumD*i).V, 
     278                Reduce!(Exp.MolN,Exp.MolD*i).V) Root2; 
     279        else alias T!() Root2; 
     280   
     281    private static template RootT(int i) 
     282   
     283        alias SIB!(Batch!( 
     284            Reduce!(Exp.LenN, Exp.LenD*i).V, 
     285            Reduce!(Exp.MasN, Exp.MasD*i).V, 
     286            Reduce!(Exp.TimN, Exp.TimD*i).V, 
     287            Reduce!(Exp.TmpN, Exp.TmpD*i).V, 
     288            Reduce!(Exp.CurN, Exp.CurD*i).V, 
     289            Root2!(i) 
     290            ), 
     291            U) RootT; 
     292   
     293 
     294    /// find the type of "This ^ i" 
     295    private template Power2(int i) 
     296   
     297        version(FullSI) alias T!( 
     298                Reduce!(Exp.LumN*i,Exp.LumD).V, 
     299                Reduce!(Exp.MolN*i,Exp.MolD).V) Power2; 
     300        else alias T!() Power2; 
     301   
     302    private template Power(int i) 
     303   
     304        alias SIB!(Batch!( 
     305            Reduce!(Exp.LenN*i, Exp.LenD).V, 
     306            Reduce!(Exp.MasN*i, Exp.MasD).V, 
     307            Reduce!(Exp.TimN*i, Exp.TimD).V, 
     308            Reduce!(Exp.TmpN*i, Exp.TmpD).V, 
     309            Reduce!(Exp.CurN*i, Exp.CurD).V, 
     310            Power2!(i) 
     311            ), 
     312            U) Power; 
     313   
     314 
     315    // I don't think I need this anymore 
     316    //This opCall(This ret) { return ret; } 
     317 
     318 
     319    private this(U u) { value = u; } 
     320 
     321    int opCmp(This that)  
     322   
     323        if(this.value < that.value) return -1; 
     324        if(this.value > that.value) return +1; 
     325        return 0; 
     326   
     327 
     328    int opCmp(U that)  
     329   
     330        if(this.value < that) return -1; 
     331        if(this.value > that) return +1; 
     332        return 0; 
     333   
     334 
     335    /// Homomorphic math operators 
     336    This opNeg() { return This(- this.value);} 
     337    This opPos() { return this; }    /// 
     338 
     339    This opAdd(This that) { return This(this.value + that.value);}    /// 
     340    This opSub(This that) { return This(this.value - that.value);}    /// 
     341    This opAddAssign(This that) { this.value += that.value; return this; }    /// 
     342    This opSubAssign(This that) { this.value -= that.value; return this; }    /// 
     343 
     344    This opMulAssign(U r) { this.value *= r; return this; } 
     345    This opDivAssign(U r) { this.value /= r; return this; }    /// 
     346     
     347    This opMul_r(U that) { return This(this.value * that); }    /// 
     348 
     349        /// non-Homomorphic math operators 
     350    auto opDiv_r(U that) { return Power!(-1)(that / this.value); }    /// 
     351 
     352    version(FullSI) private enum unitless2 = Exp.LumN == 0 && Exp.MolN == 0; 
     353    else private enum unitless2 = true; 
     354    static if(Exp.LenN == 0 && Exp.MasN == 0 && Exp.TimN == 0 && Exp.TmpN == 0 && Exp.CurN == 0 && unitless2) 
     355        alias value this; 
     356    else 
     357   
     358        // these conflict if the "alias value this" is in effect 
     359 
     360        /// non-Homomorphic math operators 
     361        auto opMul(T)(T that) 
     362       
     363            static if(is(T : U)) return Mul!(T)(this.value * that); 
     364            else return Mul!(T)(this.value * that.value); 
     365       
     366        auto opDiv(T)(T that)    /// 
     367       
     368            static if(is(T : U)) return Div!(T)(this.value / that); 
     369            else return Div!(T)(this.value / that.value); 
     370       
     371   
     372 
     373    /// test if these are close enough 
     374    bool Near(This that, int count = 5) 
     375   
     376        static if(isFloatingPoint!(U)) 
     377            return std.math.feqrel!(U)(this.value,that.value) + count >= U.mant_dig; 
     378        else 
     379            return this.value == that.value; 
     380   
     381 
     382    /// common math functions 
     383    auto Root(int i)(){return RootT!(i)(std.math.sqrt(this.value));} 
     384    auto Pow(int i)(){return Power!(i)(std.math.pow(this.value,i));}    /// 
     385    This Abs() { return This(std.math.abs(this.value)); }    /// 
     386 
     387 
     388    /// convert to real from type "s" 
     389    U opDispatch(string s)() 
     390   
     391        static if(!is(Unit!(s).type)) static assert(false, "SI has no member named "~s~" nor is it a known type"); 
     392        else 
     393       
     394            static assert(This.Alike!(Unit!(s).type), "Can't convert type "~This.Stringof~" to \""~s~"\" of type "~Unit!(s).type.Stringof); 
     395            return value / Unit!(s).mul; 
     396       
     397   
    370398 
    371399} 
     
    374402struct OfType 
    375403{ 
    376    static auto opDispatch(string s, U)(U v) /// 
    377    
    378        static if(!is(Unit!(s).type)) static assert(false, "OfType."~s~" is not a known type"); 
    379        else return Unit!(s).type.Using!(U)(cast(U)(v * Unit!(s).mul)); 
    380    
     404    static auto opDispatch(string s, U)(U v) /// 
     405   
     406        static if(!is(Unit!(s).type)) static assert(false, "OfType."~s~" is not a known type"); 
     407        else return Unit!(s).type.Using!(U)(cast(U)(v * Unit!(s).mul)); 
     408   
    381409} 
    382410 
     
    385413public struct Types 
    386414{ 
    387    alias SI!( 0, 0, 0, 0, 0, extra) Value;         /// 
    388    alias SI!( 1, 0, 0, 0, 0, extra) Distance;      /// 
    389    alias SI!( 0, 1, 0, 0, 0, extra) Mass;          /// 
    390    alias SI!( 0, 0, 1, 0, 0, extra) Time;          /// 
    391    alias SI!( 0, 0, 0, 1, 0, extra) Temp;          /// 
    392    alias SI!( 0, 0, 0, 0, 1, extra) Current;       /// 
    393    version(FullSI) 
    394    
    395    alias SI!( 0, 0, 0, 0, 0, 1, 0) Luminosity;     /// 
    396    alias SI!( 0, 0, 0, 0, 0, 0, 1) Quantity;       /// 
    397    
    398  
    399    alias SI!(-3, 1, 0, 0, 0, extra) MassDensity;   /// 
    400  
    401    alias SI!(-2,-1, 3, 0, 2, extra) Resistance;    /// 
    402    alias SI!(-2,-1, 4, 0, 2, extra) Capacitance;   /// 
    403  
    404    alias SI!(-1, 1,-2, 0, 0, extra) Pressure;      /// 
    405    alias SI!(-1, 1,-1, 0, 0, extra) Viscosity;     /// 
    406  
    407    alias SI!( 0, 0,-1, 0, 0, extra) Frequency;     /// 
    408    alias SI!( 0, 0, 1, 0, 1, extra) Charge;        /// 
    409    alias SI!( 0, 1,-1, 0, 0, extra) MassFlow;      /// 
    410    alias SI!( 0, 1,-2, 0,-1, extra) MagneticFluxD; /// 
    411  
    412    alias SI!( 1, 1,-2, 0, 0, extra) Force;         /// 
    413    alias SI!( 1, 0,-2, 0, 0, extra) Acceleration;  /// 
    414    alias SI!( 1, 0,-1, 0, 0, extra) Speed;         /// 
    415  
    416  
    417    alias SI!( 2, 1,-3, 0,-1, extra) Voltage;       /// 
    418    alias SI!( 2, 1,-3, 0, 0, extra) Power;         /// 
    419    alias SI!( 2, 1,-2, 0,-2, extra) Inductance;    /// 
    420    alias SI!( 2, 1,-2, 0, 0, extra) Energy;        /// 
    421    alias SI!( 2, 0, 0, 0, 0, extra) Area;          /// 
    422    alias SI!( 2, 0,-1, 0, 0, extra) KViscosity;    /// 
    423  
    424    alias SI!( 3, 0,-1, 0, 0, extra) VolumeFlow;    /// 
    425    alias SI!( 3, 0, 0, 0, 0, extra) Volume;        /// 
     415    alias SI!( 0, 0, 0, 0, 0, extra) Value;            /// 
     416    alias SI!( 1, 0, 0, 0, 0, extra) Distance;        /// 
     417    alias SI!( 0, 1, 0, 0, 0, extra) Mass;            /// 
     418    alias SI!( 0, 0, 1, 0, 0, extra) Time;            /// 
     419    alias SI!( 0, 0, 0, 1, 0, extra) Temp;            /// 
     420    alias SI!( 0, 0, 0, 0, 1, extra) Current;        /// 
     421    version(FullSI) 
     422   
     423    alias SI!( 0, 0, 0, 0, 0, 1, 0) Luminosity;        /// 
     424    alias SI!( 0, 0, 0, 0, 0, 0, 1) Quantity;        /// 
     425   
     426 
     427    alias SI!(-3, 1, 0, 0, 0, extra) MassDensity;    /// 
     428 
     429    alias SI!(-2,-1, 3, 0, 2, extra) Resistance;    /// 
     430    alias SI!(-2,-1, 4, 0, 2, extra) Capacitance;    /// 
     431 
     432    alias SI!(-1, 1,-2, 0, 0, extra) Pressure;        /// 
     433    alias SI!(-1, 1,-1, 0, 0, extra) Viscosity;        /// 
     434 
     435    alias SI!( 0, 0,-1, 0, 0, extra) Frequency;        /// 
     436    alias SI!( 0, 0, 1, 0, 1, extra) Charge;        /// 
     437    alias SI!( 0, 1,-1, 0, 0, extra) MassFlow;        /// 
     438    alias SI!( 0, 1,-2, 0,-1, extra) MagneticFluxD;    /// 
     439 
     440    alias SI!( 1, 1,-2, 0, 0, extra) Force;            /// 
     441    alias SI!( 1, 0,-2, 0, 0, extra) Acceleration;    /// 
     442    alias SI!( 1, 0,-1, 0, 0, extra) Speed;            /// 
     443 
     444 
     445    alias SI!( 2, 1,-3, 0,-1, extra) Voltage;        /// 
     446    alias SI!( 2, 1,-3, 0, 0, extra) Power;            /// 
     447    alias SI!( 2, 1,-2, 0,-2, extra) Inductance;    /// 
     448    alias SI!( 2, 1,-2, 0, 0, extra) Energy;        /// 
     449    alias SI!( 2, 0, 0, 0, 0, extra) Area;            /// 
     450    alias SI!( 2, 0,-1, 0, 0, extra) KViscosity;    /// 
     451 
     452    alias SI!( 3, 0,-1, 0, 0, extra) VolumeFlow;    /// 
     453    alias SI!( 3, 0, 0, 0, 0, extra) Volume;        /// 
    426454} 
    427455 
     
    429457public struct Engr 
    430458{ 
    431    /// 
    432    public struct Thermal 
    433    
    434        alias SI!( 2, 0,-2,-1, 0, extra) ThermalCap;        /// 
    435        alias SI!( 1, 1,-3,-1, 0, extra) ThermalCond;       /// 
    436        alias SI!( 0, 1,-3,-1, 0, extra) ConvectionCoeff;   /// 
    437    
    438    /// 
    439    public struct FracturMechanics 
    440    
    441        alias SI!(-1,2, 1,1,-2,1, 0,1, 0,1, extra2) StressIntensity;/// 
    442    
     459    /// 
     460    public struct Thermal 
     461   
     462        alias SI!( 2, 0,-2,-1, 0, extra) ThermalCap;        /// 
     463        alias SI!( 1, 1,-3,-1, 0, extra) ThermalCond;        /// 
     464        alias SI!( 0, 1,-3,-1, 0, extra) ConvectionCoeff;    /// 
     465   
     466    /// 
     467    public struct FracturMechanics 
     468   
     469        alias SI!(-1,2, 1,1,-2,1, 0,1, 0,1, extra2) StressIntensity;/// 
     470   
    443471} 
    444472 
    445473/// Base SI units 
    446 template Unit(string name : "value")   { enum mul = 1.0;               alias Value          type; } 
    447 template Unit(string name : "meter")   { enum mul = 1.0;               alias Types.Distance type; }    /// 
    448 template Unit(string name : "kilogram")    { enum mul = 1.0;               alias Types.Mass     type; }    /// 
    449 template Unit(string name : "second")  { enum mul = 1.0;               alias Types.Time     type; }    /// 
    450 template Unit(string name : "kelvin")  { enum mul = 1.0;               alias Types.Temp     type; }    /// 
    451 template Unit(string name : "ampere")  { enum mul = 1.0;               alias Types.Current  type; }    /// 
     474template Unit(string name : "value")    { enum mul = 1.0;                alias Value          type; } 
     475template Unit(string name : "meter")    { enum mul = 1.0;                alias Types.Distance type; }    /// 
     476template Unit(string name : "kilogram")    { enum mul = 1.0;                alias Types.Mass     type; }    /// 
     477template Unit(string name : "second")    { enum mul = 1.0;                alias Types.Time     type; }    /// 
     478template Unit(string name : "kelvin")    { enum mul = 1.0;                alias Types.Temp     type; }    /// 
     479template Unit(string name : "ampere")    { enum mul = 1.0;                alias Types.Current  type; }    /// 
    452480version(FullSI) 
    453481{ 
    454 //template Unit(string name : "candela")   { enum mul = 1.0;               alias Types.Luminosity type; }  /// This one is named wrong 
    455 template Unit(string name : "mole")        { enum mul = 1.0;               alias Types.Quantity   type; }  /// 
     482//template Unit(string name : "candela")    { enum mul = 1.0;                alias Types.Luminosity type; }    /// This one is named wrong 
     483template Unit(string name : "mole")        { enum mul = 1.0;                alias Types.Quantity   type; }    /// 
    456484} 
    457485 
    458486/// Distance Unit Types 
    459 template Unit(string name : "Angstrom")    { enum mul = 1e-10;             alias Types.Distance type; } 
    460 template Unit(string name : "Micron")  { enum mul = 1e-6;              alias Types.Distance type; }    /// 
    461 template Unit(string name : "mm")      { enum mul = 1e-3;              alias Types.Distance type; }    /// 
    462 template Unit(string name : "cm")      { enum mul = 1e-2;              alias Types.Distance type; }    /// 
    463 template Unit(string name : "km")      { enum mul = 1e3;               alias Types.Distance type; }    /// 
    464 template Unit(string name : "inch")        { enum mul = 2.54e-2;           alias Types.Distance type; }    /// 
    465 template Unit(string name : "foot")        { enum mul = 3.04799835e-1;     alias Types.Distance type; }    /// 
    466 template Unit(string name : "yard")        { enum mul = 9.14399506e-1;     alias Types.Distance type; }    /// 
    467 template Unit(string name : "mile")        { enum mul = 1.609343130e3;     alias Types.Distance type; }    /// 
    468 template Unit(string name : "parsec")  { enum mul = 3.085677473598e13; alias Types.Distance type; }    /// 
     487template Unit(string name : "Angstrom")    { enum mul = 1e-10;                alias Types.Distance type; } 
     488template Unit(string name : "Micron")    { enum mul = 1e-6;                alias Types.Distance type; }    /// 
     489template Unit(string name : "mm")        { enum mul = 1e-3;                alias Types.Distance type; }    /// 
     490template Unit(string name : "cm")        { enum mul = 1e-2;                alias Types.Distance type; }    /// 
     491template Unit(string name : "km")        { enum mul = 1e3;                alias Types.Distance type; }    /// 
     492template Unit(string name : "inch")        { enum mul = 2.54e-2;            alias Types.Distance type; }    /// 
     493template Unit(string name : "foot")        { enum mul = 3.04799835e-1;        alias Types.Distance type; }    /// 
     494template Unit(string name : "yard")        { enum mul = 9.14399506e-1;        alias Types.Distance type; }    /// 
     495template Unit(string name : "mile")        { enum mul = 1.609343130e3;        alias Types.Distance type; }    /// 
     496template Unit(string name : "parsec")    { enum mul = 3.085677473598e13;    alias Types.Distance type; }    /// 
    469497 
    470498/// Mass Unit Types 
    471 template Unit(string name : "gram")        { enum mul = 1e-3;              alias Types.Mass type; } 
    472 template Unit(string name : "lb")      { enum mul = 4.5359237e-1;      alias Types.Mass type; }    /// 
    473 template Unit(string name : "Ounce")   { enum mul = 2.834952e-2;       alias Types.Mass type; }    /// 
     499template Unit(string name : "gram")        { enum mul = 1e-3;                alias Types.Mass type; } 
     500template Unit(string name : "lb")        { enum mul = 4.5359237e-1;        alias Types.Mass type; }    /// 
     501template Unit(string name : "Ounce")    { enum mul = 2.834952e-2;        alias Types.Mass type; }    /// 
    474502 
    475503/// Time Unit Types 
    476 template Unit(string name : "minute")  { enum mul = 60.0;              alias Types.Time type; } 
    477 template Unit(string name : "hour")        { enum mul = 3600.0;            alias Types.Time type; }    /// 
    478 template Unit(string name : "day")     { enum mul = 86400.0;           alias Types.Time type; }    /// 
     504template Unit(string name : "minute")    { enum mul = 60.0;                alias Types.Time type; } 
     505template Unit(string name : "hour")        { enum mul = 3600.0;            alias Types.Time type; }    /// 
     506template Unit(string name : "day")        { enum mul = 86400.0;            alias Types.Time type; }    /// 
    479507 
    480508/// Temperature Unit Types 
    481 template Unit(string name : "R")       { enum mul = 0.5555555555;      alias Types.Temp type; } 
     509template Unit(string name : "R")        { enum mul = 0.5555555555;        alias Types.Temp type; } 
    482510 
    483511/// Force  Unit Types 
    484 template Unit(string name : "newton")  { enum mul = 1.0;               alias Types.Force type; } 
    485 template Unit(string name : "dyne")        { enum mul = 1e-5;              alias Types.Force type; }   /// 
    486 template Unit(string name : "lbf")     { enum mul = 4.44822246806;     alias Types.Force type; }   /// 
     512template Unit(string name : "newton")    { enum mul = 1.0;                alias Types.Force type; } 
     513template Unit(string name : "dyne")        { enum mul = 1e-5;                alias Types.Force type; }    /// 
     514template Unit(string name : "lbf")        { enum mul = 4.44822246806;        alias Types.Force type; }    /// 
    487515 
    488516/// Charge Unit Types 
    489 template Unit(string name : "coulomb") { enum mul = 1.0;               alias Types.Charge type; } 
     517template Unit(string name : "coulomb")    { enum mul = 1.0;                alias Types.Charge type; } 
    490518 
    491519/// Magnetic flux density 
    492 template Unit(string name : "tesla")       { enum mul = 1.0;               alias Types.MagneticFluxD type; } 
     520template Unit(string name : "tesla")        { enum mul = 1.0;                alias Types.MagneticFluxD type; } 
    493521 
    494522/// magnetic flux 
    495 template Unit(string name : "weber")       { enum mul = 1.0;               alias SI!(2,1,-2,0,1) type; } 
     523template Unit(string name : "weber")        { enum mul = 1.0;                alias SI!(2,1,-2,0,1) type; } 
    496524 
    497525/// inductance 
    498 template Unit(string name : "henry")       { enum mul = 1.0;               alias Types.Inductance type; } 
     526template Unit(string name : "henry")        { enum mul = 1.0;                alias Types.Inductance type; } 
    499527 
    500528/// Energy Unit Types 
    501 template Unit(string name : "joule")   { enum mul = 1.0;               alias Types.Energy type; } 
    502 template Unit(string name : "Erg")     { enum mul = 1e-7L;             alias Types.Energy type; }  /// 
    503 template Unit(string name : "cal")     { enum mul = 4.1868L;           alias Types.Energy type; }  /// 
    504 template Unit(string name : "eV")      { enum mul = 1.602176462e-19L;  alias Types.Energy type; }  /// 
    505 template Unit(string name : "BTU")     { enum mul = 1.0550558526e3L;   alias Types.Energy type; }  /// 
     529template Unit(string name : "joule")    { enum mul = 1.0;                alias Types.Energy type; } 
     530template Unit(string name : "Erg")        { enum mul = 1e-7L;                alias Types.Energy type; }    /// 
     531template Unit(string name : "cal")        { enum mul = 4.1868L;            alias Types.Energy type; }    /// 
     532template Unit(string name : "eV")        { enum mul = 1.602176462e-19L;    alias Types.Energy type; }    /// 
     533template Unit(string name : "BTU")        { enum mul = 1.0550558526e3L;    alias Types.Energy type; }    /// 
    506534 
    507535/// Voltage Unit Types 
    508 template Unit(string name : "volt")        { enum mul = 1.0;               alias Types.Voltage type; } 
     536template Unit(string name : "volt")        { enum mul = 1.0;                alias Types.Voltage type; } 
    509537 
    510538/// Frequency Unit Types 
    511 template Unit(string name : "hertz")       { enum mul = 1.0;               alias Types.Frequency type; } 
     539template Unit(string name : "hertz")        { enum mul = 1.0;                alias Types.Frequency type; } 
    512540 
    513541/// Resistance Unit Types 
    514 template Unit(string name : "ohm")     { enum mul = 1.0;               alias Types.Resistance type; } 
     542template Unit(string name : "ohm")        { enum mul = 1.0;                alias Types.Resistance type; } 
    515543 
    516544/// Pressure Unit Types 
    517 template Unit(string name : "pascal")      { enum mul = 1.0;               alias Types.Pressure type; } 
    518 template Unit(string name : "Bar")     { enum mul = 1e5L;              alias Types.Pressure type; }    /// 
    519 template Unit(string name : "Atm")     { enum mul = 1.01325e5L;        alias Types.Pressure type; }    /// 
    520 template Unit(string name : "psi")     { enum mul = 6.89475729e3;      alias Types.Pressure type; }    /// 
     545template Unit(string name : "pascal")        { enum mul = 1.0;                alias Types.Pressure type; } 
     546template Unit(string name : "Bar")        { enum mul = 1e5L;                alias Types.Pressure type; }    /// 
     547template Unit(string name : "Atm")        { enum mul = 1.01325e5L;        alias Types.Pressure type; }    /// 
     548template Unit(string name : "psi")        { enum mul = 6.89475729e3;        alias Types.Pressure type; }    /// 
    521549 
    522550/// Viscosity 
    523551// 
    524 template Unit(string name : "poise")   { enum mul = 0.1;               alias Types.Viscosity type; } 
     552template Unit(string name : "poise")    { enum mul = 0.1;                alias Types.Viscosity type; } 
    525553// 
    526 template Unit(string name : "stokes")  { enum mul = 0.0001;            alias Types.KViscosity type; } 
     554template Unit(string name : "stokes")    { enum mul = 0.0001;            alias Types.KViscosity type; } 
    527555 
    528556/// Power Unit Types 
    529 template Unit(string name : "watt")        { enum mul = 1.0;               alias Types.Power type; } 
    530 template Unit(string name : "kWatt")   { enum mul = 1000;              alias Types.Power type; }   /// 
    531 template Unit(string name : "Hp")      { enum mul = 745.69987158L;     alias Types.Power type; }   /// 
     557template Unit(string name : "watt")        { enum mul = 1.0;                alias Types.Power type; } 
     558template Unit(string name : "kWatt")    { enum mul = 1000;                alias Types.Power type; }    /// 
     559template Unit(string name : "Hp")        { enum mul = 745.69987158L;        alias Types.Power type; }    /// 
    532560 
    533561/// Volume Unit Types 
    534 template Unit(string name : "steres")  { enum mul = 1.0;               alias Types.Volume type; } 
    535 template Unit(string name : "litre")   { enum mul = 0.001L;            alias Types.Volume type; }  /// 
    536 template Unit(string name : "Gal")     { enum mul = 0.0037854120L;     alias Types.Volume type; }  /// 
    537 template Unit(string name : "Cup")     { enum mul = 0.0002365883L;     alias Types.Volume type; }  /// 
     562template Unit(string name : "steres")    { enum mul = 1.0;                alias Types.Volume type; } 
     563template Unit(string name : "litre")    { enum mul = 0.001L;            alias Types.Volume type; }    /// 
     564template Unit(string name : "Gal")        { enum mul = 0.0037854120L;        alias Types.Volume type; }    /// 
     565template Unit(string name : "Cup")        { enum mul = 0.0002365883L;        alias Types.Volume type; }    /// 
    538566 
    539567/// volume rate 
    540 template Unit(string name : "gpm")     { enum mul = 6.30901995e-5L;    alias Types.VolumeFlow type; } 
    541 template Unit(string name : "cfm")     { enum mul = 4.71947443e-4L;    alias Types.VolumeFlow type; }  /// 
     568template Unit(string name : "gpm")        { enum mul = 6.30901995e-5L;    alias Types.VolumeFlow type; } 
     569template Unit(string name : "cfm")        { enum mul = 4.71947443e-4L;    alias Types.VolumeFlow type; }    /// 
    542570 
    543571/// Speed Unit Types 
    544 template Unit(string name : "mps")     { enum mul = 1L;                alias Types.Speed type; } 
    545 template Unit(string name : "Knots")   { enum mul = 1.51444L;          alias Types.Speed type; }   /// 
    546 template Unit(string name : "mph")     { enum mul = 0.44704L;          alias Types.Speed type; }   /// 
    547 template Unit(string name : "kph")     { enum mul = 0.27778L;          alias Types.Speed type; }   /// 
    548 template Unit(string name : "fps")     { enum mul = 0.3048L;           alias Types.Speed type; }   /// 
     572template Unit(string name : "mps")        { enum mul = 1L;                alias Types.Speed type; } 
     573template Unit(string name : "Knots")    { enum mul = 1.51444L;            alias Types.Speed type; }    /// 
     574template Unit(string name : "mph")        { enum mul = 0.44704L;            alias Types.Speed type; }    /// 
     575template Unit(string name : "kph")        { enum mul = 0.27778L;            alias Types.Speed type; }    /// 
     576template Unit(string name : "fps")        { enum mul = 0.3048L;            alias Types.Speed type; }    /// 
    549577 
    550578/// Capacitance Unit Types 
    551 template Unit(string name : "farad")   { enum mul = 1.0;               alias Types.Capacitance type; } 
     579template Unit(string name : "farad")    { enum mul = 1.0;                alias Types.Capacitance type; } 
    552580 
    553581/// Area Unit Types 
    554 template Unit(string name : "Acre")        { enum mul = 4046.856421L;      alias Types.Area type; } 
     582template Unit(string name : "Acre")        { enum mul = 4046.856421L;        alias Types.Area type; } 
    555583 
    556584/// Acceleration Unit Types 
    557 template Unit(string name : "G")       { enum mul = 9.80665L;          alias Types.Acceleration type; } 
     585template Unit(string name : "G")        { enum mul = 9.80665L;            alias Types.Acceleration type; } 
    558586 
    559587/// alterant names 
     
    587615unittest 
    588616{ 
    589    writef("%s\n", OfType.foot(3.0).meter); 
    590  
    591    Types.Distance v;  //pragma(msg,"v:\t"~typeof(v).stringof); 
    592  
    593    auto v2 = v * v;  //pragma(msg,"v2:\t"~typeof(v2).stringof); 
    594    auto v3 = v2 / v; //pragma(msg,"v3:\t"~typeof(v3).stringof); 
    595    auto v4 = v / v;  //pragma(msg,"v4:\t"~typeof(v4).stringof); 
    596    real r = v4; 
    597    auto v5 = v4 / v; //pragma(msg,"v5:\t"~typeof(v5).stringof); 
    598    //auto v6a = v2 + v; 
    599    auto v6b = v3 + v; 
    600    auto v7 = v.Root!(2)(); //pragma(msg,"v7:\t"~typeof(v7).stringof); 
    601    auto v8 = v7.Pow!(4)(); //pragma(msg,"v8:\t"~typeof(v8).stringof); 
    602  
    603    Engr.FracturMechanics.StressIntensity k; 
    604    auto k2 = k*k; 
    605    auto p = OfType.psi(0.0L); 
    606    k2 = p*p*OfType.foot(3.0L); 
    607  
    608    auto newton = OfType.N(5); 
    609 } 
     617    writef("%s\n", OfType.foot(3.0).meter); 
     618 
     619    Types.Distance v;  //pragma(msg,"v:\t"~typeof(v).stringof); 
     620 
     621    auto v2 = v * v;  //pragma(msg,"v2:\t"~typeof(v2).stringof); 
     622    auto v3 = v2 / v; //pragma(msg,"v3:\t"~typeof(v3).stringof); 
     623    auto v4 = v / v;  //pragma(msg,"v4:\t"~typeof(v4).stringof); 
     624    real r = v4; 
     625    auto v5 = v4 / v; //pragma(msg,"v5:\t"~typeof(v5).stringof); 
     626    //auto v6a = v2 + v; 
     627    auto v6b = v3 + v; 
     628    auto v7 = v.Root!(2)(); //pragma(msg,"v7:\t"~typeof(v7).stringof); 
     629    auto v8 = v7.Pow!(4)(); //pragma(msg,"v8:\t"~typeof(v8).stringof); 
     630 
     631    Engr.FracturMechanics.StressIntensity k; 
     632    auto k2 = k*k; 
     633    auto p = OfType.psi(0.0L); 
     634    k2 = p*p*OfType.foot(3.0L); 
     635 
     636    auto newton = OfType.N(5); 
     637}