made changes:
* floating-point type was changed from double to float
* Implemented Greg's method