Double sin(double x)

Am I the only person that was confused by this? I wasn’t sure what to do with that tidbit of information.

I wasn’t sure either.
I looked at the other solutions posted to help me along.
Math is certainly not a strong area of mine.

i also found difficult :-S

the solutions are good though… they work… its the understanding them bit i’m trying to get my head round :astonished:

I was confused as well. I guess it is more because my math skills are terrible. I didn’t understand exactly how the formula is applied. Therefore, I didn’t know how I was supposed to arrive at the answer shown in the book.

I was confused too until I looked at other responses. I still don’t understand why I need:


still works.

Why do I need the x?

The double sin(double x) is a declaration of the sin() function as the book states it is, it wouldn’t be how you use it. The actual way to use sin() would be:

double answer;
answer = sin(1);

The ‘x’ is just a placeholder, it could have been ‘y’, ‘arg’, ‘whatever’.

A declaration tells you how to use the function, what the input (arguments) and output (return value) types are, and from there you can use the function.


// Declare my own function called doverylittle
double doverylittle(double x, float y, int z);

Then to use this function in your main code:

void main()
double answer;
answer = doverylittle(2.34, 5.6, 7);

And somewhere in some file would be the actual function code:

double doverylittle(double x, float y, int z)
return x + y - z;

The book will probably expand on this soon enough!

Here is my take, which works:

[code]#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {

   printf("the sine of 1 radian is %.3f.\n", sin(1));
return 0;

The easiest way.
We could moreover input a variable to replace 1, so it would give the following code which works too:

[code]#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {

double x = 1;
printf("the sine of %.0f radian is %.3f.\n", x, sin(x));
return 0;


I was confused too, but I think I’ve found the answer. Although the examples in the other answers are great, I don’t think anyone has explained specifically why ‘double’ appears before the function, which throws an error if actually included in the code.

Looking at the man page below (as the author helpfully recommends), the first ‘double’ is in fact just a label to indicate the usage of sin() with a double precision number. Unfortunately, in the book, it was inserted on the same line as the function. It’s not a part of the function call and shouldn’t be included in your code. Perhaps in any future editions, the first ‘double’ could be simply deleted or placed on a separate line, as in the man page.

The ‘x’ is a placeholder for whatever variable you use. The ‘double’ in ‘double x’ shows that sin() expects a double precision variable its argument, but I’m guessing it will be in the type declaration for your variable, not in the sin() call. I’d appreciate a comment if that isn’t generally the case or anything else is wrong, I’m just a beginner :slight_smile:

The other examples in the man page show how to use the sine function with other types.

[quote]The sine function is declared like this:
double sin( double x);[/quote]

[quote]SIN(3) BSD Library Functions Manual SIN(3)

sin – sine function

#include <math.h>

 sin(double x);

 long double
 sinl(long double x);

 sinf(float x);

The sin() function computes the sine of x (measured in radians).