Index: sasmodels/compare.py
===================================================================
--- sasmodels/compare.py	(revision b514adfe3f715e5ad1efba9c3b18ed3f086b37af)
+++ sasmodels/compare.py	(revision 5edfe12d884117a412d8437e870506cdf8c27006)
@@ -233,5 +233,8 @@
     model_definition = core.load_model_definition(name)
 
-    view = 'linear' if '-linear' in opts else 'log' if '-log' in opts else 'q4' if '-q4' in opts else 'log'
+    view = ('linear' if '-linear' in opts
+            else 'log' if '-log' in opts
+            else 'q4' if '-q4' in opts
+            else 'log')
 
     opt_values = dict(split
@@ -239,5 +242,8 @@
                       if len(split) == 2)
     # Sort out data
-    qmax = 10.0 if '-exq' in opts else 1.0 if '-highq' in opts else 0.2 if '-midq' in opts else 0.05
+    qmax = (10.0 if '-exq' in opts
+            else 1.0 if '-highq' in opts
+            else 0.2 if '-midq' in opts
+            else 0.05)
     Nq = int(opt_values.get('-Nq', '128'))
     res = float(opt_values.get('-res', '0'))
@@ -248,5 +254,7 @@
 
     # modelling accuracy is determined by dtype and cutoff
-    dtype = 'double' if '-double' in opts else 'single'
+    dtype = ('longdouble' if '-longdouble' in opts
+             else 'double' if '-double' in opts
+             else 'single')
     cutoff = float(opt_values.get('-cutoff','1e-5'))
 
@@ -371,5 +379,5 @@
 
     -plot*/-noplot plots or suppress the plot of the model
-    -single*/-double uses double precision for comparison
+    -single*/-double/-longdouble uses double precision for comparison
     -lowq*/-midq/-highq/-exq use q values up to 0.05, 0.2, 1.0, 10.0
     -Nq=128 sets the number of Q points in the data set
@@ -395,5 +403,5 @@
 NAME_OPTIONS = set([
     'plot','noplot',
-    'single','double',
+    'single','double','longdouble',
     'lowq','midq','highq','exq',
     '2d','1d',
Index: sasmodels/generate.py
===================================================================
--- sasmodels/generate.py	(revision cd3dba0c60af7479ce1bae901d065d3d5786c8ea)
+++ sasmodels/generate.py	(revision 5edfe12d884117a412d8437e870506cdf8c27006)
@@ -197,5 +197,5 @@
 # TODO: identify model files which have changed since loading and reload them.
 
-__all__ = ["make", "doc", "sources", "use_single"]
+__all__ = ["make", "doc", "sources", "use_single", "use_long_double"]
 
 import sys
@@ -206,4 +206,5 @@
 C_KERNEL_TEMPLATE_PATH = joinpath(dirname(__file__), 'kernel_template.c')
 
+F128 = np.dtype('float128')
 F64 = np.dtype('float64')
 F32 = np.dtype('float32')
@@ -322,4 +323,19 @@
     source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?',
                     r'\g<0>f', source)
+    return source
+
+def use_long_double(source):
+    """
+    Convert code from double precision to long double precision.
+    """
+    # Convert double keyword to float.  Accept an 'n' parameter for vector
+    # values, where n is 2, 4, 8 or 16. Assume complex numbers are represented
+    # as cdouble which is typedef'd to double2.
+    source = re.sub(r'(^|[^a-zA-Z0-9_]c?)double(([248]|16)?($|[^a-zA-Z0-9_]))',
+                    r'\1long double\2', source)
+    # Convert floating point constants to single by adding 'f' to the end.
+    # OS/X driver complains if you don't do this.
+    source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?',
+                    r'\g<0>L', source)
     return source
 
Index: sasmodels/kerneldll.py
===================================================================
--- sasmodels/kerneldll.py	(revision 92da2316c75e24044469af05f4f89967a0422190)
+++ sasmodels/kerneldll.py	(revision 5edfe12d884117a412d8437e870506cdf8c27006)
@@ -49,5 +49,5 @@
 import tempfile
 import ctypes as ct
-from ctypes import c_void_p, c_int, c_double, c_float
+from ctypes import c_void_p, c_int, c_longdouble, c_double, c_float
 
 import numpy as np
@@ -96,4 +96,8 @@
     if np.dtype(dtype) == generate.F32:
         basename += "32"
+    elif np.dtype(dtype) == generate.F64:
+        basename += "64"
+    else:
+        basename += "128"
     return joinpath(DLL_PATH, basename+'.so')
 
@@ -118,6 +122,7 @@
     models are allowed as DLLs.
     """
-    if not ALLOW_SINGLE_PRECISION_DLLS: dtype = "double"   # Force 64-bit dll
     dtype = np.dtype(dtype)
+    if dtype == generate.F32 and not ALLOW_SINGLE_PRECISION_DLLS:
+        dtype = generate.F64  # Force 64-bit dll
 
     if callable(info.get('Iq',None)):
@@ -127,6 +132,9 @@
         source = generate.use_single(source)
         tempfile_prefix = 'sas_'+info['name']+'32_'
+    elif dtype == generate.F64:
+        tempfile_prefix = 'sas_'+info['name']+'64_'
     else:
-        tempfile_prefix = 'sas_'+info['name']+'_'
+        source = generate.use_long_double(source)
+        tempfile_prefix = 'sas_'+info['name']+'128_'
 
     source_files = generate.sources(info) + [info['filename']]
@@ -196,5 +204,7 @@
             raise
 
-        fp = c_float if self.dtype == generate.F32 else c_double
+        fp = (c_float if self.dtype == generate.F32
+              else c_double if self.dtype == generate.F64
+              else c_longdouble)
         pd_args_1d = [c_void_p, fp] + [c_int]*Npd1d if Npd1d else []
         pd_args_2d= [c_void_p, fp] + [c_int]*Npd2d if Npd2d else []
@@ -265,5 +275,7 @@
 
     def __call__(self, fixed_pars, pd_pars, cutoff):
-        real = np.float32 if self.q_input.dtype == generate.F32 else np.float64
+        real = (np.float32 if self.q_input.dtype == generate.F32
+                else np.float64 if self.q_input.dtype == generate.F64
+                else np.float128)
 
         nq = c_int(self.q_input.nq)
