Tải bản đầy đủ (.pdf) (11 trang)

Mathematics

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (392.3 KB, 11 trang )

122
15. Mathematics
It's your favorite subject: Mathematics! Hello, I'm Doctor Math, and I'll be making math FUN
and EASY!
[vomiting sounds]
Ok, I know math isn't the grandest thing for some of you out there, but these are merely
functions that quickly and easily do math you either know, want, or just don't care about. That
pretty much covers it.
For you trig fans out there, we've got all manner of things, including sine, cosine, tangent, and,
conversely, arc sine, arc cosine, and arc tangent. That's very exciting.
And for normal people, there is a slurry of your run-of-the-mill functions that will serve your
general purpose mathematical needs, including absolute value, hypotenuse length, square root, cube
root, and power.
In short, you're a fricking MATHEMATICAL GOD!
Oh wait, before then, I should tell you that the trig functions have three variants with different
suffixes. The “f” suffix (e.g. sinf()) returns a float, while the “l” suffix (e.g. sinl()) returns
a massive and nicely accurate long double. Normal sin() just returns a double. These are
extensions to ANSI C, but they should be supported by modern compilers.
Also, there are several values that are defined in the math.h header file.
M_E
e
M_LOG2E
log_2 e
M_LOG10E
log_10 e
M_LN2
log_e 2
M_LN10
log_e 10
M_PI
pi


M_PI_2
pi/2
M_PI_4
pi/4
M_1_PI
1/pi
M_2_PI
2/pi
Beej's Guide to C Programming 123
M_2_SQRTPI
2/sqrt(pi)
M_SQRT2
sqrt(2)
M_SQRT1_2
1/sqrt(2)
Beej's Guide to C Programming 124
15.1. sin(), sinf(), sinl()
Calculate the sine of a number.
Prototypes
#include <math.h>
double sin(double x);
float sinf(float x);
long double sinl(long double x);
Description
Calculates the sine of the value x, where x is in radians.
For those of you who don't remember, radians are another way of measuring an angle, just like
degrees. To convert from degrees to radians or the other way around, use the following code:
degrees = radians * 180.0f / M_PI;
radians = degrees * M_PI / 180;
Return Value

Returns the sine of x. The variants return different types.
Example
double sinx;
long double ldsinx;
sinx = sin(3490.0); // round and round we go!
ldsinx = sinl((long double)3.490);
See Also
cos(), tan(), asin()
Beej's Guide to C Programming 125
15.2. cos(), cosf(), cosl()
Calculate the cosine of a number.
Prototypes
#include <math.h>
double cos(double x)
float cosf(float x)
long double cosl(long double x)
Description
Calculates the cosine of the value x, where x is in radians.
For those of you who don't remember, radians are another way of measuring an angle, just like
degrees. To convert from degrees to radians or the other way around, use the following code:
degrees = radians * 180.0f / M_PI;
radians = degrees * M_PI / 180;
Return Value
Returns the cosine of x. The variants return different types.
Example
double sinx;
long double ldsinx;
sinx = sin(3490.0); // round and round we go!
ldsinx = sinl((long double)3.490);
See Also

sin(), tan(), acos()
Beej's Guide to C Programming 126
15.3. tan(), tanf(), tanl()
Calculate the tangent of a number.
Prototypes
#include <math.h>
double tan(double x)
float tanf(float x)
long double tanl(long double x)
Description
Calculates the tangent of the value x, where x is in radians.
For those of you who don't remember, radians are another way of measuring an angle, just like
degrees. To convert from degrees to radians or the other way around, use the following code:
degrees = radians * 180.0f / M_PI;
radians = degrees * M_PI / 180;
Return Value
Returns the tangent of x. The variants return different types.
Example
double tanx;
long double ldtanx;
tanx = tan(3490.0); // round and round we go!
ldtanx = tanl((long double)3.490);
See Also
sin(), cos(), atan(), atan2()

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×