Show
Ignore:
Timestamp:
08/24/10 23:09:37 (1 year ago)
Author:
BCS
Message:

detab

Files:

Legend:

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

    r783 r784  
    3434uint gcd(int n, uint d) 
    3535{ 
    36    if(n < 0) n = -n; 
    37    while(d) 
    38    
    39        int t = d; 
    40        d = n%d; 
    41        n = t; 
    42    
    43    return n; 
     36    if(n < 0) n = -n; 
     37    while(d) 
     38   
     39        int t = d; 
     40        d = n%d; 
     41        n = t; 
     42   
     43    return n; 
    4444} 
    4545static assert(7 == gcd(14,21)); 
     
    4848template Reduce(int n, uint d) 
    4949{ 
    50    static assert(d != 0); 
    51    static if(n != 0) 
    52    
    53        //pragma(msg,n.stringof~"/"~d.stringof); 
    54        const int N =  n / cast(int)gcd(n,d); 
    55        const int D = cast(uint)(d / gcd(n,d)); 
    56        const bool Reduced = (gcd(n,d) == 1); 
    57    
    58    else 
    59    
    60        const int N =  0; 
    61        const int D = 1; 
    62        const bool Reduced = (D == 1); 
    63    
    64    alias Tpl!(N,D) V; 
     50    static assert(d != 0); 
     51    static if(n != 0) 
     52   
     53        //pragma(msg,n.stringof~"/"~d.stringof); 
     54        const int N =  n / cast(int)gcd(n,d); 
     55        const int D = cast(uint)(d / gcd(n,d)); 
     56        const bool Reduced = (gcd(n,d) == 1); 
     57   
     58    else 
     59   
     60        const int N =  0; 
     61        const int D = 1; 
     62        const bool Reduced = (D == 1); 
     63   
     64    alias Tpl!(N,D) V; 
    6565} 
    6666