Re: NOT solved: using long double math functions like sinl() with Cocoa
Re: NOT solved: using long double math functions like sinl() with Cocoa
- Subject: Re: NOT solved: using long double math functions like sinl() with Cocoa
- From: "Dr. Rolf Jansen" <email@hidden>
- Date: Fri, 12 Jan 2007 07:34:01 -0200
Am 12.01.2007 um 04:27 schrieb Nir Soffer:
On Jan 12, 2007, at 01:59, Dr. Rolf Jansen wrote:
#include <stdio.h>
#include <math.h>
int main (int argc, const char * argv[])
{
printf("%f\n%Lf", sin(1.5707963267948966), // pi/2
sinl(1.57079632679489661923132169163974L));
return 0;
}
This run fine on G5. Create new Foundation tool with this main.m:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
assert(sin(1.5707963267948966) == sinl
(1.57079632679489661923132169163974L));
return 0;
}
Seems like printf formatting issue.
Best Regards,
Nir Soffer
This would also run fine at my PowerBook G4, since the "Foundation.h"
includes "fp.h" which redefines the long double sinl() to the double
sin(), and that gives correct results.
This was my original problem from last week, which I thought that i
could solve it (see below)
Best regards
Rolf Jansen
Anfang der weitergeleiteten E-Mail:
Von: "Dr. Rolf Jansen" <email@hidden>
Datum: 3. Januar 2007 21:59:59 GMT-02:00
An: email@hidden
Betreff: using long double math functions like sinl() with Cocoa
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