title: How to define custom float-type numpy dtypes (C-API)
body: <p>I have a custom float data type that emulates 128bit floats using two 64bit floats (the double-double class <code>dd_real</code> from the <a href="http://crd-legacy.lbl.gov/~dhbailey/mpdist/" rel="nofollow noreferrer">QD library</a>). From C++ I want to export an ndarray to python. I already know how to do this for 64bit floats, but  for double-doubles I somehow need to specify my own custom dtype. How to do that?</p>
  
  <p>Note: numpy has its own 128bit float (np.float128) unfortunately this maps to <code>long double</code> in C/C++ which is merely an 80bit-float stored in 128bit (on all of my platforms). </p>
  
  <p>In fact, one should be able to do this exactly in the same way that numpy exports np.float128 (I just don't know how that is done), with the only difference that it uses <code>dd_real</code> on the C++ side instead of <code>long double</code>.</p>
  
  <p>If this helps, I already exported the C++ type <code>dd_real</code> to python using <code>boost::python</code> maybe this can be reused somehow.</p>
  
  <hr>
  
  <p>So far I was able to research the following</p>
  
  <ol>
  <li><p>The numpy documentation for <a href="http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html#defining-new-types" rel="nofollow noreferrer">dtypes</a> refers to  <a href="http://docs.scipy.org/doc/numpy/reference/c-api.dtype.html" rel="nofollow noreferrer">C-API</a> for how to export custom dtypes, but that document somehow only explains the existing dtypes not how to create new ones. </p></li>
  <li><p>When <a href="https://stackoverflow.com/questions/13199218/how-to-create-a-custom-numpy-dtype-using-cython">browsing</a> stackoverflow I found <a href="https://github.com/numpy/numpy-dtypes/blob/master/npytypes/quaternion/numpy_quaternion.c" rel="nofollow noreferrer">this</a> example, but I wonder if for <code>dd_real</code> this could be simpler. I also don't see where the dtype is actually generated. Maybe only in python <a href="https://github.com/numpy/numpy-dtypes/blob/master/npytypes/quaternion/__init__.py" rel="nofollow noreferrer">__ init__</a> via <code>np.typeDict['quaternion'] = np.dtype(quaternion)</code>. How to use that dtype in C++ when I want to generate an ndarray?</p></li>
  </ol>