Changeset 160 for trunk/meta/demo

Show
Ignore:
Timestamp:
03/09/06 08:25:20 (3 years ago)
Author:
Don Clugston
Message:

Many accumulated changes to 'meta'. The most interesting is the one in feqtest, which tests floating point numbers for equality to the number of decimal places given in a string.

Files:

Legend:

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

    r115 r160  
    77import meta.math; 
    88import meta.conv; 
    9  
    10 import std.math; 
    119 
    1210/** real evaluateSeries!(real x, real metafunction!(real y, int n) term) 
     
    2624     const real evaluateSeries = sumsofar; 
    2725  } else { 
    28      const real evaluateSeries = .evaluateSeries!(x, term, n+1, sumsofar + term!(x, n)); 
     26     const real evaluateSeries = evaluateSeries!(x, term, n+1, sumsofar + term!(x, n)); 
    2927  } 
    3028} 
  • trunk/meta/demo/tabledemo.d

    r126 r160  
    33// Create a constant array of long or ulong-sized items. Needs to be cast back to 
    44// long[] or ulong[]. 
    5 template generateArray(alias entry, int n) 
     5template generateArrayAsChar(alias entry, int n) 
    66{ 
    77  static if ( entry!(0).sizeof == dchar.sizeof) { 
    88      // int or uint sized items 
    99      static if (n==0) { 
    10         const dchar [] generateArray = ""d  ~ cast(dchar)entry!(n); 
     10        const dchar [] generateArrayAsChar = ""d  ~ cast(dchar)entry!(n); 
    1111      } else { 
    12         const dchar[] generateArray = generateArray!(entry, n-1) ~ cast(dchar)entry!(n); 
     12        const dchar[] generateArrayAsChar = generateArrayAsChar!(entry, n-1) ~ cast(dchar)entry!(n); 
    1313      } 
    1414  } else static if ( entry!(0).sizeof == 2*dchar.sizeof) { 
    1515      // long or ulong sized items 
    1616      static if (n==0) { 
    17         const dchar [] generateArray = ""d   
     17        const dchar [] generateArrayAsChar = ""d   
    1818                ~ cast(dchar)entry!(n) ~ cast(dchar)(entry!(n)>>>32); 
    1919      } else { 
    20         const dchar[] generateArray = generateArray!(entry, n-1) 
     20        const dchar[] generateArrayAsChar = generateArrayAsChar!(entry, n-1) 
    2121            ~ cast(dchar)entry!(n)  ~ cast(dchar)(entry!(n)>>32); 
    2222      } 
     
    2424} 
    2525 
     26template generateArray(alias entry, int n) 
     27{ 
     28  const typeof(entry!(0)) [] generateArray = cast(typeof(entry!(0)) [])generateArrayAsChar!(entry, n); 
     29} 
     30 
     31// The ubiquitous factorial function 
     32// 
    2633// Returns correct value for n=0 (factorial!(0)=1). 
    2734template factorial(int n) 
    2835{ 
    29   static if (n<2) const ulong factorial = 1; 
    30   else const ulong factorial = n * .factorial!(n-1); 
     36  static if (n<2) const uint factorial = 1; 
     37  else const uint factorial = n * factorial!(n-1); 
    3138} 
    3239 
     40// Make an array of all the factorials from 0 to 13 (14!> ulong.max) 
     41const smallfactorials = generateArray!(factorial, 13); 
    3342 
     43 
     44/+ 
    3445// Make an array of all the factorials from 0 to 20 (21!> ulong.max) 
    3546const ulong [] smallfactorials; 
    36  
    3747static this() 
    3848{ 
    39     smallfactorials = cast(ulong []) generateArray!(factorial, 20); 
     49    smallfactorials = cast(uint []) generateArrayAsChar!(factorial, 20); 
    4050} 
    41  
     51+/ 
    4252import std.stdio; 
    4353 
    44 int main() 
     54void main() 
    4555{ 
    4656  for (int i=0; i<smallfactorials.length; ++i) { 
    4757     writefln(i, "  ", smallfactorials[i]); 
    4858  } 
    49  return 0; 
    5059} 
    51  
    52 /+ 
    53 // ---------- array literals version ----------- 
    54  
    55 template generateArray(alias entry, int n) 
    56 { 
    57     static if (n==0) { 
    58         const typeof(entry!(0)) [] generateArray = [ entry!(n) ]; 
    59     } else { 
    60         const typeof(entry!(0)) [] generateArray = generateArray!(entry, n-1) ~ [ entry!(n) ]; 
    61     } 
    62 } 
    63  
    64 const smallfactorials = generateArray!(factorial, 20); 
    65 +/