Index: sasmodels/compare.py
===================================================================
--- sasmodels/compare.py	(revision fe25edaa0ee387b937ccacc643b1d54f998d9e95)
+++ sasmodels/compare.py	(revision d504bcd1759ba2c9640a45ca510f579b0094b6b8)
@@ -340,5 +340,4 @@
         if pars['radius'] < pars['thick_string']:
             pars['radius'], pars['thick_string'] = pars['thick_string'], pars['radius']
-        pars['num_pearls'] = math.ceil(pars['num_pearls'])
         pass
 
@@ -353,7 +352,4 @@
         for c in '1234':
             pars['Phi'+c] /= total
-
-    elif name == 'stacked_disks':
-        pars['n_stacking'] = math.ceil(pars['n_stacking'])
 
 def parlist(model_info, pars, is2d):
Index: sasmodels/models/core_multi_shell.c
===================================================================
--- sasmodels/models/core_multi_shell.c	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
+++ sasmodels/models/core_multi_shell.c	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
@@ -8,10 +8,9 @@
 }
 
-double
-form_volume(double core_radius, double n, double thickness[]);
-double
-form_volume(double core_radius, double n, double thickness[])
+static double
+form_volume(double core_radius, double fp_n, double thickness[])
 {
   double r = core_radius;
+  int n = (int)(fp_n+0.5);
   for (int i=0; i < n; i++) {
     r += thickness[i];
@@ -20,12 +19,9 @@
 }
 
-double
+static double
 Iq(double q, double core_sld, double core_radius,
-   double solvent_sld, double num_shells, double sld[], double thickness[]);
-double
-Iq(double q, double core_sld, double core_radius,
-   double solvent_sld, double num_shells, double sld[], double thickness[])
+   double solvent_sld, double fp_n, double sld[], double thickness[])
 {
-  const int n = (int)ceil(num_shells);
+  const int n = (int)(fp_n+0.5);
   double f, r, last_sld;
   r = core_radius;
Index: sasmodels/models/core_multi_shell.py
===================================================================
--- sasmodels/models/core_multi_shell.py	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
+++ sasmodels/models/core_multi_shell.py	(revision 5a0b3d7cc6ece282917e52177bc5e9e4de4169d1)
@@ -107,4 +107,5 @@
     Returns the SLD profile *r* (Ang), and *rho* (1e-6/Ang^2).
     """
+    n = int(n+0.5)
     z = []
     rho = []
@@ -133,5 +134,5 @@
 def ER(radius, n, thickness):
     """Effective radius"""
-    n = int(n[0])  # n cannot be polydisperse
+    n = int(n[0]+0.5)  # n is a control parameter and is not polydisperse
     return np.sum(thickness[:n], axis=0) + radius
 
Index: sasmodels/models/flexible_cylinder.c
===================================================================
--- sasmodels/models/flexible_cylinder.c	(revision 592343f7d47ec3aad7ffa1ca242acb1346553ede)
+++ sasmodels/models/flexible_cylinder.c	(revision 592343f7d47ec3aad7ffa1ca242acb1346553ede)
@@ -1,4 +1,4 @@
 static double
-form_volume(length, kuhn_length, radius)
+form_volume(double length, double kuhn_length, double radius)
 {
     return 1.0;
Index: sasmodels/models/lamellar_hg_stack_caille.c
===================================================================
--- sasmodels/models/lamellar_hg_stack_caille.c	(revision a8072067ae8a224e45d23ba71f663aadbe1ba4a9)
+++ sasmodels/models/lamellar_hg_stack_caille.c	(revision 1c6286dfdaf227a2fff41c4aafee0a2fec46c0fd)
@@ -3,28 +3,18 @@
 */
 
-double Iq(double qval,
-      double length_tail,
-      double length_head,
-      double Nlayers, 
-      double dd,
-      double Cp,
-      double tail_sld,
-      double head_sld,
-      double solvent_sld);
-
-double Iq(double qval,
-      double length_tail,
-      double length_head,
-      double Nlayers, 
-      double dd,
-      double Cp,
-      double tail_sld,
-      double head_sld,
-      double solvent_sld)
+static double
+Iq(double qval,
+   double length_tail,
+   double length_head,
+   double fp_Nlayers,
+   double dd,
+   double Cp,
+   double tail_sld,
+   double head_sld,
+   double solvent_sld)
 {
-  double NN;   //local variables of coefficient wave
+  int Nlayers = (int)(fp_Nlayers+0.5);    //cast to an integer for the loop
   double inten,Pq,Sq,alpha,temp,t2;
   //double dQ, dQDefault, t1, t3;
-  int ii,NNint;
   // from wikipedia 0.577215664901532860606512090082402431042159335
   const double Euler = 0.577215664901533;   // Euler's constant, increased sig figs for new models Feb 2015
@@ -32,18 +22,11 @@
   //dQ = dQDefault; // REMOVED UNUSED dQ calculations for new models Feb 2015
 
-  NN = trunc(Nlayers);    //be sure that NN is an integer
-  
-  Pq = (head_sld-solvent_sld)*(sin(qval*(length_head+length_tail))-sin(qval*length_tail)) +
-              (tail_sld-solvent_sld)*sin(qval*length_tail);
+  Pq = (head_sld-solvent_sld)*(sin(qval*(length_head+length_tail))-sin(qval*length_tail))
+       + (tail_sld-solvent_sld)*sin(qval*length_tail);
   Pq *= Pq;
   Pq *= 4.0/(qval*qval);
 
-  NNint = (int)NN;    //cast to an integer for the loop
-  ii=0;
   Sq = 0.0;
-  for(ii=1;ii<=(NNint-1);ii+=1) {
-
-    //fii = (double)ii;   //do I really need to do this? - unused variable, removed 18Feb2015
-
+  for(int ii=1; ii < Nlayers; ii++) {
     temp = 0.0;
     alpha = Cp/4.0/M_PI/M_PI*(log(M_PI*ii) + Euler);
@@ -52,10 +35,10 @@
     //t3 = dQ*dQ*dd*dd*ii*ii;
 
-    temp = 1.0-ii/NN;
+    temp = 1.0-(double)ii/(double)Nlayers;
     //temp *= cos(dd*qval*ii/(1.0+t1));
     temp *= cos(dd*qval*ii);
     //if (temp < 0) printf("q=%g: ii=%d, cos(dd*q*ii)=cos(%g) < 0\n",qval,ii,dd*qval*ii);
     //temp *= exp(-1.0*(t2 + t3)/(2.0*(1.0+t1)) );
-    temp *= exp(-t2/2.0 );
+    temp *= exp(-t2/2.0);
     //temp /= sqrt(1.0+t1);
 
@@ -71,5 +54,5 @@
 
   inten *= 1.0e-04;   // 1/A to 1/cm
-  return(inten);
+  return inten;
 }
 
Index: sasmodels/models/lamellar_hg_stack_caille.py
===================================================================
--- sasmodels/models/lamellar_hg_stack_caille.py	(revision 7c578619a7733b31ffab2ce827e4701af4643dea)
+++ sasmodels/models/lamellar_hg_stack_caille.py	(revision a57b31dc1634e8d710e6f72d02be91edfc5b23eb)
@@ -98,5 +98,5 @@
     ["length_head", "Ang", 2, [0, inf], "volume",
      "head thickness"],
-    ["Nlayers", "", 30, [0, inf], "",
+    ["Nlayers", "", 30, [1, inf], "",
      "Number of layers"],
     ["d_spacing", "Ang", 40., [0.0, inf], "volume",
Index: sasmodels/models/lamellar_stack_caille.c
===================================================================
--- sasmodels/models/lamellar_stack_caille.c	(revision 0bef47b278e819df7ea6b572375dd7bc9607227e)
+++ sasmodels/models/lamellar_stack_caille.c	(revision 1c6286dfdaf227a2fff41c4aafee0a2fec46c0fd)
@@ -3,24 +3,17 @@
 */
 
-double Iq(double qval,
-      double del,
-      double Nlayers, 
-      double dd,
-	  double Cp, 
-      double sld,
-      double solvent_sld);
-
-double Iq(double qval,
-      double del,
-      double Nlayers, 
-      double dd,
-	  double Cp, 
-      double sld,
-      double solvent_sld)
+static double
+Iq(double qval,
+   double del,
+   double fp_Nlayers,
+   double dd,
+   double Cp,
+   double sld,
+   double solvent_sld)
 {
-  double contr,NN;   //local variables of coefficient wave
+  int Nlayers = (int)(fp_Nlayers+0.5);    //cast to an integer for the loop
+  double contr;   //local variables of coefficient wave
   double inten,Pq,Sq,alpha,temp,t2;
   //double dQ, dQDefault, t1, t3;
-  int ii,NNint;
   // from wikipedia 0.577215664901532860606512090082402431042159335
   const double Euler = 0.577215664901533;   // Euler's constant, increased sig figs for new models Feb 2015
@@ -28,18 +21,10 @@
   //dQ = dQDefault; // REMOVED UNUSED dQ calculations for new models Feb 2015
 
-  NN = trunc(Nlayers);    //be sure that NN is an integer
-  
   contr = sld - solvent_sld;
 
   Pq = 2.0*contr*contr/qval/qval*(1.0-cos(qval*del));
 
-  NNint = (int)NN;    //cast to an integer for the loop
-  ii=0;
   Sq = 0.0;
-  // the vital "=" in ii<=  added March 2015
-  for(ii=1;ii<=(NNint-1);ii+=1) {
-
-    //fii = (double)ii;   //do I really need to do this? - unused variable, removed 18Feb2015
-
+  for (int ii=1; ii < Nlayers; ii++) {
     temp = 0.0;
     alpha = Cp/4.0/M_PI/M_PI*(log(M_PI*ii) + Euler);
@@ -48,9 +33,9 @@
     //t3 = dQ*dQ*dd*dd*ii*ii;
 
-    temp = 1.0-ii/NN;
+    temp = 1.0 - (double)ii / (double)Nlayers;
     //temp *= cos(dd*qval*ii/(1.0+t1));
     temp *= cos(dd*qval*ii);
     //temp *= exp(-1.0*(t2 + t3)/(2.0*(1.0+t1)) );
-    temp *= exp(-t2/2.0 );
+    temp *= exp(-t2/2.0);
     //temp /= sqrt(1.0+t1);
 
Index: sasmodels/models/lamellar_stack_caille.py
===================================================================
--- sasmodels/models/lamellar_stack_caille.py	(revision 7c578619a7733b31ffab2ce827e4701af4643dea)
+++ sasmodels/models/lamellar_stack_caille.py	(revision a57b31dc1634e8d710e6f72d02be91edfc5b23eb)
@@ -88,5 +88,5 @@
 parameters = [
     ["thickness",        "Ang",      30.0,  [0, inf],   "volume", "sheet thickness"],
-    ["Nlayers",          "",          20,   [0, inf],   "",       "Number of layers"],
+    ["Nlayers",          "",          20,   [1, inf],   "",       "Number of layers"],
     ["d_spacing",        "Ang",      400.,  [0.0,inf],  "volume", "lamellar d-spacing of Caille S(Q)"],
     ["Caille_parameter", "1/Ang^2",    0.1, [0.0,0.8],  "",       "Caille parameter"],
Index: sasmodels/models/lamellar_stack_paracrystal.c
===================================================================
--- sasmodels/models/lamellar_stack_paracrystal.c	(revision 4962519cc1910422a467e4f643dba223623e0e09)
+++ sasmodels/models/lamellar_stack_paracrystal.c	(revision 5467cd8429bf5dfd6306f00a223a06459a9fdf07)
@@ -2,40 +2,28 @@
 
 */
-double Iq(double qval,
-      double th,
-      double Nlayers, 
-	  double davg, 
-	  double pd,
-      double sld,
-      double solvent_sld);
-double paraCryst_sn(double ww, double qval, double davg, long Nlayers, double an);
-double paraCryst_an(double ww, double qval, double davg, long Nlayers);
+double paraCryst_sn(double ww, double qval, double davg, int Nlayers, double an);
+double paraCryst_an(double ww, double qval, double davg, int Nlayers);
 
-double Iq(double qval,
-      double th,
-      double Nlayers, 
-	  double davg, 
-	  double pd,
-      double sld,
-      double solvent_sld)
+static double
+Iq(double qval,
+   double th,
+   double fp_Nlayers,
+   double davg,
+   double pd,
+   double sld,
+   double solvent_sld)
 {
-    
-	double inten,contr,xn;
-	double xi,ww,Pbil,Znq,Snq,an;
-	long n1,n2;
+	//get the fractional part of Nlayers, to determine the "mixing" of N's
+	int n1 = (int)(fp_Nlayers);		//truncate towards zero
+	int n2 = n1 + 1;
+	const double xn = (double)n2 - fp_Nlayers;	//fractional contribution of n1
 	
-	contr = sld - solvent_sld;
-	//get the fractional part of Nlayers, to determine the "mixing" of N's
-	
-	n1 = (long)trunc(Nlayers);		//rounds towards zero
-	n2 = n1 + 1;
-	xn = (double)n2 - Nlayers;			//fractional contribution of n1
-	
-	ww = exp(-qval*qval*pd*pd*davg*davg/2.0);
+	const double ww = exp(-0.5*square(qval*pd*davg));
 
 	//calculate the n1 contribution
+	double Znq,Snq,an;
 	an = paraCryst_an(ww,qval,davg,n1);
 	Snq = paraCryst_sn(ww,qval,davg,n1,an);
-	
+
 	Znq = xn*Snq;
 	
@@ -52,16 +40,16 @@
 //	Zq = (1-ww^2)/(1+ww^2-2*ww*cos(qval*davg))
 	
-	xi = th/2.0;		//use 1/2 the bilayer thickness
-	Pbil = (sin(qval*xi)/(qval*xi))*(sin(qval*xi)/(qval*xi));
+	const double xi = th/2.0;		//use 1/2 the bilayer thickness
+	const double Pbil = square(sas_sinx_x(qval*xi));
 	
-	inten = 2.0*M_PI*contr*contr*Pbil*Znq/(qval*qval);
-	inten *= 1.0e-04;
+	const double contr = sld - solvent_sld;
+	const double inten = 2.0*M_PI*contr*contr*Pbil*Znq/(qval*qval);
 //printf("q=%.7e wwm1=%g ww=%.5e an=% 12.5e Snq=% 12.5e Znq=% 12.5e Pbil=% 12.5e\n",qval,wwm1,ww,an,Snq,Znq,Pbil);
-	return(inten);
+	return 1.0e-4*inten;
 }
 
 // functions for the lamellar paracrystal model
 double
-paraCryst_sn(double ww, double qval, double davg, long Nlayers, double an) {
+paraCryst_sn(double ww, double qval, double davg, int Nlayers, double an) {
 	
 	double Snq;
@@ -69,10 +57,9 @@
 	Snq = an/( (double)Nlayers*square(1.0+ww*ww-2.0*ww*cos(qval*davg)) );
 	
-	return(Snq);
+	return Snq;
 }
 
 double
-paraCryst_an(double ww, double qval, double davg, long Nlayers) {
-	
+paraCryst_an(double ww, double qval, double davg, int Nlayers) {
 	double an;
 	
@@ -82,5 +69,5 @@
 	an += 2.0*pow(ww,(Nlayers+1))*cos((double)(Nlayers+1)*qval*davg);
 	
-	return(an);
+	return an;
 }
 
Index: sasmodels/models/lamellar_stack_paracrystal.py
===================================================================
--- sasmodels/models/lamellar_stack_paracrystal.py	(revision 7c578619a7733b31ffab2ce827e4701af4643dea)
+++ sasmodels/models/lamellar_stack_paracrystal.py	(revision a0168e84cf86a1efabf5abe8430ab9266ddf1879)
@@ -113,5 +113,5 @@
 parameters = [["thickness", "Ang", 33.0, [0, inf], "volume",
                "sheet thickness"],
-              ["Nlayers", "", 20, [0, inf], "",
+              ["Nlayers", "", 20, [1, inf], "",
                "Number of layers"],
               ["d_spacing", "Ang", 250., [0.0, inf], "",
Index: sasmodels/models/linear_pearls.c
===================================================================
--- sasmodels/models/linear_pearls.c	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
+++ sasmodels/models/linear_pearls.c	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
@@ -4,5 +4,5 @@
             double radius,
             double edge_sep,
-            double num_pearls,
+            double fp_num_pearls,
             double pearl_sld,
             double solvent_sld);
@@ -11,11 +11,12 @@
             double radius,
             double edge_sep,
-            double num_pearls,
+            int num_pearls,
             double pearl_sld,
             double solvent_sld);
 
 
-double form_volume(double radius, double num_pearls)
+double form_volume(double radius, double fp_num_pearls)
 {
+    int num_pearls = (int)(fp_num_pearls + 0.5);
     // Pearl volume
     double pearl_vol = M_4PI_3 * cube(radius);
@@ -27,9 +28,8 @@
             double radius,
             double edge_sep,
-            double num_pearls,
+            int num_pearls,
             double pearl_sld,
             double solvent_sld)
 {
-    double n_contrib;
     //relative sld
     double contrast_pearl = pearl_sld - solvent_sld;
@@ -46,12 +46,11 @@
     double psi = sas_3j1x_x(q * radius);
 
-    // N pearls contribution
-    int n_max = num_pearls - 1;
-    n_contrib = num_pearls;
-    for(int num=1; num<=n_max; num++) {
-        n_contrib += (2.0*(num_pearls-num)*sas_sinx_x(q*separation*num));
+    // N pearls interaction terms 
+    double structure_factor = (double)num_pearls;
+    for(int num=1; num<num_pearls; num++) {
+        structure_factor += 2.0*(num_pearls-num)*sas_sinx_x(q*separation*num);
     }
     // form factor for num_pearls
-    double form_factor = 1.0e-4 * n_contrib * square(m_s*psi) / tot_vol;
+    double form_factor = 1.0e-4 * structure_factor * square(m_s*psi) / tot_vol;
 
     return form_factor;
@@ -61,9 +60,10 @@
             double radius,
             double edge_sep,
-            double num_pearls,
+            double fp_num_pearls,
             double pearl_sld,
             double solvent_sld)
 {
 
+    int num_pearls = (int)(fp_num_pearls + 0.5);
 	double result = linear_pearls_kernel(q,
                     radius,
Index: sasmodels/models/linear_pearls.py
===================================================================
--- sasmodels/models/linear_pearls.py	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
+++ sasmodels/models/linear_pearls.py	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
@@ -16,7 +16,7 @@
 .. math::
 
-    P(Q) = \frac{scale}{V}\left[ m_{p}^2
-    \left(N+2\sum_{n-1}^{N-1}(N-n)\frac{sin(qnl)}{qnl}\right)
-    \left( 3\frac{sin(qR)-qRcos(qR)}{(qr)^3}\right)^2\right]
+    P(Q) = \frac{\text{scale}}{V}\left[ m_{p}^2
+    \left(N+2\sum_{n-1}^{N-1}(N-n)\frac{\sin(qnl)}{qnl}\right)
+    \left( 3\frac{\sin(qR)-qR\cos(qR)}{(qr)^3}\right)^2\right]
 
 where the mass $m_p$ is $(SLD_{pearl}-SLD_{solvent})*(volume\ of\ N\ pearls)$.
@@ -56,5 +56,5 @@
     ["radius",      "Ang",       80.0, [0, inf],     "", "Radius of the pearls"],
     ["edge_sep",    "Ang",      350.0, [0, inf],     "", "Length of the string segment - surface to surface"],
-    ["num_pearls",  "",           3.0, [0, inf],     "", "Number of the pearls"],
+    ["num_pearls",  "",           3.0, [1, inf],     "", "Number of the pearls"],
     ["sld",   "1e-6/Ang^2", 1.0, [-inf, inf],  "sld", "SLD of the pearl spheres"],
     ["sld_solvent", "1e-6/Ang^2", 6.3, [-inf, inf],  "sld", "SLD of the solvent"],
Index: sasmodels/models/multilayer_vesicle.c
===================================================================
--- sasmodels/models/multilayer_vesicle.c	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
+++ sasmodels/models/multilayer_vesicle.c	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
@@ -7,5 +7,5 @@
           double sld_solvent,
           double sld,
-          double n_pairs)
+          int n_pairs)
 {
     //calculate with a loop, two shells at a time
@@ -47,6 +47,7 @@
           double sld_solvent,
           double sld,
-          double n_pairs)
+          double fp_n_pairs)
 {
+    int n_pairs = (int)(fp_n_pairs + 0.5);
     return multilayer_vesicle_kernel(q,
            volfraction,
Index: sasmodels/models/multilayer_vesicle.py
===================================================================
--- sasmodels/models/multilayer_vesicle.py	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
+++ sasmodels/models/multilayer_vesicle.py	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
@@ -19,23 +19,28 @@
 
 .. math::
+    P(q) = \text{scale} \cdot \frac{V_f}{V_t} F^2(q) + \text{background}
 
-    P(q) = \frac{\text{scale.volfraction}}{V_t} F^2(q) + \text{background}
-
-where
+for
 
 .. math::
+    F(q) = (\rho_\text{shell}-\rho_\text{solv}) \sum_{i=1}^{n_\text{pairs}}
+        \left[
+          3V(R_i)\frac{\sin(qR_i)-qR_i\cos(qR_i)}{(qR_i)^3} \\
+          - 3V(R_i+t_s)\frac{\sin(q(R_i+t_s))-q(R_i+t_s)\cos(q(R_i+t_s))}{(q(R_i+t_s))^3}
+        \right]
 
-     F(q) = (\rho_{shell}-\rho_{solv}) \sum_{i=1}^{n\_pairs} \left[
-     3V(R_i)\frac{\sin(qR_i)-qR_i\cos(qR_i)}{(qR_i)^3} \\
-      - 3V(R_i+t_s)\frac{\sin(q(R_i+t_s))-q(R_i+t_s)\cos(q(R_i+t_s))}{(q(R_i+t_s))^3}
-     \right]
+and
 
+.. math::
+     R_i = r_c + (i-1)(t_s + t_w)
 
-where $R_i = r_c + (i-1)(t_s + t_w)$
-   
-where $V_t$ is the volume of the whole particle, $V(R)$ is the volume of a sphere
-of radius $R$, $r_c$ is the radius of the core, $\rho_{shell}$ is the scattering length 
-density of a shell, $\rho_{solv}$ is the scattering length density of the solvent.
+where $V_f$ is the volume fraction of particles, $V_t$ is the volume of the
+whole particle, $V(r)$ is the volume of a sphere of radius $r$, $r_c$ is the
+radius of the core, $\rho_\text{shell}$ is the scattering length density of a
+shell, $\rho_\text{solv}$ is the scattering length density of the solvent.
 
+The outer most radius, $r_o = R_n + t_s$, is used for both the volume fraction
+normalization and for the effective radius for *S(Q)* when $P(Q) * S(Q)$
+is applied.
 
 The 2D scattering intensity is the same as 1D, regardless of the orientation
@@ -45,12 +50,4 @@
 
     q = \sqrt{q_x^2 + q_y^2}
-
-
-The outer most radius
-
-$radius + n\_pairs * thick\_shell + (n\_pairs- 1) * thick\_solvent$
-
-is used for both the volume fraction normalization and for the 
-effective radius for *S(Q)* when $P(Q) * S(Q)$ is applied.
 
 For information about polarised and magnetic scattering, see
@@ -70,5 +67,5 @@
 **Author:** NIST IGOR/DANSE **on:** pre 2010
 
-**Last Modified by:** Piotr Rozyczko**on:** Feb 24, 2016
+**Last Modified by:** Piotr Rozyczko **on:** Feb 24, 2016
 
 **Last Reviewed by:** Paul Butler **on:** March 20, 2016
@@ -109,4 +106,5 @@
 source = ["lib/sas_3j1x_x.c", "multilayer_vesicle.c"]
 
+# TODO: the following line does nothing
 polydispersity = ["radius", "n_pairs"]
 
Index: sasmodels/models/onion.c
===================================================================
--- sasmodels/models/onion.c	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
+++ sasmodels/models/onion.c	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
@@ -30,9 +30,9 @@
 
 static double
-form_volume(double radius_core, double n, double thickness[])
+form_volume(double radius_core, double n_shells, double thickness[])
 {
-  int i;
+  int n = (int)(n_shells+0.5);
   double r = radius_core;
-  for (i=0; i < n; i++) {
+  for (int i=0; i < n; i++) {
     r += thickness[i];
   }
Index: sasmodels/models/onion.py
===================================================================
--- sasmodels/models/onion.py	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
+++ sasmodels/models/onion.py	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
@@ -323,5 +323,5 @@
     Returns shape profile with x=radius, y=SLD.
     """
-
+    n_shells = int(n_shells+0.5)
     total_radius = 1.25*(sum(thickness[:n_shells]) + radius_core + 1)
     dz = total_radius/400  # 400 points for a smooth plot
@@ -366,7 +366,8 @@
     return np.asarray(z), np.asarray(rho)
 
-def ER(radius_core, n, thickness):
+def ER(radius_core, n_shells, thickness):
     """Effective radius"""
-    return np.sum(thickness[:int(n[0])], axis=0) + radius_core
+    n = int(n_shells[0]+0.5)
+    return np.sum(thickness[:n], axis=0) + radius_core
 
 demo = {
Index: sasmodels/models/pearl_necklace.c
===================================================================
--- sasmodels/models/pearl_necklace.c	(revision 4b541acdec7c4de7cd7f18ff5911816123ce8333)
+++ sasmodels/models/pearl_necklace.c	(revision 3f853bebcb00b60a94839b6814ab5fd833196ce6)
@@ -1,6 +1,6 @@
 double form_volume(double radius, double edge_sep,
-    double thick_string, double num_pearls);
+    double thick_string, double fp_num_pearls);
 double Iq(double q, double radius, double edge_sep,
-    double thick_string, double num_pearls, double sld, 
+    double thick_string, double fp_num_pearls, double sld,
     double string_sld, double solvent_sld);
 
@@ -9,10 +9,9 @@
 // From Igor library
 static double
-_pearl_necklace_kernel(double q, double radius, double edge_sep, double thick_string,
-    double num_pearls, double sld_pearl, double sld_string, double sld_solv)
+pearl_necklace_kernel(double q, double radius, double edge_sep, double thick_string,
+    int num_pearls, double sld_pearl, double sld_string, double sld_solv)
 {
     // number of string segments
-    num_pearls = floor(num_pearls + 0.5); //Force integer number of pearls
-    const double num_strings = num_pearls - 1.0;
+    const int num_strings = num_pearls - 1;
 
     //each masses: contrast * volume
@@ -69,9 +68,8 @@
 
 double form_volume(double radius, double edge_sep,
-    double thick_string, double num_pearls)
+    double thick_string, double fp_num_pearls)
 {
-    num_pearls = floor(num_pearls + 0.5); //Force integer number of pearls
-
-    const double num_strings = num_pearls - 1.0;
+    const int num_pearls = (int)(fp_num_pearls + 0.5); //Force integer number of pearls
+    const int num_strings = num_pearls - 1;
     const double string_vol = edge_sep * M_PI_4 * thick_string * thick_string;
     const double pearl_vol = M_4PI_3 * radius * radius * radius;
@@ -82,8 +80,9 @@
 
 double Iq(double q, double radius, double edge_sep,
-    double thick_string, double num_pearls, double sld, 
+    double thick_string, double fp_num_pearls, double sld,
     double string_sld, double solvent_sld)
 {
-    const double form = _pearl_necklace_kernel(q, radius, edge_sep,
+    const int num_pearls = (int)(fp_num_pearls + 0.5); //Force integer number of pearls
+    const double form = pearl_necklace_kernel(q, radius, edge_sep,
         thick_string, num_pearls, sld, string_sld, solvent_sld);
 
Index: sasmodels/models/pearl_necklace.py
===================================================================
--- sasmodels/models/pearl_necklace.py	(revision 4b541acdec7c4de7cd7f18ff5911816123ce8333)
+++ sasmodels/models/pearl_necklace.py	(revision 1bd1ea22a4ccb6ec87819647e470bbc002b2a1ac)
@@ -82,5 +82,5 @@
               ["thick_string", "Ang", 2.5, [0, inf], "volume",
                "Thickness of the chain linkage"],
-              ["num_pearls", "none", 3, [0, inf], "volume",
+              ["num_pearls", "none", 3, [1, inf], "volume",
                "Number of pearls in the necklace (must be integer)"],
               ["sld", "1e-6/Ang^2", 1.0, [-inf, inf], "sld",
@@ -100,4 +100,5 @@
     Redundant with form_volume.
     """
+    num_pearls = int(num_pearls + 0.5)
     number_of_strings = num_pearls - 1.0
     string_vol = edge_sep * pi * pow((thick_string / 2.0), 2.0)
@@ -111,4 +112,5 @@
     Calculation for effective radius.
     """
+    num_pearls = int(num_pearls + 0.5)
     tot_vol = volume(radius, edge_sep, thick_string, num_pearls)
     rad_out = (tot_vol/(4.0/3.0*pi)) ** (1./3.)
Index: sasmodels/models/raspberry.py
===================================================================
--- sasmodels/models/raspberry.py	(revision 8e68ea06a7246c4bd95ce82c755719ced6fa5a60)
+++ sasmodels/models/raspberry.py	(revision 8e68ea06a7246c4bd95ce82c755719ced6fa5a60)
@@ -10,13 +10,13 @@
     Schematic of the raspberry model
 
-In order to calculate the form factor of the entire complex, the self-
-correlation of the large droplet, the self-correlation of the particles, the
-correlation terms between different particles and the cross terms between large
-droplet and small particles all need to be calculated.
+In order to calculate the form factor of the entire complex, the
+self-correlation of the large droplet, the self-correlation of the particles,
+the correlation terms between different particles and the cross terms between
+large droplet and small particles all need to be calculated.
 
-Consider two infinitely thin shells of radii R1 and R2 separated by distance r.
-The general structure of the equation is then the form factor of the two shells
-multiplied by the phase factor that accounts for the separation of their
-centers.
+Consider two infinitely thin shells of radii $R_1$ and $R_2$ separated by
+distance $r$. The general structure of the equation is then the form factor
+of the two shells multiplied by the phase factor that accounts for the
+separation of their centers.
 
 .. math::
Index: sasmodels/models/rpa.c
===================================================================
--- sasmodels/models/rpa.c	(revision 20c856a138b7cfbe5d8eb03e1655371ef25b4b06)
+++ sasmodels/models/rpa.c	(revision 20c856a138b7cfbe5d8eb03e1655371ef25b4b06)
@@ -1,3 +1,3 @@
-double Iq(double q, double case_num,
+double Iq(double q, double fp_case_num,
     double N[], double Phi[], double v[], double L[], double b[],
     double Kab, double Kac, double Kad,
@@ -5,5 +5,5 @@
     );
 
-double Iq(double q, double case_num,
+double Iq(double q, double fp_case_num,
     double N[],    // DEGREE OF POLYMERIZATION
     double Phi[],  // VOL FRACTION
@@ -15,5 +15,5 @@
     )
 {
-  int icase = (int)case_num;
+  int icase = (int)(fp_case_num+0.5);
 
   double Nab,Nac,Nad,Nbc,Nbd,Ncd;
Index: sasmodels/models/rpa.py
===================================================================
--- sasmodels/models/rpa.py	(revision 20c856a138b7cfbe5d8eb03e1655371ef25b4b06)
+++ sasmodels/models/rpa.py	(revision 20c856a138b7cfbe5d8eb03e1655371ef25b4b06)
@@ -116,4 +116,5 @@
     Return a list of parameters to hide depending on the multiplicity parameter.
     """
+    case_num = int(case_num+0.5)
     if case_num < 2:
         return HIDE_AB
Index: sasmodels/models/spherical_sld.c
===================================================================
--- sasmodels/models/spherical_sld.c	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
+++ sasmodels/models/spherical_sld.c	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
@@ -1,7 +1,8 @@
 static double form_volume(
-    int n_shells,
+    double fp_n_shells,
     double thickness[],
     double interface[])
 {
+    int n_shells= (int)(fp_n_shells + 0.5);
     double r = 0.0;
     for (int i=0; i < n_shells; i++) {
@@ -20,5 +21,5 @@
         return pow(z, nu);
     } else if (shape==2) {
-        return 1.0 - pow(1. - z, nu);
+        return 1.0 - pow(1.0 - z, nu);
     } else if (shape==3) {
         return expm1(-nu*z)/expm1(-nu);
@@ -44,5 +45,5 @@
 static double Iq(
     double q,
-    int n_shells,
+    double fp_n_shells,
     double sld_solvent,
     double sld[],
@@ -51,7 +52,9 @@
     double shape[],
     double nu[],
-    int n_steps)
+    double fp_n_steps)
 {
     // iteration for # of shells + core + solvent
+    int n_shells = (int)(fp_n_shells + 0.5);
+    int n_steps = (int)(fp_n_steps + 0.5);
     double f=0.0;
     double r=0.0;
Index: sasmodels/models/spherical_sld.py
===================================================================
--- sasmodels/models/spherical_sld.py	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
+++ sasmodels/models/spherical_sld.py	(revision 925ad6edca2969db8fb763eb02beee2c5a5f2872)
@@ -233,4 +233,6 @@
     """
 
+    n_shells = int(n_shells + 0.5)
+    n_steps = int(n_steps + 0.5)
     z = []
     rho = []
@@ -240,5 +242,5 @@
     rho.append(sld[0])
 
-    for i in range(0, int(n_shells)):
+    for i in range(0, n_shells):
         z_next += thickness[i]
         z.append(z_next)
@@ -261,5 +263,5 @@
 def ER(n_shells, thickness, interface):
     """Effective radius"""
-    n_shells = int(n_shells)
+    n_shells = int(n_shells + 0.5)
     total = (np.sum(thickness[:n_shells], axis=1)
              + np.sum(interface[:n_shells], axis=1))
Index: sasmodels/models/stacked_disks.c
===================================================================
--- sasmodels/models/stacked_disks.c	(revision 6c3e2666e0741d50f118672e164dfa561dcc7765)
+++ sasmodels/models/stacked_disks.c	(revision 19f996bbf3615f0161b71f00777e5f16155bef70)
@@ -1,42 +1,15 @@
-double form_volume(double thick_core,
-                   double thick_layer,
-                   double radius,
-                   double n_stacking);
-
-double Iq(double q,
-          double thick_core,
-          double thick_layer,
-          double radius,
-          double n_stacking,
-          double sigma_dnn,
-          double core_sld,
-          double layer_sld,
-          double solvent_sld);
-
-double Iqxy(double qx, double qy,
-          double thick_core,
-          double thick_layer,
-          double radius,
-          double n_stacking,
-          double sigma_dnn,
-          double core_sld,
-          double layer_sld,
-          double solvent_sld,
-          double theta,
-          double phi);
-
-static
-double _kernel(double q,
-               double radius,
-               double core_sld,
-               double layer_sld,
-               double solvent_sld,
-               double halfheight,
-               double thick_layer,
-               double sin_alpha,
-               double cos_alpha,
-               double sigma_dnn,
-               double d,
-               double n_stacking)
+static double stacked_disks_kernel(
+    double q,
+    double halfheight,
+    double thick_layer,
+    double radius,
+    int n_stacking,
+    double sigma_dnn,
+    double core_sld,
+    double layer_sld,
+    double solvent_sld,
+    double sin_alpha,
+    double cos_alpha,
+    double d)
 
 {
@@ -88,14 +61,14 @@
 
 
-static
-double stacked_disks_kernel(double q,
-                            double thick_core,
-                            double thick_layer,
-                            double radius,
-                            double n_stacking,
-                            double sigma_dnn,
-                            double core_sld,
-                            double layer_sld,
-                            double solvent_sld)
+static double stacked_disks_1d(
+    double q,
+    double thick_core,
+    double thick_layer,
+    double radius,
+    int n_stacking,
+    double sigma_dnn,
+    double core_sld,
+    double layer_sld,
+    double solvent_sld)
 {
 /*    StackedDiscsX  :  calculates the form factor of a stacked "tactoid" of core shell disks
@@ -111,16 +84,16 @@
         double sin_alpha, cos_alpha; // slots to hold sincos function output
         SINCOS(zi, sin_alpha, cos_alpha);
-        double yyy = _kernel(q,
+        double yyy = stacked_disks_kernel(q,
+                           halfheight,
+                           thick_layer,
                            radius,
+                           n_stacking,
+                           sigma_dnn,
                            core_sld,
                            layer_sld,
                            solvent_sld,
-                           halfheight,
-                           thick_layer,
                            sin_alpha,
                            cos_alpha,
-                           sigma_dnn,
-                           d,
-                           n_stacking);
+                           d);
         summ += Gauss76Wt[i] * yyy * sin_alpha;
     }
@@ -132,23 +105,28 @@
 }
 
-double form_volume(double thick_core,
-                   double thick_layer,
-                   double radius,
-                   double n_stacking){
+static double form_volume(
+    double thick_core,
+    double thick_layer,
+    double radius,
+    double fp_n_stacking)
+{
+    int n_stacking = (int)(fp_n_stacking + 0.5);
     double d = 2.0 * thick_layer + thick_core;
     return M_PI * radius * radius * d * n_stacking;
 }
 
-double Iq(double q,
-          double thick_core,
-          double thick_layer,
-          double radius,
-          double n_stacking,
-          double sigma_dnn,
-          double core_sld,
-          double layer_sld,
-          double solvent_sld)
+static double Iq(
+    double q,
+    double thick_core,
+    double thick_layer,
+    double radius,
+    double fp_n_stacking,
+    double sigma_dnn,
+    double core_sld,
+    double layer_sld,
+    double solvent_sld)
 {
-    return stacked_disks_kernel(q,
+    int n_stacking = (int)(fp_n_stacking + 0.5);
+    return stacked_disks_1d(q,
                     thick_core,
                     thick_layer,
@@ -162,17 +140,17 @@
 
 
-double
-Iqxy(double qx, double qy,
-     double thick_core,
-     double thick_layer,
-     double radius,
-     double n_stacking,
-     double sigma_dnn,
-     double core_sld,
-     double layer_sld,
-     double solvent_sld,
-     double theta,
-     double phi)
+static double Iqxy(double qx, double qy,
+    double thick_core,
+    double thick_layer,
+    double radius,
+    double fp_n_stacking,
+    double sigma_dnn,
+    double core_sld,
+    double layer_sld,
+    double solvent_sld,
+    double theta,
+    double phi)
 {
+    int n_stacking = (int)(fp_n_stacking + 0.5);
     double q, sin_alpha, cos_alpha;
     ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha);
@@ -180,16 +158,16 @@
     double d = 2.0 * thick_layer + thick_core;
     double halfheight = 0.5*thick_core;
-    double answer = _kernel(q,
+    double answer = stacked_disks_kernel(q,
+                     halfheight,
+                     thick_layer,
                      radius,
+                     n_stacking,
+                     sigma_dnn,
                      core_sld,
                      layer_sld,
                      solvent_sld,
-                     halfheight,
-                     thick_layer,
                      sin_alpha,
                      cos_alpha,
-                     sigma_dnn,
-                     d,
-                     n_stacking);
+                     d);
 
     //convert to [cm-1]
Index: sasmodels/models/stacked_disks.py
===================================================================
--- sasmodels/models/stacked_disks.py	(revision b7e8b94b477e6d9a7e4e2666bb218d3568ee66d2)
+++ sasmodels/models/stacked_disks.py	(revision b7e8b94b477e6d9a7e4e2666bb218d3568ee66d2)
@@ -126,5 +126,5 @@
     ["thick_layer", "Ang",        10.0, [0, inf],    "volume",      "Thickness of layer each side of core"],
     ["radius",      "Ang",        15.0, [0, inf],    "volume",      "Radius of the stacked disk"],
-    ["n_stacking",  "",            1.0, [0, inf],    "volume",      "Number of stacked layer/core/layer disks"],
+    ["n_stacking",  "",            1.0, [1, inf],    "volume",      "Number of stacked layer/core/layer disks"],
     ["sigma_d",     "Ang",         0,   [0, inf],    "",            "Sigma of nearest neighbor spacing"],
     ["sld_core",    "1e-6/Ang^2",  4,   [-inf, inf], "sld",         "Core scattering length density"],
Index: sasmodels/models/star_polymer.c
===================================================================
--- sasmodels/models/star_polymer.c	(revision 3a48772f136eb2795903c63707474e7527b4a325)
+++ sasmodels/models/star_polymer.c	(revision 2586093fb630ef8ed2de654064935388bf67460d)
@@ -3,5 +3,5 @@
 double Iq(double q, double radius2, double arms);
 
-static double _mass_fractal_kernel(double q, double radius2, double arms)
+static double star_polymer_kernel(double q, double radius2, double arms)
 {
 
@@ -23,4 +23,4 @@
 double Iq(double q, double radius2, double arms)
 {
-    return _mass_fractal_kernel(q, radius2, arms);
+    return star_polymer_kernel(q, radius2, arms);
 }
Index: sasmodels/models/unified_power_Rg.py
===================================================================
--- sasmodels/models/unified_power_Rg.py	(revision 66ca2a6cf404d09b601f9022e85222304a98dc8e)
+++ sasmodels/models/unified_power_Rg.py	(revision 66ca2a6cf404d09b601f9022e85222304a98dc8e)
@@ -97,6 +97,6 @@
 
 def Iq(q, level, rg, power, B, G):
-    ilevel = int(level)
-    if ilevel == 0:
+    level = int(level + 0.5)
+    if level == 0:
         with errstate(divide='ignore'):
             return 1./q
@@ -104,8 +104,8 @@
     with errstate(divide='ignore', invalid='ignore'):
         result = np.zeros(q.shape, 'd')
-        for i in range(ilevel):
+        for i in range(level):
             exp_now = exp(-(q*rg[i])**2/3.)
             pow_now = (erf(q*rg[i]/sqrt(6.))**3/q)**power[i]
-            if i < ilevel-1:
+            if i < level-1:
                 exp_next = exp(-(q*rg[i+1])**2/3.)
             else:
@@ -113,5 +113,5 @@
             result += G[i]*exp_now + B[i]*exp_next*pow_now
 
-    result[q == 0] = np.sum(G[:ilevel])
+    result[q == 0] = np.sum(G[:level])
     return result
 
