开发者

Why does this code sometimes return NaN?

开发者 https://www.devze.com 2023-01-02 22:35 出处:网络
This often returns NAN (\"Not A Number\") depending on input: 开发者_如何转开发 #define PI 3.1415f

This often returns NAN ("Not A Number") depending on input:

开发者_如何转开发
#define PI 3.1415f

GLfloat sineEaseIn(GLfloat ratio) {
 return 1.0f-cosf(ratio * (PI / 2.0f));
}

I tried making PI a few digits smaller to see if that would help. No dice. Then I thought it might be a datatype mismatch, but float and glfloat seem to be equivalent:

gl.h

typedef float           GLfloat;

math.h

extern float  cosf( float );

Is this a casting issue?


I suspect that one of the following is afoot:

  • your input value to ratio may not be what you expect it to be, and ratio itself is possibly NaN
  • the cosf that you're calling isn't the one in math.h

Otherwise, there doesn't appear to be anything wrong with your expression.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号