From: interval@my-deja.com
Subject: problem with the function ecvt
Date: 1999/12/01 [thread overview]
Message-ID: <823maf$lbi$1@nnrp1.deja.com> (raw)
The documentation describes that the function ecvt rounds the number
according to the rounding mode.
I try to use it but I get wrong values.
My program is :
/*---------------*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
void print(double t);
void print(double t)
{
int dec,sign;
char *buffer;
printf("%E :",t);
buffer=ecvt(t,10,&dec,&sign);
printf("%c%s (%d)\n",(sign==0)?'+':'-',buffer,dec);
}
int main(void)
{
double pi;
write_rnd(FP_RND_RN);
printf("round mode:%u\n",read_rnd());
pi=atan2(0.E0,-1.E0);
print(pi);
print(-pi);
write_rnd(FP_RND_RP);
printf("round mode:%u\n",read_rnd());
print(pi);
print(-pi);
write_rnd(FP_RND_RM);
printf("round mode:%u\n",read_rnd());
print(pi);
print(-pi);
return 0;
}
/*--------*/
I compile it with : cc -fprm d -ieee ecv.c -lm
I get these results :
round mode:1
3.141593E+00 :+3141592654 (1)
-3.141593E+00 :-3141592654 (1)
round mode:2
3.141593E+00 :+3141592654 (1)
-3.141593E+00 :-3141592654 (1)
round mode:3
3.141593E+00 :+3141592654 (1)
-3.141593E+00 :-3141592654 (1)
What is wrong in my program ?
Thanks
Sent via Deja.com http://www.deja.com/
Before you buy.
reply other threads:[~1999-12-01 5:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox