Added ANSI C version using math.h functions