Changeset 458

Show
Ignore:
Timestamp:
10/20/08 20:31:21 (4 years ago)
Author:
BCS
Message:

added a few more constants
general cleanup
gut more digits for si.d conversion values
more types in Types
more op*'s in unit.d

Files:

Legend:

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

    r447 r458  
    1414    static const Types.Value gamma = { value : 0.577215664901532 }; 
    1515    /// good old pi 
    16     static const Types.Value pi = { value : 3.14159265359}; 
     16    static const Types.Value pi    = { value : 3.14159265359}; 
    1717    /// natural log base 
    18     static const Types.Value e = { value : 2.718281828459 }; 
     18    static const Types.Value e     = { value : 2.718281828459 }; 
    1919    /// golden ratio 
    20     static const Types.Value phi = { value : 1.6180339887498948482045868 }; 
     20    static const Types.Value phi   = { value : 1.6180339887498948482045868 }; 
    2121} 
    2222 
     
    2525{ 
    2626    /// unified atomic mass 
    27     static const Types.Mass u = { value : 1.66053873e-27 }; 
     27    static const Types.Mass   u = { value : 1.66053873e-27 }; 
    2828    /// electron mass 
    29     static const Types.Mass me = { value : 9.109373815276e-31 }; 
     29    static const Types.Mass   me = { value : 9.109373815276e-31 }; 
    3030    /// electron charge 
    31     static const Types.Charge e = { value : 1.602176462e-16 }; 
     31    static const Types.Charge e = { value : 1.602176462e-16 }; 
    3232    /// Proton mass 
    33     static const Types.Mass mp = { value : 1.67262158e-27 }; 
     33    static const Types.Mass   mp = { value : 1.67262158e-27 }; 
    3434    /// Neutron mass 
    35     static const Types.Mass mn = { value : 1.67492716e-27 }; 
     35    static const Types.Mass   mn = { value : 1.67492716e-27 }; 
    3636     
    3737} 
     
    4040struct Physical 
    4141{ 
     42    /// standard gravity 
     43    static const Types.Acceleration g    = { value : 9.81 }; 
    4244    /// 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 }; 
    4446    /// 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}; 
    4648    /// 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 }; 
    4850    /// 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}; 
    5052    /// speed of light 
    51     static const Types.Speed c = { value : 2.99792458e8 }; 
     53    static const Types.Speed       c    = { value : 2.99792458e8 }; 
    5254    /// 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 }; 
    5456    /// 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 }; 
    5658    /// Stefan-Boltzmann constant 
    5759    static const Lit!(4,-3,1,-4,0) sigma = { value : 5.670400e-8 }; 
    58      
    5960} 
    6061 
     
    6566    static const Types.Distance AU = { value :149.59787e11 }; 
    6667} 
     68 
     69/// 
     70struct 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  
    33template Tpl(T...){alias T Tpl;} 
    44 
     5/// 
    56uint gcd(int n, uint d) 
    67{ 
     
    1617static assert(7 == gcd(14,21)); 
    1718 
     19/// 
    1820template Reduce(int n, uint d) 
    1921{ 
     
    3739static assert(!Reduce!(-14,21).Reduced); 
    3840static 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  
    6161/// The set of unit defs 
    6262alias Tpl!(  
     63    `"value",    1.0, 0,0,0,0,0`, 
    6364    `"meter",    1.0, 1,0,0,0,0`, 
    6465    `"kilogram", 1.0, 0,1,0,0,0`, 
     
    8081     
    8182    /// Mass Unit Types 
    82     `"gram",  1e-3,       0,1,0,0,0`, 
    83     `"lb",    4.5359e-1,  0,1,0,0,0`, 
    84     `"Ounce", 2.83495e-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`, 
    8586     
    8687    /// Time Unit Types 
     
    112113    `"Joule", 1.0,              2,1,-2,0,0`, 
    113114    `"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`, 
    115116    `"eV",    1.602176462e-19L, 2,1,-2,0,0`, 
    116117     
     
    125126     
    126127    /// 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.895e3,    -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`, 
    131132     
    132133    /// Viscosity 
     
    138139    /// Power Unit Types 
    139140    `"Watt", 1.0,          2,1,-3,0,0`, 
    140     `"Hp",   745.69987L, 2,1,-3,0,0`, 
     141    `"Hp",   745.69987158L,2,1,-3,0,0`, 
    141142     
    142143    /// Volume Unit Types 
    143144    `"Steres", 1.0,          3,0,0,0,0`, 
    144145    `"Liter",  0.001L,       3,0,0,0,0`, 
    145     `"Gal",    0.0037854L,   3,0,0,0,0`, 
    146     `"Cup",    0.0002365875, 3,0,0,0,0`, 
     146    `"Gal",    0.0037854120L,3,0,0,0,0`, 
     147    `"Cup",    0.0002365883L,3,0,0,0,0`, 
    147148 
    148149    /// volume rate 
    149     `"gpm",    6.309e-5L,  3,0,-1,0,0`, 
    150     `"cfm",    4.719e-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`, 
    151152 
    152153    /// 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`, 
    156159     
    157160    /// Capacitance Unit Types 
  • trunk/units/types.d

    r447 r458  
    99 
    1010 
    11  
     11/// 
    1212public struct Types 
    1313{ 
    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;        /// 
    2020 
    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; /// 
    2322 
    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; /// 
    2525 
    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;  /// 
    2828 
    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;      /// 
    3231 
    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;       /// 
    3835 
    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;      /// 
    4144 
    4245} 
  • trunk/units/unit.d

    r447 r458  
    8383    } 
    8484 
     85    This opNeg() { This ret; ret.value = - this.value; return ret; } 
     86    This opPos() { return *this; } 
     87 
    8588    This opAdd(This that) { This ret; ret.value = this.value + that.value; return ret; } 
    8689    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    } 
    8799 
    88100    static if(LengthN == 0 && MassN == 0 && TimeN == 0 && TempN == 0 && CurrentN == 0) 
     
    90102        This opAdd(real that) { This ret; ret.value = this.value + that; return ret; } 
    91103        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; } 
    92106        This opAdd_r(real that) { This ret; ret.value = that + this.value; return ret; } 
    93107        This opSub_r(real that) { This ret; ret.value = that - this.value; return ret; }