various improvements

Some fixes for 64 bit operation, double float, curand support, etc.

Often I only added only as much as I immediately neeeded (for instance math functions, curand support), but the overall approach may be sound so I'm making it available to you for review.