Changeset 115
- Timestamp:
- 01/16/06 00:36:22 (3 years ago)
- Files:
-
- trunk/meta/conv.d (modified) (4 diffs)
- trunk/meta/demo/calcpi.d (modified) (2 diffs)
- trunk/meta/strhacks.d (modified) (3 diffs)
- trunk/meta/string.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/meta/conv.d
r114 r115 45 45 static if (s.length==indx) const long atoi=sofar; 46 46 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; 48 48 else const long atoi = .atoi!(s, sofar * 10 + s[indx]-'0', indx+1); 49 49 } … … 58 58 } else static if (indx==0 && s[indx]=='-') { 59 59 const int countleadingdigits = .countleadingdigits!(s, indx+1); 60 } else static if (!isdigit!( cast(char)s[indx])) {60 } else static if (!isdigit!( (s[indx]) )) { 61 61 const int countleadingdigits=indx; 62 62 } else { … … 66 66 67 67 /* ***************************** 68 * int sig figs!(char [] s)68 * int sigFigs!(char [] s) 69 69 * 70 70 * Returns the number of significant figures in the decimal number s. 71 71 */ 72 template sig figs(char [] s, int p=0)72 template sigFigs(char [] s, int p=0) 73 73 { 74 74 static if ( s.length ==p ) { 75 const int sig figs=0;75 const int sigFigs=0; 76 76 } else static if ( s[p]=='.'|| (p==0 && s[p]=='-') ) { 77 const int sig figs = .sigfigs!(s, p+1);78 }else static if ( isdigit!( cast(char)s[p]) ) {79 const int sig figs = 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); 80 80 } else static if ( s[p]=='e' || s[p]=='E' ) { 81 81 // abort once we reach the exponent 82 const int sig figs=0;82 const int sigFigs=0; 83 83 } else { 84 84 static assert(0); // invalid character in string … … 138 138 static assert( countleadingdigits!("325827wip")==6); 139 139 static assert( countleadingdigits!("abc")==0); 140 static assert( sig figs!("1.2500")==5);141 static assert( sig figs!("-380.0")==4);142 static assert( sig figs!("0")==1);143 static assert( sig figs!("-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); 144 144 } trunk/meta/demo/calcpi.d
r93 r115 7 7 import meta.math; 8 8 import meta.conv; 9 10 import std.math; 9 11 10 12 /** real evaluateSeries!(real x, real metafunction!(real y, int n) term) … … 35 37 template atan(real z) 36 38 { 37 const real atan = evaluateSeries!(z, atanTerm);39 const real atan = evaluateSeries!(z, atanTerm); 38 40 } 39 41 40 42 template atanTerm(real x, int n) 41 43 { 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); 47 45 } 48 46 49 47 /// Machin's formula for pi 50 48 /// 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))) );49 pragma(msg, "PI = " ~ fcvt!(4.0 * (4*atan!(1/5.0) - atan!(1/239.0))) ); 52 50 trunk/meta/strhacks.d
r114 r115 1 /** Workarounds required for DMD 0.14 21 /** Workarounds required for DMD 0.143 2 2 * 3 3 * Most of these are only required when they are used as a template value parameter. 4 4 */ 5 5 module 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 }16 6 17 7 // return true if str1 == str2/ … … 56 46 // Workarounds required for DMD 0.141, fixed for DMD 0.142 57 47 48 template 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 56 template 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 58 64 /// = str[from..to] 59 65 template slice(char [] str, int from, int to) … … 80 86 } 81 87 82 //-----------------------------------------------------------------trunk/meta/string.d
r114 r115 1 1 2 2 module meta.string; 3 import meta.strhacks;3 private import meta.strhacks; 4 4 5 5 // Returns str[] sans trailing delimiter[], if any.
