ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change
on this file since b9a5f0e was
79492222,
checked in by krzywon, 10 years ago
|
Changed the file and folder names to remove all SANS references.
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Rev | Line | |
---|
[230f479] | 1 | /* expx2.c |
---|
| 2 | * |
---|
| 3 | * Exponential of squared argument |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * |
---|
| 7 | * SYNOPSIS: |
---|
| 8 | * |
---|
| 9 | * double x, y, expx2(); |
---|
| 10 | * int sign; |
---|
| 11 | * |
---|
| 12 | * y = expx2( x, sign ); |
---|
| 13 | * |
---|
| 14 | * |
---|
| 15 | * |
---|
| 16 | * DESCRIPTION: |
---|
| 17 | * |
---|
| 18 | * Computes y = exp(x*x) while suppressing error amplification |
---|
| 19 | * that would ordinarily arise from the inexactness of the |
---|
| 20 | * exponential argument x*x. |
---|
| 21 | * |
---|
| 22 | * If sign < 0, the result is inverted; i.e., y = exp(-x*x) . |
---|
| 23 | * |
---|
| 24 | * |
---|
| 25 | * ACCURACY: |
---|
| 26 | * |
---|
| 27 | * Relative error: |
---|
| 28 | * arithmetic domain # trials peak rms |
---|
| 29 | * IEEE -26.6, 26.6 10^7 3.9e-16 8.9e-17 |
---|
| 30 | * |
---|
| 31 | */ |
---|
| 32 | |
---|
| 33 | /* |
---|
| 34 | Cephes Math Library Release 2.9: June, 2000 |
---|
| 35 | Copyright 2000 by Stephen L. Moshier |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "mconf.h" |
---|
| 39 | |
---|
| 40 | #ifdef ANSIPROT |
---|
| 41 | extern double fabs (double); |
---|
| 42 | extern double floor (double); |
---|
| 43 | extern double exp (double); |
---|
| 44 | #else |
---|
| 45 | double fabs(); |
---|
| 46 | double floor(); |
---|
| 47 | double exp(); |
---|
| 48 | #endif |
---|
| 49 | |
---|
| 50 | #ifdef DEC |
---|
| 51 | #define M 32.0 |
---|
| 52 | #define MINV .03125 |
---|
| 53 | #else |
---|
| 54 | #define M 128.0 |
---|
| 55 | #define MINV .0078125 |
---|
| 56 | #endif |
---|
| 57 | |
---|
| 58 | extern double MAXLOG; |
---|
| 59 | extern double INFINITY; |
---|
| 60 | |
---|
| 61 | double expx2 (x, sign) |
---|
| 62 | double x; |
---|
| 63 | int sign; |
---|
| 64 | { |
---|
| 65 | double u, u1, m, f; |
---|
| 66 | |
---|
| 67 | x = fabs (x); |
---|
| 68 | if (sign < 0) |
---|
| 69 | x = -x; |
---|
| 70 | |
---|
| 71 | /* Represent x as an exact multiple of M plus a residual. |
---|
| 72 | M is a power of 2 chosen so that exp(m * m) does not overflow |
---|
| 73 | or underflow and so that |x - m| is small. */ |
---|
| 74 | m = MINV * floor(M * x + 0.5); |
---|
| 75 | f = x - m; |
---|
| 76 | |
---|
| 77 | /* x^2 = m^2 + 2mf + f^2 */ |
---|
| 78 | u = m * m; |
---|
| 79 | u1 = 2 * m * f + f * f; |
---|
| 80 | |
---|
| 81 | if (sign < 0) |
---|
| 82 | { |
---|
| 83 | u = -u; |
---|
| 84 | u1 = -u1; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | if ((u+u1) > MAXLOG) |
---|
| 88 | return (INFINITY); |
---|
| 89 | |
---|
| 90 | /* u is exact, u1 is small. */ |
---|
| 91 | u = exp(u) * exp(u1); |
---|
| 92 | return(u); |
---|
| 93 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.