views:

149

answers:

3

Hi Guys,

I am trying to use sinf function in my C Program and it does give me undefined reference under MSVC 6.0 but sin works fine.

This make me curious to find the difference between sin and sinf.

What is the logical difference between sin and sinf().

How can I implement my own sinf functionality?

+2  A: 

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

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

If you're using an old compiler that doesn't have sinf you can implement it as:

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

Paul R
+2  A: 

sin takes a double and returns a double and is defined by ANSI C. sinf isn't.

Apprentice Queue
`sinf()` is not standard in C89. It _is_ standard in C99.
James McNellis
This reveals that I'm old.
Apprentice Queue
+2  A: 

sinf() was added to C in C99, which Microsoft Visual C++ does not fully support (even so, Visual C++ 6 was released before C99 was standardized).

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

James McNellis
"Doesn't fully support" is pretty much the understatement of the decade =)
Stephen Canon