pow(0.99, 2.5) returns nan?

Started by
4 comments, last by jvff 20 years, 1 month ago
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]
ThanQ, JVFF (Janito Vaqueiro Ferreira Filho)
Advertisement
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
ThanQ, JVFF (Janito Vaqueiro Ferreira Filho)
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.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
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.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
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
ThanQ, JVFF (Janito Vaqueiro Ferreira Filho)

This topic is closed to new replies.

Advertisement