Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!mcsun!hp4nl!star.cs.vu.nl!engbert From: engbert@cs.vu.nl (Engbert Gerrit IJff) Newsgroups: comp.lang.c Subject: Re: Implementation of pow(3m) function Message-ID: <7254@star.cs.vu.nl> Date: 7 Aug 90 22:49:45 GMT References: <1990Aug2.120706.25713@bnrgate.bnr.ca> <13474@smoke.BRL.MIL> <46584@brunix.UUCP> <11143@alice.UUCP> <10803@crdgw1.crd.ge.com> Sender: news@cs.vu.nl Reply-To: engbert@cs.vu.nl (Engbert Gerrit IJff) Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 45 In article <10803@crdgw1.crd.ge.com>, volpe@underdog.crd.ge.com (Christopher R Volpe) writes: ) In article <11143@alice.UUCP>, ark@alice.UUCP (Andrew Koenig) writes: ) |>If such an ) |>implementation uses exp and log for the ordinary cases, it will ) |>almost surely not be monotonic. That is, it will be possible to ) |>find positive x, y, and z such that y > z and pow(x,y) < pow(x,z). ) ) I sure hope so, since there are trivial real-life cases where this is ) true. E.g.: x=0.5, y=3, z=2. pow(x,y)=.125 < pow(x,z)=.25 ) ) Am I missing something???? ) ) |>-- ) |> --Andrew Koenig ) |> ark@europa.att.com ) ) Chris Volpe ) GE Corporate R&D ) volpecr@crd.ge.com Well, althoug Andrews story was right, the example might not have sufficient as an explanation. There are, in fact, two cases, both of which shouldn't, but could occur if the implementation uses several speed optimizing strategies. One could probably find: some y > z > 0 and x > 1 where pow(x,y) <= pow(x,z) some y > z > 0 and 0 < x < 1 where pow(x,y) >= pow(x,z) A correct implementation should give: / if x > 1 then pow(x,y) > pow(x,z) for all y > z > 0 { \ if 0 < x < 1 then pow(x,y) < pow(x,z) as we expect it to be. Bert IJff Free University Amsterdam ------------------------------------- "The power of a math library function is not always in its speed." Bert