sin v/s sinf function in C

左心房为你撑大大i 提交于 2019-12-19 06:26:14

问题


I am trying to use the sinf function in my C Program but it gives me an undefined reference error under MSVC 6.0, however 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?


回答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))




回答2:


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




回答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).



来源:https://stackoverflow.com/questions/2841639/sin-v-s-sinf-function-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!