Archived

This topic is now archived and is closed to further replies.

jvff

pow(0.99, 2.5) returns nan?

Recommended Posts

Hello, I'm trying to do the phong illumination equation but when I do: float rdotv = ray.dot(view); float shine = pow(fabs(rdotv), getRoghness()) * getSpecular(); the shine is not a number. I know after debugging that specular is 0.9, rdotv is 0.99 and roughness is 2.5. What's wrong with the code? Thanks for your answers, EDIT: Fixed code JVFF [edited by - jvff on March 20, 2004 3:42:28 PM]

Share this post


Link to post
Share on other sites
Yes it''s always valid. I did a

printf("%f, %f, %f", fabs(rdotv), getRoughness(), pow(fabs(rdotv), getRoughness()))

and I always get "0.999xxx, 2.500000, nan". Where ''x'' is variable.

Can''t I pass float values to pow? Thank you,

JVFF

Share this post


Link to post
Share on other sites
OK have you actually tried typing
float x = pow(0.99, 2.5) * 0.9;
into your program and seeing that it definately does the same thing as your phong illumination code? If it does then perhaps either your debugger is lying to you, or perhaps your CPU is overclocked too much.
I get about 0.877668 in MSVC++ 6.

Share this post


Link to post
Share on other sites
Oh I see your problem, your printf statement is expecting a float (because of the %f) but you''re passing it a double. printf does not check the types so it''s assuming that the first four bytes of the double are a float which is not the case.
you need to use %e or %g, or cast the function result to a float. Your code is working fine.

Share this post


Link to post
Share on other sites
ThanX. It works now I put a (double) before each argument to the pow function. And yeah, it was printf''s fault. Thank you again,

JVFF

Share this post


Link to post
Share on other sites