• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: using lgamma_r
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using lgamma_r


  • Subject: Re: using lgamma_r
  • From: Michael McLaughlin <email@hidden>
  • Date: Tue, 04 Mar 2008 13:26:41 -0500
  • Thread-topic: using lgamma_r



On 3/4/08 12:58 PM, "Jeremy Pereira" <email@hidden> wrote:

>
> On 28 Feb 2008, at 16:52, Michael McLaughlin wrote:
>
>> I have a multi-threaded CoreServices C++ tool project built for OS
>> 10.5.  I
>> want/need to use lgamma_r in one of my functions.  Therefore, as
>> stated in
>> math.h, I added the precompiler flag
>>
>> -D_REENTRANT
>>
>> to the Build options.
>>
>> The relevant code fragment, viz.,
>>
>> double pdf(double x, double lambda) {
>> int   *signgam;
>> double logpdf = x*log(lambda) - lambda - lgamma_r(x + 1, signgam);
>> ...
>> }
>>
>> builds successfully with ppc architecture but *fails* when the i386
>> architecture is added. [I need the latter for a universal binary.]
>> The
>> build results confirm that the i386 compile is what fails.
>>
>> Math.h mentions lgamma_r in just one block and says nothing special
>> about
>> i386.
>
> On my system, math.h doesn't mention lgamma_r or, in fact, anything
> useful other than including an architecture specific version of
> math.h.  If you look at the i386 version  of math.h in /usr/include/
> architecture.i386, you'll notice that lgamma_r is not defined there
> which is probably where your error comes from.
>
Yes, it appears to be limited to ppc.  In both my 10.4 and 10.5 SDKs, there
is a block near the end of math.h (ppc) as follows:

/*
 * Reentrant version of gamma & lgamma; passes signgam back by reference
 * as the second argument; user must allocate space for signgam.
 */
#ifdef _REENTRANT
extern double gamma_r ( double, int * );
extern double lgamma_r ( double, int * );
#endif /* _REENTRANT */
#endif /* (!_XOPEN_SOURCE || _DARWIN_C_SOURCE) */
#endif /* !_ANSI_SOURCE && (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */

#endif /* __WANT_EXTENSIONS__ */

> Incidentally, if you use your code exactly as specified in your mail,
> then I'm amazed if you don't often see bus errors or equivalent -
> you're passing an unitialised pointer to lgamma_r.

That was indeed bad code and never really used (since it never compiled for
i386).  I changed it later to pass the address of a local integer.  Works
fine for PPC.

I am at a loss, however, as to why there is no equivalent for i386.  The
prototype for the latter is essentially the same as for the non-recursive
version.

--
Mike McLaughlin

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: using lgamma_r (From: Jeremy Pereira <email@hidden>)

  • Prev by Date: Re: Code Index with "*.hh" Files
  • Next by Date: Setting is not defined in Project, Target or Application level, but not default either.
  • Previous by thread: Re: using lgamma_r
  • Next by thread: Re: using lgamma_r
  • Index(es):
    • Date
    • Thread