Changeset 70530778 in sasmodels


Ignore:
Timestamp:
Aug 23, 2018 6:38:30 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
c11d09f
Parents:
0168844
Message:

avoid cancellation error causing NaN values to appear in 2D patterns

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernel_iq.c

    r7c35fda r70530778  
    8484  out_spin = clip(out_spin, 0.0, 1.0); 
    8585  // Previous version of this function took the square root of the weights, 
    86   // under the assumption that  
     86  // under the assumption that 
    8787  // 
    8888  //     w*I(q, rho1, rho2, ...) = I(q, sqrt(w)*rho1, sqrt(w)*rho2, ...) 
     
    188188    QACRotation *rotation, 
    189189    double qx, double qy, 
    190     double *qa_out, double *qc_out) 
     190    double *qab_out, double *qc_out) 
    191191{ 
     192    // Indirect calculation of qab, from qab^2 = |q|^2 - qc^2 
    192193    const double dqc = rotation->R31*qx + rotation->R32*qy; 
    193     // Indirect calculation of qab, from qab^2 = |q|^2 - qc^2 
    194     const double dqa = sqrt(-dqc*dqc + qx*qx + qy*qy); 
    195  
    196     *qa_out = dqa; 
     194    const double dqab_sq = -dqc*dqc + qx*qx + qy*qy; 
     195    //*qab_out = sqrt(fabs(dqab_sq)); 
     196    *qab_out = dqab_sq > 0.0 ? sqrt(dqab_sq) : 0.0; 
    197197    *qc_out = dqc; 
    198198} 
Note: See TracChangeset for help on using the changeset viewer.