Sin v / s sinf in C

I am trying to use the sinf function in my C program, but it gives me an undefined reference error in MSVC 6.0, however sin working fine.

I am interested to know the difference between sin and sinf .

What is the logical difference between sin and sinf ?

How can I implement my own sinf functions?

+7
c math floating-point visual-c ++ sin
source share
3 answers

sin takes a double and returns double - sinf takes a float and returns a float.

In other words, sin is double precision, and sinf is single precision.

If you are using an old compiler that does not have sinf, you can implement it as:

#define sinf(x) (float)sin((double)(x))

+7
source share

sin takes a double and returns double and is determined by ANSI C. sinf is not.

+3
source share

sinf() was added to C on C99, which Microsoft Visual C ++ does not fully support (even though Visual C ++ 6 was released before the standardization of C99).

You can use the sin() function, which takes a double ( sinf() takes a float ).

+2
source share

All Articles