Changeset 27
- Timestamp:
- 12/07/05 03:26:34 (3 years ago)
- Files:
-
- trunk/complex.d (modified) (7 diffs)
- trunk/docs/bitoperations.html (modified) (1 diff)
- trunk/docs/complex.html (modified) (2 diffs)
- trunk/testconsistency.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/complex.d
r25 r27 45 45 real log(real x) { return std.math.log(x); } 46 46 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 */ 54 template archetype(A) 55 { alias A archetype; } 56 57 template archetype(A : float) 58 { alias real archetype; } 59 60 template archetype(A: double) 61 { alias real archetype; } 62 63 template archetype(A: short) 64 { alias int archetype; } 65 66 template archetype(A: ushort) 67 { alias uint archetype; } 68 69 template archetype(A: int) 70 { alias long archetype; } 71 72 template archetype(A: uint) 73 { alias ulong archetype; } 74 75 template archetype(A: bit) 76 { alias int archetype; } 77 78 79 /******************************************* 49 80 * Absolute value 50 81 * … … 117 148 * Exponential, complex and imaginary 118 149 * 150 * For complex numbers, the exponential function is defined as 151 * 119 152 * exp(x+iy) = exp(x)cos(y) + exp(x)sin(y)i. 120 153 * … … 172 205 return mod * exp(1i*phase); 173 206 } 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. 174 213 175 214 /******************************************* … … 209 248 return p; 210 249 } 211 212 250 213 251 /******************************************* … … 280 318 assert(asinh(-real.infinity)==-real.infinity); 281 319 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 291 320 } 292 321 … … 318 347 assert(acosh(1)==0.0); 319 348 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 }326 349 } 327 350 … … 351 374 assert(isnan(atanh(real.nan))); 352 375 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 }359 376 } 360 377 trunk/docs/bitoperations.html
r25 r27 16 16 </dd> 17 17 <dt><big>int <u>bitcount</u>(uint <i>x</i>); 18 <br>int <u>bitcount</u>(ulong <i>x</i>);19 18 </big></dt> 20 19 <dd>Calculates the number of set bits in a 32-bit integer. trunk/docs/complex.html
r25 r27 21 21 <br><br> 22 22 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> 26 Given 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>); 24 34 <br>long <u>abs</u>(long <i>x</i>); 25 35 <br>int <u>abs</u>(int <i>x</i>); … … 54 64 <dd>Exponential, complex and imaginary 55 65 <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. 66 For 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. 57 70 <br><br> 58 71 trunk/testconsistency.d
r25 r27 70 70 } 71 71 72 unittest { // 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 80 unittest { // 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 87 unittest { // 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 72 94 int main() 73 95 {
