[LC++]Can I rely on log(0) = -inf ?

Dr Mark H Phillips mark at austrics.com.au
Wed Oct 2 15:41:01 UTC 2002


Hi,

If I do

  cout<<"  log(0)      = "<<log(0)<<endl;
  cout<<"  int(log(0)) = "<<int(log(0))<<endl;

I get 

  log(0)      = -inf
  int(log(0)) = -2147483648

Is "-inf" an "official double number"?  Is this true across 
architectures, or only for Intel?

Is the int cast of -inf guaranteed to give the minimum integer
or is this only gcc behaviour?

What I want to do is use the test

  if (log(x)>0)
    ...;

and have it do the sensible thing in the case of x=0, but can
I rely on this, or should I do the more complicated:

  if (x>0 && log(x)>0)
    ...;

Thanks,

Mark.

-- 
Dr Mark H Phillips
Research Analyst (Mathematician)

AUSTRICS - smarter scheduling solutions - www.austrics.com

Level 2, 50 Pirie Street, Adelaide SA 5000, Australia
Phone +61 8 8226 9850
Fax   +61 8 8231 4821
Email mark at austrics.com.au




More information about the tuxCPProgramming mailing list