pow(0.99, 2.5) returns nan?
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]
Nothing, as far as I can tell. Can you guarantee that the values being supplied are always valid? Have you watched the function over several iterations?
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
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
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.
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.
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.
you need to use %e or %g, or cast the function result to a float. Your code is working fine.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement