Index: sasmodels/generate.py
===================================================================
--- sasmodels/generate.py	(revision 32e3c9bc7952e078b48a3a2ce4bd06b565d7326a)
+++ sasmodels/generate.py	(revision b966a96fbdc2825411d2c2a16c6f9e47f38e9ba5)
@@ -540,4 +540,6 @@
 
     # Define the parameter table
+    # TODO: plug in current line number
+    source.append('#line 542 "sasmodels/generate.py"')
     source.append("#define PARAMETER_TABLE \\")
     source.append("\\\n".join(p.as_definition()
@@ -580,18 +582,21 @@
 
     source.append("#if defined(USE_OPENCL)")
-    source.extend(_add_kernels(ocl_code[0], call_iq, call_iqxy, model_info.name))
+    source.extend(_add_kernels(ocl_code, call_iq, call_iqxy, model_info.name))
     source.append("#else /* !USE_OPENCL */")
-    source.extend(_add_kernels(dll_code[0], call_iq, call_iqxy, model_info.name))
+    source.extend(_add_kernels(dll_code, call_iq, call_iqxy, model_info.name))
     source.append("#endif /* !USE_OPENCL */")
     return '\n'.join(source)
 
 
-def _add_kernels(kernel_code, call_iq, call_iqxy, name):
-    # type: (str, str, str, str) -> List[str]
+def _add_kernels(kernel, call_iq, call_iqxy, name):
+    # type: ([str,str], str, str, str) -> List[str]
+    code = kernel[0]
+    path = kernel[1].replace('\\', '\\\\')
     source = [
         # define the Iq kernel
         "#define KERNEL_NAME %s_Iq" % name,
         call_iq,
-        kernel_code,
+        '#line 1 "%s-Iq"' % path,
+        code,
         "#undef CALL_IQ",
         "#undef KERNEL_NAME",
@@ -600,5 +605,6 @@
         "#define KERNEL_NAME %s_Iqxy" % name,
         call_iqxy,
-        kernel_code,
+        '#line 1 "%s-Iqxy"' % path,
+        code,
         "#undef CALL_IQ",
         "#undef KERNEL_NAME",
@@ -608,5 +614,6 @@
         "#define MAGNETIC 1",
         call_iqxy,
-        kernel_code,
+        '#line 1 "%s-Imagnetic"' % path,
+        code,
         "#undef MAGNETIC",
         "#undef CALL_IQ",
Index: sasmodels/kernel_header.c
===================================================================
--- sasmodels/kernel_header.c	(revision ba32cddebeff04b66d828ca58b1843244d4425fb)
+++ sasmodels/kernel_header.c	(revision b966a96fbdc2825411d2c2a16c6f9e47f38e9ba5)
@@ -8,4 +8,6 @@
 // Note: if using a C++ compiler, then define kernel as extern "C"
 #ifndef USE_OPENCL
+// Use SAS_DOUBLE to force the use of double even for float kernels
+#  define SAS_DOUBLE dou ## ble
 #  ifdef __cplusplus
       #include <cstdio>
@@ -16,43 +18,38 @@
          #include <float.h>
          #define kernel extern "C" __declspec( dllexport )
-         static double trunc(double x) { return x>=0?floor(x):-floor(-x); }
-         static double fmin(double x, double y) { return x>y ? y : x; }
-         static double fmax(double x, double y) { return x<y ? y : x; }
-         static double isnan(double x) { return _isnan(x); }
+         inline double trunc(double x) { return x>=0?floor(x):-floor(-x); }
+         inline double fmin(double x, double y) { return x>y ? y : x; }
+         inline double fmax(double x, double y) { return x<y ? y : x; }
+         #define isnan(x) _isnan(x)
+         #define isinf(x) (!_finite(x))
+         #define isfinite(x) _finite(x)
          #define NAN (std::numeric_limits<double>::quiet_NaN()) // non-signalling NaN
-         static double cephes_expm1(double x) {
-            // Adapted from the cephes math library.
-            // Copyright 1984 - 1992 by Stephen L. Moshier
-            if (x != x || x == 0.0) {
-               return x; // NaN and +/- 0
-            } else if (x < -0.5 || x > 0.5) {
-               return exp(x) - 1.0;
-            } else {
-               const double xsq = x*x;
-               const double p = (((
-                  +1.2617719307481059087798E-4)*xsq
-                  +3.0299440770744196129956E-2)*xsq
-                  +9.9999999999999999991025E-1);
-               const double q = ((((
-                  +3.0019850513866445504159E-6)*xsq
-                  +2.5244834034968410419224E-3)*xsq
-                  +2.2726554820815502876593E-1)*xsq
-                  +2.0000000000000000000897E0);
-               double r = x * p;
-               r =  r / (q - r);
-               return r+r;
-             }
-         }
-         #define expm1 cephes_expm1
-         typedef __int32 int32_t
+         #define INFINITY (std::numeric_limits<double>::infinity())
+         #define NEED_EXPM1
+         #define NEED_TGAMMA
      #else
          #define kernel extern "C"
          #include <cstdint>
      #endif
-     static void SINCOS(double angle, double &svar, double &cvar) { svar=sin(angle); cvar=cos(angle); }
+     inline void SINCOS(double angle, double &svar, double &cvar) { svar=sin(angle); cvar=cos(angle); }
 #  else
      #include <inttypes.h>  // C99 guarantees that int32_t types is here
      #include <stdio.h>
-     #include <tgmath.h> // C99 type-generic math, so sin(float) => sinf
+     #if defined(__TINYC__)
+         typedef int int32_t;
+         #include <math.h>
+         // TODO: test isnan
+         inline double _isnan(double x) { return x != x; } // hope this doesn't optimize away!
+         #undef isnan
+         #define isnan(x) _isnan(x)
+         // Defeat the double->float conversion since we don't have tgmath
+         inline SAS_DOUBLE trunc(SAS_DOUBLE x) { return x>=0?floor(x):-floor(-x); }
+         inline SAS_DOUBLE fmin(SAS_DOUBLE x, SAS_DOUBLE y) { return x>y ? y : x; }
+         inline SAS_DOUBLE fmax(SAS_DOUBLE x, SAS_DOUBLE y) { return x<y ? y : x; }
+         #define NEED_EXPM1
+         #define NEED_TGAMMA
+     #else
+         #include <tgmath.h> // C99 type-generic math, so sin(float) => sinf
+     #endif
      // MSVC doesn't support C99, so no need for dllexport on C99 branch
      #define kernel
@@ -73,4 +70,31 @@
 #    define SINCOS(angle,svar,cvar) do {const double _t_=angle; svar=sin(_t_);cvar=cos(_t_);} while (0)
 #  endif
+#endif
+
+#if defined(NEED_EXPM1)
+   static SAS_DOUBLE expm1(SAS_DOUBLE x_in) {
+      double x = (double)x_in;  // go back to float for single precision kernels
+      // Adapted from the cephes math library.
+      // Copyright 1984 - 1992 by Stephen L. Moshier
+      if (x != x || x == 0.0) {
+         return x; // NaN and +/- 0
+      } else if (x < -0.5 || x > 0.5) {
+         return exp(x) - 1.0;
+      } else {
+         const double xsq = x*x;
+         const double p = (((
+            +1.2617719307481059087798E-4)*xsq
+            +3.0299440770744196129956E-2)*xsq
+            +9.9999999999999999991025E-1);
+         const double q = ((((
+            +3.0019850513866445504159E-6)*xsq
+            +2.5244834034968410419224E-3)*xsq
+            +2.2726554820815502876593E-1)*xsq
+            +2.0000000000000000000897E0);
+         double r = x * p;
+         r =  r / (q - r);
+         return r+r;
+       }
+   }
 #endif
 
@@ -103,6 +127,6 @@
 #  define M_4PI_3 4.18879020478639
 #endif
-static double square(double x) { return x*x; }
-static double cube(double x) { return x*x*x; }
-static double sinc(double x) { return x==0 ? 1.0 : sin(x)/x; }
+inline double square(double x) { return x*x; }
+inline double cube(double x) { return x*x*x; }
+inline double sinc(double x) { return x==0 ? 1.0 : sin(x)/x; }
 
Index: sasmodels/kernel_iq.c
===================================================================
--- sasmodels/kernel_iq.c	(revision 32e3c9bc7952e078b48a3a2ce4bd06b565d7326a)
+++ sasmodels/kernel_iq.c	(revision b966a96fbdc2825411d2c2a16c6f9e47f38e9ba5)
@@ -29,5 +29,5 @@
 
 typedef struct {
-    PARAMETER_TABLE;
+    PARAMETER_TABLE
 } ParameterBlock;
 #endif
@@ -41,5 +41,5 @@
 static double clip(double value, double low, double high)
 {
-    return (value < low ? low : (value > high ? high : value));
+  return (value < low ? low : (value > high ? high : value));
 }
 
@@ -53,22 +53,22 @@
     double *uu, double *dd, double *ud, double *du)
 {
-    in_spin = clip(in_spin, 0.0, 1.0);
-    out_spin = clip(out_spin, 0.0, 1.0);
-	*uu = sqrt(sqrt(in_spin * out_spin));
-	*dd = sqrt(sqrt((1.0-in_spin) * (1.0-out_spin)));
-	*ud = sqrt(sqrt(in_spin * (1.0-out_spin)));
-	*du = sqrt(sqrt((1.0-in_spin) * out_spin));
+  in_spin = clip(in_spin, 0.0, 1.0);
+  out_spin = clip(out_spin, 0.0, 1.0);
+  *uu = sqrt(sqrt(in_spin * out_spin));
+  *dd = sqrt(sqrt((1.0-in_spin) * (1.0-out_spin)));
+  *ud = sqrt(sqrt(in_spin * (1.0-out_spin)));
+  *du = sqrt(sqrt((1.0-in_spin) * out_spin));
 }
 
 // Convert polar to rectangular coordinates.
 static void polrec(double r, double theta, double phi,
-    double *x, double *y, double *z)
+  double *x, double *y, double *z)
 {
-    double cos_theta, sin_theta, cos_phi, sin_phi;
-    SINCOS(theta*M_PI_180, sin_theta, cos_theta);
-    SINCOS(phi*M_PI_180, sin_phi, cos_phi);
-    *x = r * cos_theta * cos_phi;
-    *y = r * sin_theta;
-    *z = -r * cos_theta * sin_phi;
+  double cos_theta, sin_theta, cos_phi, sin_phi;
+  SINCOS(theta*M_PI_180, sin_theta, cos_theta);
+  SINCOS(phi*M_PI_180, sin_phi, cos_phi);
+  *x = r * cos_theta * cos_phi;
+  *y = r * sin_theta;
+  *z = -r * cos_theta * sin_phi;
 }
 #endif
Index: sasmodels/kerneldll.py
===================================================================
--- sasmodels/kerneldll.py	(revision 32e3c9bc7952e078b48a3a2ce4bd06b565d7326a)
+++ sasmodels/kerneldll.py	(revision b966a96fbdc2825411d2c2a16c6f9e47f38e9ba5)
@@ -292,5 +292,5 @@
         if self._dll is None:
             self._load_dll()
-        kernel = [self._Iqxy, self._Imagnetic] if q_input.is_2d else self._Iq
+        kernel = [self._Iqxy, self._Imagnetic] if q_input.is_2d else [self._Iq]*2
         return DllKernel(kernel, self.info, q_input)
 
