Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* problem with the function ecvt
@ 1999-12-01  5:00 interval
  0 siblings, 0 replies; only message in thread
From: interval @ 1999-12-01  5:00 UTC (permalink / 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.



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-12-01  5:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-12-01  5:00 problem with the function ecvt interval

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox