Changeset b3796fa in sasmodels


Ignore:
Timestamp:
Aug 4, 2016 12:11:51 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
38ce0ab
Parents:
4fd2c63
Message:

Allow use of cephes erf() even if erf() is available in the math library

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernel_header.c

    redf06e1 rb3796fa  
    1515#  endif 
    1616   // OpenCL only has type generic math 
     17   #define expf exp 
    1718   #define erff erf 
    1819   #define erfcf erfc 
     20   // Intel CPU on Mac gives strange values for erf(), so maybe don't use it 
     21   //#define NEED_ERF 
    1922#else // !USE_OPENCL 
    2023// Use SAS_DOUBLE to force the use of double even for float kernels 
     
    123126#  define M_E 2.718281828459045091 
    124127#endif 
     128#ifndef M_SQRT1_2 
     129#  define M_SQRT1_2 0.70710678118654746 
     130#endif 
    125131 
    126132// Non-standard function library 
  • sasmodels/models/lib/sas_erf.c

    redf06e1 rb3796fa  
    8989 
    9090#if FLOAT_SIZE>4  // DOUBLE_PRECISION 
    91 double erf(double x); 
    92 double erfc(double a); 
     91 
     92double cephes_erf(double x); 
     93double cephes_erfc(double a); 
    9394 
    9495constant double PD[] = { 
     
    152153}; 
    153154 
    154 double erfc(double a) 
     155double cephes_erfc(double a) 
    155156{ 
    156157    double MAXLOG = 88.72283905206835; 
     
    158159 
    159160 
    160     /*if (a < 0.0) 
    161         x = -a; 
    162     else 
    163         x = a;*/ 
    164  
    165161    x = fabs(a); 
    166162 
    167  
    168163    if (x < 1.0) { 
    169         //The line bellow is a troublemaker for GPU, so sas_erf function 
    170         //is explicit here for the case < 1.0 
    171         //return (1.0 - sas_erf(a)); 
     164        // The line below causes problems on the GPU, so inline 
     165        // the erf function instead and z < 1.0. 
     166        //return (1.0 - cephes_erf(a)); 
    172167        z = x * x; 
    173168        y = x * polevl(z, TD, 4) / p1evl(z, UD, 5); 
     
    211206 
    212207 
    213 double erf(double x) 
     208double cephes_erf(double x) 
    214209{ 
    215210    double y, z; 
    216211 
    217212    if (fabs(x) > 1.0) 
    218         return (1.0 - erfc(x)); 
     213        return (1.0 - cephes_erfc(x)); 
    219214 
    220215    z = x * x; 
    221     #if FLOAT_SIZE>4 
    222         y = x * polevl(z, TD, 4) / p1evl(z, UD, 5); 
    223     #else 
    224         y = x * polevl( z, TF, 6 ); 
    225     #endif 
     216    y = x * polevl(z, TD, 4) / p1evl(z, UD, 5); 
    226217 
    227218    return y; 
     
    230221#else // SINGLE PRECISION 
    231222 
    232 double erff(double x); 
    233 double erfcf(double a); 
     223float cephes_erff(float x); 
     224float cephes_erfcf(float a); 
    234225 
    235226/* erfc(x) = exp(-x^2) P(1/x), 1 < x < 2 */ 
    236 constant double PF[] = { 
     227constant float PF[] = { 
    237228    2.326819970068386E-002, 
    238229    -1.387039388740657E-001, 
     
    247238 
    248239/* erfc(x) = exp(-x^2) 1/x P(1/x^2), 2 < x < 14 */ 
    249 constant double RF[] = { 
     240constant float RF[] = { 
    250241    -1.047766399936249E+001, 
    251242    1.297719955372516E+001, 
     
    259250 
    260251/* erf(x) = x P(x^2), 0 < x < 1 */ 
    261  constant double TF[] = { 
     252 constant float TF[] = { 
    262253    7.853861353153693E-005, 
    263254    -8.010193625184903E-004, 
     
    270261 
    271262 
    272 float erfcf(float a) 
     263float cephes_erfcf(float a) 
    273264{ 
    274265    float MAXLOG = 88.72283905206835; 
     
    327318 
    328319 
    329 float erff(float x) 
     320float cephes_erff(float x) 
    330321{ 
    331322    float y, z; 
     
    333324    // TODO: tinycc does not support fabsf 
    334325    if (fabs(x) > 1.0) 
    335         return (1.0 - erfcf(x)); 
     326        return (1.0 - cephes_erfcf(x)); 
    336327 
    337328    z = x * x; 
     
    342333 
    343334#endif // SINGLE_PRECISION 
    344 #endif // NEED_ERF 
    345335 
    346336#if FLOAT_SIZE>4 
     337//static double sas_erf(double x) { return erf(x); } 
     338//static double sas_erfc(double x) { return erfc(x); } 
     339#define sas_erf cephes_erf 
     340#define sas_erfc cephes_erfc 
     341#else 
     342#define sas_erf cephes_erff 
     343#define sas_erfc cephes_erfcf 
     344#endif 
     345 
     346#else // !NEED_ERF 
     347 
     348#if FLOAT_SIZE>4 
     349//static double sas_erf(double x) { return erf(x); } 
     350//static double sas_erfc(double x) { return erfc(x); } 
    347351#define sas_erf erf 
    348352#define sas_erfc erfc 
     
    351355#define sas_erfc erfcf 
    352356#endif 
     357#endif // !NEED_ERF 
Note: See TracChangeset for help on using the changeset viewer.