• 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
using long double math functions like sinl() with Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using long double math functions like sinl() with Cocoa


  • Subject: using long double math functions like sinl() with Cocoa
  • From: "Dr. Rolf Jansen" <email@hidden>
  • Date: Wed, 3 Jan 2007 21:59:59 -0200

PowerBook G4, Mac OS X 10.4.8, Xcode 2.4.1

I tried to use long double math functions in my cocoa application and got the program compiling and running, but the function results were double and not long double.

Here is a test case built directly from the Cocoa Application template. sin(pi) should give zero, of course within the limits of the expected math precision.

//  main.m
//  CocoaSinTest

#import  <Cocoa/Cocoa.h>
#include <math.h>

int main(int argc, char *argv[])
{
    printf("%-.16f\n%-.33Lf", sin(3.1415926535897932),
                             sinl(3.1415926535897932384626433832795L));
    return NSApplicationMain(argc,  (const char **) argv);
}

[Session started at 2007-01-03 21:38:48 -0200.]
0.0000000000000001
0.000000000000000122464679914735321

Both results are 1e-16, wich is the precision of 64bit double math.

Digging into the assembly code, I found out, that in both cases the sin function is called and not the sinl function.


A pure C program builded from the Standard Tool template works as expected:


// main.c
// SinTest

#include <stdio.h>
#include <math.h>

int main (int argc, const char * argv[])
{
    printf("%-.16f\n%-.33Lf", sin(3.1415926535897932),
                             sinl(3.1415926535897932384626433832795L));
    return 0;
}

[Session started at 2007-01-03 21:43:39 -0200.]
0.0000000000000001
0.000000000000000000000000000000022

The second result seems to be indeed zero within the limits of 128bit long double precision.


QUESTIONS:

- are long double functions supposed to give in Cocoa applications
  long double results as they do in pure C?

- is there a compiler switch, which activates the
  expected behaviour?

- am I missing something obvious?

Best regards

Rolf Jansen





_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Switch/case with NSString?
  • Next by Date: Re: using long double math functions like sinl() with Cocoa
  • Previous by thread: Catching a keyDown within draggingUpdated
  • Next by thread: Re: using long double math functions like sinl() with Cocoa
  • Index(es):
    • Date
    • Thread