Changeset 115

Show
Ignore:
Timestamp:
01/16/06 00:36:22 (3 years ago)
Author:
Don Clugston
Message:

Meta: Folded in DMD 0.143 changes (fewer workarounds required). Regex still needs to be updated.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/meta/conv.d

    r114 r115  
    4545  static if (s.length==indx) const long atoi=sofar; 
    4646  else static if (indx==0 && s[indx]=='-') const long atoi = -.atoi!(s, 0, 1); 
    47   else static if (!isdigit!( cast(char) s[indx] ) ) const long atoi = sofar; 
     47  else static if (!isdigit!( (s[indx]) ) ) const long atoi = sofar; 
    4848  else const long atoi = .atoi!(s, sofar * 10 + s[indx]-'0', indx+1); 
    4949} 
     
    5858    } else static if (indx==0 && s[indx]=='-')  { 
    5959        const int countleadingdigits = .countleadingdigits!(s, indx+1); 
    60     } else static if (!isdigit!( cast(char)s[indx] )) { 
     60    } else static if (!isdigit!( (s[indx]) )) { 
    6161        const int countleadingdigits=indx; 
    6262    } else { 
     
    6666 
    6767/* ***************************** 
    68  *  int sigfigs!(char [] s) 
     68 *  int sigFigs!(char [] s) 
    6969 * 
    7070 * Returns the number of significant figures in the decimal number s. 
    7171 */ 
    72 template sigfigs(char [] s, int p=0) 
     72template sigFigs(char [] s, int p=0) 
    7373{ 
    7474    static if ( s.length ==p ) { 
    75         const int sigfigs=0; 
     75        const int sigFigs=0; 
    7676    } else static if ( s[p]=='.'|| (p==0 && s[p]=='-') ) { 
    77         const int sigfigs = .sigfigs!(s, p+1); 
    78     }else static if ( isdigit!(cast(char)s[p]) ) { 
    79         const int sigfigs = 1 + .sigfigs!(s, p+1); 
     77        const int sigFigs = .sigFigs!(s, p+1); 
     78    }else static if ( isdigit!((s[p])) ) { 
     79        const int sigFigs = 1 + .sigFigs!(s, p+1); 
    8080    } else static if ( s[p]=='e' || s[p]=='E' ) { 
    8181        // abort once we reach the exponent 
    82         const int sigfigs=0; 
     82        const int sigFigs=0; 
    8383    } else { 
    8484        static assert(0); // invalid character in string 
     
    138138 static assert( countleadingdigits!("325827wip")==6); 
    139139 static assert( countleadingdigits!("abc")==0); 
    140  static assert( sigfigs!("1.2500")==5); 
    141  static assert( sigfigs!("-380.0")==4); 
    142  static assert( sigfigs!("0")==1); 
    143  static assert( sigfigs!("-1.20e49")==3); 
     140 static assert( sigFigs!("1.2500")==5); 
     141 static assert( sigFigs!("-380.0")==4); 
     142 static assert( sigFigs!("0")==1); 
     143 static assert( sigFigs!("-1.20e49")==3); 
    144144} 
  • trunk/meta/demo/calcpi.d

    r93 r115  
    77import meta.math; 
    88import meta.conv; 
     9 
     10import std.math; 
    911 
    1012/** real evaluateSeries!(real x, real metafunction!(real y, int n) term) 
     
    3537template atan(real z) 
    3638{ 
    37   const real atan = evaluateSeries!(z, atanTerm); 
     39   const real atan = evaluateSeries!(z, atanTerm); 
    3840} 
    3941 
    4042template atanTerm(real x, int n) 
    4143{ 
    42    static if (n&1) { 
    43      const real atanTerm =  pow!(x, 2*n-1)/(2*n-1); 
    44    } else { 
    45      const real atanTerm =  -pow!(x, 2*n-1)/(2*n-1); 
    46    } 
     44    const real atanTerm =  (n & 1 ? 1 : -1) * pow!(x, 2*n-1)/(2*n-1); 
    4745} 
    4846 
    4947/// Machin's formula for pi 
    5048/// pi/4 = 4 atan(1/5) - atan(1/239). 
    51 pragma(msg, "PI = " ~ fcvt!(4.0 * (4*.atan!(1/5.0) - .atan!(1/239.0))) ); 
     49pragma(msg, "PI = " ~ fcvt!(4.0 * (4*atan!(1/5.0) - atan!(1/239.0))) ); 
    5250 
  • trunk/meta/strhacks.d

    r114 r115  
    1 /** Workarounds required for DMD 0.142 
     1/** Workarounds required for DMD 0.143 
    22 * 
    33 * Most of these are only required when they are used as a template value parameter. 
    44 */ 
    55module meta.strhacks; 
    6  
    7 template strlen(char [] str) 
    8 { 
    9   const int strlen = str.length; 
    10 } 
    11  
    12 template concat(char [] str1, char [] str2) 
    13 { 
    14   const char [] concat = str1 ~ str2; 
    15 } 
    166 
    177// return true if str1 == str2/ 
     
    5646// Workarounds required for DMD 0.141, fixed for DMD 0.142 
    5747 
     48template strlen(char [] str) 
     49{ 
     50  const int strlen = str.length; 
     51} 
     52 
     53//----------------------------------------------------------------- 
     54//   Workarounds for DMD 0.142, fixed in DMD 0.143 
     55 
     56template concat(char [] str1, char [] str2) 
     57{ 
     58  const char [] concat = str1 ~ str2; 
     59} 
     60 
     61//----------------------------------------------------------------- 
     62//   Workarounds for DMD 0.141, almost work in DMD 0.143 (need to add parentheses) 
     63 
    5864///  = str[from..to] 
    5965template slice(char [] str, int from, int to) 
     
    8086} 
    8187 
    82 //----------------------------------------------------------------- 
  • trunk/meta/string.d

    r114 r115  
    11 
    22module meta.string; 
    3 import meta.strhacks; 
     3private import meta.strhacks; 
    44 
    55// Returns str[] sans trailing delimiter[], if any.