#include "mymath.h" #include using namespace std; //************************************************************************ // function to return the gcd of two integers // // parameter usage // a,b -- import the numbers to find the gcd of // // Pre-Condition -- a and b are positive // Post-Conditions -- the gcd is returned //************************************************************************ int gcd(int a, int b) { while (b != 0) { int remainder = a % b; a = b; b = remainder; } return a; } //************************************************************************ // function to find and return the lowest commmom multiple of two numbers // // parameter usage : // a, b -- import the numbers to find the lcm of // // Pre-Condition -- a and b are positive // Post-Condition -- lowest common multiple of a and b is returned //************************************************************************ int lcm(int a, int b) { return a * b / gcd(a,b); } //************************************************************************ // function to exchange the values stored in two integer locations // // parameter usage : // a,b -- import the numbers to be exchanged and // export the exchanged values // // Post-condition -- the values in the locations will be exchanged //************************************************************************ void swap(int& a, int& b) { int temp = a; a = b; b = temp; } //************************************************************************ // function to exchange the values stored in two float locations // // parameter usage : // a,b -- import the numbers to be exchanged and // export the exchanged values // // Post-condition -- the values in the locations will be exchanged //************************************************************************ void swap(float& a, float& b) { float temp = a; a = b; b = temp; } //*********************************************************************** // utility function to check equality of floating point numbers // // parameter usage : // x,y -- import the numbers to compared // // post-condition -- function returns true if the numbers are within // TOLERANCE of each other; false otherwise //************************************************************************* bool dEqual(double x, double y) { return fabs(x-y) < TOLERANCE; }