Changeset 27

Show
Ignore:
Timestamp:
12/07/05 03:26:34 (3 years ago)
Author:
Don Clugston
Message:

Added archetype!(A) to complex.d, in preparation for some template versions of mathematical functions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/complex.d

    r25 r27  
    4545 real log(real x) { return std.math.log(x); } 
    4646 real atan(real x) { return std.math.atan(x); } 
    47  
    48 /*******************************************  
     47  
     48/******************************************* 
     49  * The highest precision type with the same semantics. 
     50  * 
     51  * Given a type A, returns a type which is identical but with the highest precision. 
     52  * eg, for uint, returns ulong, for float, returns real. 
     53  */ 
     54template archetype(A) 
     55{  alias A archetype; } 
     56 
     57template archetype(A : float) 
     58{  alias real archetype; } 
     59 
     60template archetype(A: double) 
     61{  alias real archetype; } 
     62 
     63template archetype(A: short) 
     64{  alias int archetype; } 
     65 
     66template archetype(A: ushort) 
     67{  alias uint archetype; } 
     68 
     69template archetype(A: int) 
     70{  alias long archetype; } 
     71 
     72template archetype(A: uint) 
     73{  alias ulong archetype; } 
     74 
     75template archetype(A: bit) 
     76{  alias int archetype; } 
     77 
     78 
     79/******************************************* 
    4980 * Absolute value 
    5081 * 
     
    117148 * Exponential, complex and imaginary 
    118149 * 
     150 * For complex numbers, the exponential function is defined as 
     151 * 
    119152 *  exp(x+iy) = exp(x)cos(y) + exp(x)sin(y)i. 
    120153 * 
     
    172205  return mod * exp(1i*phase); 
    173206} 
     207 
     208// It would also be possible to optimise the special cases... 
     209//  pow(real, creal), pow(real, ireal), 
     210//  pow(ireal, creal), pow(ireal, real), pow(ireal, ireal) 
     211//  pow(creal, real), pow(creal, ireal) 
     212// This is probably unnecessary, but could be done with templates. 
    174213 
    175214/******************************************* 
     
    209248  return p; 
    210249} 
    211  
    212250 
    213251/******************************************* 
     
    280318 assert(asinh(-real.infinity)==-real.infinity); 
    281319 assert(isnan(asinh(real.nan))); 
    282   
    283   version (X86_NO) { 
    284      assert( consistencyRealInverse(&asinh, &sinh,-double.max, double.max) >= double.mant_dig); 
    285      assert( consistencyRealInverse(&asinh, &sinh,-1, 1) >= real.mant_dig-2); 
    286      assert( consistencyRealInverse(&sinh, &asinh,  
    287              -log(real.max)*(1+real.epsilon), log(real.max)*(1-real.epsilon) 
    288              )>= double.mant_dig); 
    289  } 
    290   
    291320} 
    292321 
     
    318347  assert(acosh(1)==0.0); 
    319348  assert(acosh(real.infinity) == real.infinity); 
    320     version (X86_NO) { 
    321   assert( consistencyRealInverse(&acosh, &cosh, 1, double.max) 
    322              >= double.mant_dig); 
    323   assert( consistencyRealInverse(&cosh, &acosh, 1, log(real.max)*(1-real.epsilon)) 
    324              >= real.mant_dig-1); 
    325     } 
    326349} 
    327350 
     
    351374 assert(isnan(atanh(real.nan))); 
    352375 assert(isNegZero(atanh(-real.infinity)));  
    353     version (X86_NO) { 
    354  assert( consistencyRealInverse(&atanh, &tanh, -1, 1) 
    355          >= real.mant_dig-2); 
    356  assert( consistencyRealInverse(&tanh, &atanh, -1,1) 
    357          >= real.mant_dig-1); 
    358     } 
    359376} 
    360377 
  • trunk/docs/bitoperations.html

    r25 r27  
    1616</dd> 
    1717<dt><big>int <u>bitcount</u>(uint <i>x</i>); 
    18 <br>int <u>bitcount</u>(ulong <i>x</i>); 
    1918</big></dt> 
    2019<dd>Calculates the number of set bits in a 32-bit integer. 
  • trunk/docs/complex.html

    r25 r27  
    2121<br><br> 
    2222 
    23 <dl><dt><big>real <u>abs</u>(real <i>x</i>); 
     23<dl><dt><big>template <u>archetype</u>(A)</big></dt> 
     24<dd>The highest precision type with the same semantics. 
     25<br><br> 
     26Given a type A, returns a type which is identical but with the highest precision. 
     27 eg, for uint, returns ulong, for float, returns real. 
     28   
     29<br><br> 
     30 
     31<dl></dl> 
     32</dd> 
     33<dt><big>real <u>abs</u>(real <i>x</i>); 
    2434<br>long <u>abs</u>(long <i>x</i>); 
    2535<br>int <u>abs</u>(int <i>x</i>); 
     
    5464<dd>Exponential, complex and imaginary 
    5565<br><br> 
    56 <u>exp</u>(x+iy) = <u>exp</u>(x)cos(<i>y</i>) + <u>exp</u>(x)sin(<i>y</i>)i. 
     66For complex numbers, the exponential function is defined as 
     67<br><br> 
     68 
     69  <u>exp</u>(x+iy) = <u>exp</u>(x)cos(<i>y</i>) + <u>exp</u>(x)sin(<i>y</i>)i. 
    5770<br><br> 
    5871 
  • trunk/testconsistency.d

    r25 r27  
    7070} 
    7171 
     72unittest { // asinh 
     73     assert( consistencyRealInverse(&asinh, &sinh,-double.max, double.max) >= double.mant_dig); 
     74     assert( consistencyRealInverse(&asinh, &sinh,-1, 1) >= real.mant_dig-2); 
     75     assert( consistencyRealInverse(&sinh, &asinh,  
     76             -log(real.max)*(1+real.epsilon), log(real.max)*(1-real.epsilon) 
     77             )>= double.mant_dig); 
     78} 
     79 
     80unittest { // acosh 
     81  assert( consistencyRealInverse(&acosh, &cosh, 1, double.max) 
     82             >= double.mant_dig); 
     83  assert( consistencyRealInverse(&cosh, &acosh, 1, log(real.max)*(1-real.epsilon)) 
     84             >= real.mant_dig-1); 
     85} 
     86 
     87unittest { // atanh 
     88 assert( consistencyRealInverse(&atanh, &tanh, -1, 1) 
     89         >= real.mant_dig-2); 
     90 assert( consistencyRealInverse(&tanh, &atanh, -1,1) 
     91         >= real.mant_dig-1); 
     92} 
     93 
    7294int main() 
    7395{