sin v/s sinf function in C
Solution 1
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))
Solution 2
sin takes a double and returns a double and is defined by ANSI C. sinf isn't.
Solution 3
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
).
Related videos on Youtube
Viks
Updated on April 21, 2022Comments
-
Viks about 2 years
I am trying to use the
sinf
function in my C Program but it gives me an undefined reference error under MSVC 6.0, howeversin
works fine.This make me curious to find the difference between
sin
andsinf
.What is the logical difference between
sin
andsinf
?How can I implement my own
sinf
functionality? -
James McNellis about 14 years
sinf()
is not standard in C89. It is standard in C99.