Added test function and nan handler

The results are tested against sqrt from numpy; if difference bigger
than 1.e-14 is computed, an error is raised