[comp.lang.c] log function

stadt@cs.utwente.nl (Richard van de Stadt) (06/21/91)

I get the error message
log: SING error

when the statement 

store_control_parameter (mean / log (1/get_acceptance_ratio_X0()))

is executed.

Does anybody know what the error message means?

The same message appears when I split up the statement:
tolog = 1/get_acceptance_ratio_X0();   /* tolog has then value 1.25 */
loggie = log (tolog);  /* now this is the statement that causes the message */
store_control_parameter (mean / loggie);

Richard.

-- 
R.R. van de Stadt (Richard)
Email: stadt@cs.utwente.nl

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (06/21/91)

In article <1991Jun21.113211@cs.utwente.nl>, stadt@cs.utwente.nl (Richard van de Stadt) writes:
> I get the error message
> log: SING error
from
> store_control_parameter (mean / log (1/get_acceptance_ratio_X0()))
> Does anybody know what the error message means?

If you R the FM (it looks as though you're using System V, so the FM in
question is 'man 3 exp' or 'man 3 matherr', I looked up the SVID v1) it
tells you that SING from log() or log10() means that the argument is
not positive.

> The same message appears when I split up the statement:
> tolog = 1/get_acceptance_ratio_X0();   /* tolog has then value 1.25 */
> loggie = log (tolog);  /* now this is the statement that causes the message */

This is very strange.  Have you tried writing a program that just evaluates
log(1.25) and seeing what it does?

By the way, I note that log(1/x) = -log(x), so
	store_control_parameter(-mean/log(get_acceptance_ratio_X0()));
should compute the same thing.  Does it fail the same way?

What does the declaration of log() in your <math.h> look like?
Does lint tell you anything interesting?
-- 
I agree with Jim Giles about many of the deficiencies of present UNIX.

kremer@cs.odu.edu (Lloyd Kremer) (06/25/91)

In article <1991Jun21.113211@cs.utwente.nl> stadt@cs.utwente.nl (Richard van de Stadt) writes:
>
>I get the error message
>log: SING error
>
>when the statement 
>store_control_parameter (mean / log (1/get_acceptance_ratio_X0()))
>is executed.
>
>Does anybody know what the error message means?
>
>The same message appears when I split up the statement:
>tolog = 1/get_acceptance_ratio_X0();   /* tolog has then value 1.25 */
>loggie = log (tolog);  /* now this is the statement that causes the message */
>store_control_parameter (mean / loggie);
>

SING error is the result of an operation producing a mathematical singularity.
For the log() function, a singularity exists for log(0.0).  I believe taking
the log of a negative number would cause a DOMAIN error rather than SING.

So the log() function thinks it's being handed a 0.0 argument.

The log() function takes a double and returns a double, yet I see the integral
constant "1" in the argument to log in your code.  If no prototype is in scope,
maybe an integral bit pattern is being passed to log(), which then interprets
the pattern as a double representing the value 0.0 .  As a first step, I would
explicitly cast log's argument to double and see what happens.

Passing the type float will not work either unless the compiler does automatic
float-to-double promotion or a prototype is in scope.

					Lloyd Kremer
					Hilton Systems, Inc.
					kremer@cs.odu.edu