[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
int fesetround (int ROUND) returns 0 if ok, 1 if not ok
From: |
Conrado Badenas |
Subject: |
int fesetround (int ROUND) returns 0 if ok, 1 if not ok |
Date: |
Thu, 02 Nov 2000 13:37:13 +0100 |
Dear glibc maintainer,
I sent this same bug report to the maintainer of the Debian packages
libc6 and glibc-doc, but I have not obtained an answer in six weeks.
Today I have decided to download the file glibc-2.1.3.tar.gz (Feb 25
2000 8803k) from a GNU mirror site. I have examined the source files,
and now I know what happens:
$ info libc Rounding
[...]
- Function: int fesetround (int ROUND)
Changes the currently selected rounding mode to ROUND. If ROUND
does not correspond to one of the supported rounding modes nothing
is changed. `fesetround' returns a nonzero value if it changed
the rounding mode, zero if the mode is not supported.
[...]
but...
$ cat nothing.c
#include <stdio.h>
#include <fenv.h>
void setandprintround(int i) {
printf ("%.8x (%d) ==> ",i,fesetround(i));
i=fegetround();
if (i==FE_TONEAREST) printf("To nearest\n");
else if (i==FE_UPWARD) printf("Upward\n");
else if (i==FE_DOWNWARD) printf("Downward\n");
else if (i==FE_TOWARDZERO) printf("Toward 0\n");
else printf("UNKNOWN!!!\n");
}
main() {
int i;
setandprintround(rand());
setandprintround(FE_TOWARDZERO);
setandprintround(FE_DOWNWARD);
setandprintround(FE_UPWARD);
setandprintround(FE_TONEAREST);
}
$ gcc nothing.c -o nothing -lm
$ nothing
6b8b4567 (1) ==> To nearest
00000c00 (0) ==> Toward 0
00000400 (0) ==> Downward
00000800 (0) ==> Upward
00000000 (0) ==> To nearest
fesetround() returns 0 if it changes the rounding mode, and 1 (not zero)
if it can't change the rounding mode.
The file glibc-2.1.3/sysdeps/i386/fpu/fesetround.c contains:
fesetround (int round)
{
unsigned short int cw;
if ((round & ~0xc00) != 0)
/* ROUND is no valid rounding mode. */
return 1;
__asm__ ("fnstcw %0" : "=m" (*&cw));
cw &= ~0xc00;
cw |= round;
__asm__ ("fldcw %0" : : "m" (*&cw));
return 0;
}
which means that fesetround returns 0 if ok, and 1 if not ok. The files
fesetround.c for other architectures do the same (0 if ok, 1 of not ok).
Thus, the glibc documentation should be changed to contain
- Function: int fesetround (int ROUND)
Changes the currently selected rounding mode to ROUND. If ROUND
does not correspond to one of the supported rounding modes nothing
is changed. `fesetround' returns zero if it changed the rounding
mode, a nonzero value if the mode is not supported.
Thank you very much for your patiente.
--
Conrado Badenas <address@hidden>
PhD student | Assistant Lecturer
Department of Thermodynamics | Department of Exp. Sciences
Faculty of Physics | Univ. School of Tech. and Exp. Sciences
University of Valencia | University Jaume I
c/. Dr. Moliner, 50 | Campus del Riu Sec
46100 Burjassot (Valencia) | 12071 Castellón
SPAIN
- int fesetround (int ROUND) returns 0 if ok, 1 if not ok,
Conrado Badenas <=