Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2003:
[Freeciv-Dev] Re: (PR#6781) Cleanups
Home

[Freeciv-Dev] Re: (PR#6781) Cleanups

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#6781) Cleanups
From: "Raimar Falke" <i-freeciv-lists@xxxxxxxxxxxxx>
Date: Sun, 9 Nov 2003 10:44:21 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=6781 >

On Sun, Nov 09, 2003 at 10:05:49AM -0800, Jason Short wrote:
> 
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=6781 >
> 
> Gregory Berkolaiko wrote:
> > <URL: http://rt.freeciv.org/Ticket/Display.html?id=6781 >
> > 
> > On Thu, 6 Nov 2003 rt@xxxxxxxxxxx wrote:

The new RT adds these urls. Is this a feature or a bug?

> >>2)
> >>ai/aiunit.c:591:134: Expression has undefined behavior (left operand
> >>uses errno, modified by right operand): log(most_desirable / ((((100 *
> >>5 * 81 + 100 * (9 - 5) * 51) + 1) + 1) + (100 * 5 * 81 + 100 * (9 - 5)
> >>* 51))) / log(0.6)
> >>Code has unspecified behavior. Order of evaluation of function
> >>parameters or subexpressions is not defined, so if a value is used and
> >>modi fied in different places not separated by a sequence point
> >>constraining evaluation order, then the result of the expression is
> >>unspecified.
> > 
> > 
> > I do not understand this error at all.  Mathmatically, the order of 
> > evaluation is well defined.
> 
> Presumably log is a macro which modifies the value of errno.  It is 
> illegal to do this multiple times within the same "sequence".
> 
> Seems like a bug in the implementation of log, to me.  The way to work 
> around it would be
> 
>    a = log (...)
>    b = log (...)
>    a / b

This is what I did in the patch.

> although complaining to the library writers is probably just as good of 
> a solution.

You have to go to the ISO people and not the the glibc one. The
standard even explicitly cite log():

   A floating result overflows if the magnitude of the mathematical
   result is finite but so large that the mathematical result cannot
   be represented without extraordinary roundoff error in an object of
   the specified type. If a floating result overflows and default
   rounding is in effect, or if the mathematical result is an exact

   infinity (for example log(0.0)), then the function returns the

   value of the macro HUGE_VAL, HUGE_VALF,or HUGE_VALL according to
   the return type, with the same sign as the correct value of the
   function; if the integer expression math_errhandling & MATH_ERRNO
   is nonzero, the integer expression errno acquires the value ERANGE;
   if the integer expression math_errhandling & MATH_ERREXCEPT is
   nonzero, the divide-by-zero floating-point exception is raised if
   the mathematical result is an exact infinity and the overflow
   floating-point exception is raised otherwise.

And:

   The log functions compute the base-e (natural) logarithm of x. A
   domain error occurs if the argument is negative. A range error may
   occur if the argument is zero.

So it is a feature and not a bug.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 checking for the vaidity of the Maxwell laws on this machine... ok
 checking if e=mc^2... ok
 checking if we can safely swap on /dev/fd0... yes
    -- kvirc 2.0.0's configure 




[Prev in Thread] Current Thread [Next in Thread]