-
March 12th, 2005, 07:39 AM
#1
Member
General math functions header
Sorry if this is the wrong place to post this, but since it said it was a place to share code...
I got bored after chores .
Code:
/* General math functions header file, (c) Sam Tootell. This piece of code
** was madeto be used openly and freely, as if under the GNU GPL.
*/
double pi = 3.1428571428571428571428571428571; /*For use with geometric functions, which is currently just a circle area*/
/*Addition*/
float add(float value1=0.0, float value2=0.0, float value3=0.0, float value4=0.0, float value5=0.0)
{
float endValue = value1 + value2 + value3 + value4 + value5;
/*cout << "\nThe sum is " << endValue << ".\n";*/
/*printf("\nThe sum is %f.\n" endValue);*/
return endValue;
}
/*Subtraction*/
float subtract(float sub-value1 =0.0, float sub-value2=0.0, float sub-value3=0.0, float sub-value4=0.0, float sub-value5=0.0)
{
float sub-endValue = sub-value1 - subvalue2 - subvalue3 - subvalue4 - subvalue5;
/*cout << "\nThe difference is " << sub-endValue; << ".\n";*/
/*printf("\nThe difference is %f.\n" sub-endValue);*/
return sub-endValue;
}
/*Multiplication*/
float multiply(float mult-value1=0.0, float mult-value2=0.0, float mult-value3=0.0, float mult-value4=0.0, float mult-value5=0.0)
{
float mult-endValue = mult-value1 * mult-value2 * mult-value3 * mult-value4 * mult-value5;
/*cout << "\nThe product is " << mult-endValue << ".\n";*/
/*printf("\nThe product is %f.\n" mult-endValue);*/
return mult-endValue;
}
/*Division*/
float divide(float divi-value1=0.0, divi-value2=0.0, divi-value3=0.0, divi-value4=0.0, divi-value5=0.0)
{
float divi-endValue = divi-value1 / divi-value2 / divi-value3 / divi-value4 / divi-value5;
/*cout << "\nThe difference is " << divi-endValue << ".\n";*/
/*printf("\nThe difference is %f.\n" divi-endValue);*/
return divi-endValue;
}
/*Division, but gives remainders*/
float remainder(float remain-value1, float remain-value2)
{
float remaniderOfValues1 = remain-value1 % remain-value2;
float remainderOfValues2 = remain-value2 % remain-value1;
/*cout << "\nThe remainder of << remain-value1 divided by remain-value2 is:" \
" " << remainderOfValues1 << ". The remainder of " << remain-value2 << " divided" \
" by " << remain-value1 << " is: " << remainderOfValues2 << "./n"; */
/*printf("\nThe remainder of %f divided by %f is: %f.\n"remain-value1,remain-value2,remainderOfValues1);
printf("\nThe remainder of %f divided by %f is: %f.\n"remain-value2,remain-value1,remainderOfValues2); */
return remainderOfValues1; /*Not sure if I can return two at a time... I won't risk it*/
}
/*Pythagoream Theorem*/
float pythTheorem(float a, float b)
{
float c = a^2 + b^2;
/*cout << "\nFor << a << "^2 and << b << "^2, the result is << c << "^2.\n;*/
/*printf("\nFor %f^2 and %f^2, the result is %f^2.\n" a,b,c);*/
return c;
}
/*Exponentation*/
float exponent(float exp-value1, float exp-value2)
{
float exp-endValue = exp-value1 ^ exp-value2;
/*cout << "\nThe exponentation of " << exp-value1 << " and " << exp-value2 << " is " << \
exp-EndValue << ".\n*/
/*printf("\nThe exponentation of %f and %f is %f\n" exp-value1, exp-value2, exp-endValue);*/
return exp-endValue;
}
/*================Geometry================*/
/*Circle area*/
float circleArea(float radius)
{
double area = pi * (radius ^ 2);
/*cout << "\nFor radius = " << radius << ", the result is: \n " << area << "\n"*/
/*printf("\nFor radius %f, the result is:\n%f\n" radius, area);*/
return area;
}
/*Circle circumference*/
float circleCircum(float radius-circ)
{
double circumference = 2*pi*radius-circ;
/*cout << "\nFor radius = " << radius-circ << ", the circle circumference is: " << circumference << ".\n";
/*printf("\nFor radius = %f, the circle circumference is: %f.\n" radius-circ, circumference);*/
return circumference;
}
/*Cube Volume*/
float cubeVolume(float side)
{
float volume = side^3;
/*cout << "\nFor any side of the cube being " << side << " units, the volume is " << volume << " units^3.\n";
/*printf("\nFor any side of the cube being %f units, the volume is %f units^3.\n" side, volume*/
return volume;
}
/* I'll work on more geometry later, and maybe even put in prompting functions... no guarantee*/
Hope you can get some use out of it .
EDIT: Added some more on.
Tell me if you think I\'m spamming or doing something stupid, please.
-
March 13th, 2005, 12:42 AM
#2
lol, you must be really bored. All I have to say is why not use
#define PI 3.14159...
instead of what you had? Peace.
-
March 13th, 2005, 04:44 AM
#3
Member
Good question...
So, updated now, with your advice, and some other thinkanating:
Code:
/* General math functions header file, (c) Sam Tootell. This piece of code
** was madeto be used openly and freely, as if under the GNU GPL.
*/
/*double pi = 3.1428571428571428571428571428571; /*For use with geometric functions, which is currently just a circle area*/ */
#define PI = 3.142857;
/*Addition*/
float add(float value1=0, float value2=0, float value3=0, float value4=0, float value5=0)
{
float endValue = value1 + value2 + value3 + value4 + value5;
/*cout << "\nThe sum is " << endValue << ".\n";*/
/*printf("\nThe sum is %f.\n" endValue);*/
return endValue;
}
/*Subtraction*/
float subtract(float sub-value1=0, float sub-value2=0, float sub-value3=0, float sub-value4=0, float sub-value5=0)
{
float sub-endValue = sub-value1 - subvalue2 - subvalue3 - subvalue4 - subvalue5;
/*cout << "\nThe difference is " << sub-endValue; << ".\n";*/
/*printf("\nThe difference is %f.\n" sub-endValue);*/
return sub-endValue;
}
/*Multiplication*/
float multiply(float mult-value1=0, float mult-value2=0, float mult-value3=0, float mult-value4=0, float mult-value5=0)
{
float mult-endValue = mult-value1 * mult-value2 * mult-value3 * mult-value4 * mult-value5;
/*cout << "\nThe product is " << mult-endValue << ".\n";*/
/*printf("\nThe product is %f.\n" mult-endValue);*/
return mult-endValue;
}
/*Division*/
float divide(float divi-value1=0, divi-value2=0, divi-value3=0, divi-value4=0, divi-value5=0)
{
float divi-endValue = divi-value1 / divi-value2 / divi-value3 / divi-value4 / divi-value5;
/*cout << "\nThe difference is " << divi-endValue << ".\n";*/
/*printf("\nThe difference is %f.\n" divi-endValue);*/
return divi-endValue;
}
/*Division, but gives remainders*/
float remainder(float remain-value1, float remain-value2)
{
float remaniderOfValues1 = remain-value1 % remain-value2;
float remainderOfValues2 = remain-value2 % remain-value1;
/*cout << "\nThe remainder of << remain-value1 divided by remain-value2 is:" \
" " << remainderOfValues1 << ". The remainder of " << remain-value2 << " divided" \
" by " << remain-value1 << " is: " << remainderOfValues2 << "./n"; */
/*printf("\nThe remainder of %f divided by %f is: %f.\n"remain-value1,remain-value2,remainderOfValues1);
printf("\nThe remainder of %f divided by %f is: %f.\n"remain-value2,remain-value1,remainderOfValues2); */
return remainderOfValues1; /*Not sure if I can return two at a time... I won't risk it*/
}
/*Pythagoream Theorem*/
float pythTheorem(float a, float b)
{
float c = a^2 + b^2;
/*cout << "\nFor << a << "^2 and << b << "^2, the result is << c << "^2.\n;*/
/*printf("\nFor %f^2 and %f^2, the result is %f^2.\n" a,b,c);*/
return c;
}
/*Exponentation*/
float exponent(float exp-value1, float exp-value2)
{
float exp-endValue = exp-value1 ^ exp-value2;
/*cout << "\nThe exponentation of " << exp-value1 << " and " << exp-value2 << " is " << \
exp-EndValue << ".\n*/
/*printf("\nThe exponentation of %f and %f is %f\n" exp-value1, exp-value2, exp-endValue);*/
return exp-endValue;
}
/*================Geometry================*/
/*Circle area*/
float circleArea(float radius)
{
double area = PI * (radius ^ 2);
/*cout << "\nFor radius = " << radius << ", the result is: \n " << area << "\n"*/
/*printf("\nFor radius %f, the result is:\n%f\n" radius, area);*/
return area;
}
/*Circle circumference*/
float circleCircum(float radius-circ)
{
double circumference = 2*PI*radius-circ;
/*cout << "\nFor radius = " << radius-circ << ", the circle circumference is: " << circumference << ".\n";
/*printf("\nFor radius = %f, the circle circumference is: %f.\n" radius-circ, circumference);*/
return circumference;
}
/*Cube Volume*/
float cubeVolume(float side)
{
float volume = side^3;
/*cout << "\nFor any side of the cube being " << side << " units, the volume is " << volume << " units^3.\n";
/*printf("\nFor any side of the cube being %f units, the volume is %f units^3.\n" side, volume*/
return volume;
}
/* I'll work on more geometry later, and maybe even put in prompting functions... no guarantee*/
Yea, I was REALLY bored that night .
Tell me if you think I\'m spamming or doing something stupid, please.
-
March 30th, 2005, 12:26 PM
#4
Sorry to bring back "old" thread, but I just came across this one...
1. I know in school they told us PI ~ 22/7, but PI is NOT 22/7. PI is 3.141592653589793238...
Just google for 3.1415926535 and you'll find the higher precision values (I've seen up to 50 digits).
2. Have you tried to make use of the header file (#include and anything)?
The use of dash in variable names caught my eyes right away, also the first line of subtrack().
But then I let my compiler to decide anyway, and yes, it complains...
Now that's what I call bored.
Peace always,
<jdenny>
Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert Heinlein
I\'m basically a very lazy person who likes to get credit for things other people actually do. -- Linus Torvalds
-
March 30th, 2005, 01:55 PM
#5
Hi
...which brings me to the most useless url I have ever seen:
http://3.141592653589793238462643383...974944592.com/
edit: the url in two pieces
3.141592653589793238462643383279502
884197169399375105820974944592.com
Cheers.
If the only tool you have is a hammer, you tend to see every problem as a nail.
(Abraham Maslow, Psychologist, 1908-70)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|