[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: another 754R proposal to vote on



WARNING: This is a lengthy commentary, because I fear that existing
technology and standards are being overlooked.

In
        http://754r.ucbtest.org/ballots/integral.txt
is the proposed text:

>> ...
>>    * aint(x) rounds x to an integral value toward zero.
>>      [name suggestive of Fortran AINT].
>>    * ceil(x) rounds x to an integral value toward positive infinity.
>>      [name suggestive of C ceil].
>>    * floor(x) rounds x to an integral value toward negative infinity.
>>      [name suggestive of C floor].
>> ...

Rather than mixing Fortran and C notation, why not stick with one
language: C?

Here is what the 1999 ISO C Standard has to say:

>> ...
>>      7.12.9.8 The trunc functions
>>
>>      Synopsis
>>
>> 1        #include <math.h>
>>          double trunc(double x);
>>          float truncf(float x);
>>          long double truncl(long double x);
>>
>>      Description
>>
>> 2    The trunc functions round their argument to the integer value, in
>>      floating format, nearest to but no larger in magnitude than the
>>      argument.
>>
>>      Returns
>>
>> 3    The trunc functions return the truncated integer value.
>> ...

Thus, aint(x) could be replaced by trunc(x), and the proposal is then
in agreement with an already-accepted, but alas, not yet
widely-implemented, international programming language standard for
what is likely the most widely-used programming language today.

The rationale in integral.txt then goes on to say:

>> ...
>> Additional functions to staticly round to nearest, ties to even,
>> or to dynamically round according to current rounding mode, are plausible
>> additions to this proposal but I don't think usage would warrant them.
>> ...

Once again, the 1999 ISO C Standard already completely supports ALL of
the features in that statement:

>> ...
>>      7.12.9.3 The nearbyint functions
>>
>>      Synopsis
>>
>> 1        #include <math.h>
>>          double nearbyint(double x);
>>          float nearbyintf(float x);
>>          long double nearbyintl(long double x);
>>
>>      Description
>>
>> 2    The nearbyint functions round their argument to an integer value in
>>      floating-point format, using the current rounding direction and
>>      without raising the ``inexact'' floating- point exception.
>>
>>      Returns
>>
>> 3    The nearbyint functions return the rounded integer value.
>>
>>
>>
>>      7.12.9.4 The rint functions
>>
>>      Synopsis
>>
>> 1        #include <math.h>
>>          double rint(double x);
>>          float rintf(float x);
>>          long double rintl(long double x);
>>
>>      Description
>>
>> 2    The rint functions differ from the nearbyint functions (7.12.9.3)
>>      only in that the rint functions may raise the ``inexact''
>>      floating-point exception if the result differs in value from the
>>      argument.
>>
>>      Returns
>>
>> 3    The rint functions return the rounded integer value.
>>
>>
>>
>>      7.12.9.5 The lrint and llrint functions
>>
>>      Synopsis
>>
>> 1        #include <math.h>
>>          long int lrint(double x);
>>          long int lrintf(float x);
>>          long int lrintl(long double x);
>>          long long int llrint(double x);
>>          long long int llrintf(float x);
>>          long long int llrintl(long double x);
>>
>>      Description
>>
>> 2    The lrint and llrint functions round their argument to the nearest
>>      integer value, rounding according to the current rounding
>>      direction. If the rounded value is outside the range of the
>>      return type, the numeric result is unspecified. A range error may
>>      occur if the magnitude of x is too large.
>>
>>      Returns
>>
>> 3    The lrint and llrint functions return the rounded integer value.
>>
>>
>>
>>      7.12.9.6 The round functions
>>
>>      Synopsis
>>
>> 1        #include <math.h>
>>          double round(double x);
>>          float roundf(float x);
>>          long double roundl(long double x);
>>
>>      Description
>>
>> 2    The round functions round their argument to the nearest integer value
>>      in floating-point format, rounding halfway cases away from zero,
>>      regardless of the current rounding direction.
>>
>>      Returns
>>
>> 3    The round functions return the rounded integer value.
>>
>>
>>
>>      7.12.9.7 The lround and llround functions
>>
>>      Synopsis
>>
>> 1        #include <math.h>
>>          long int lround(double x);
>>          long int lroundf(float x);
>>          long int lroundl(long double x);
>>          long long int llround(double x);
>>          long long int llroundf(float x);
>>          long long int llroundl(long double x);
>>
>>      Description
>>
>> 2    The lround and llround functions round their argument to the nearest
>>      integer value, rounding halfway cases away from zero, regardless
>>      of the current rounding direction. If the rounded value is
>>      outside the range of the return type, the numeric result is
>>      unspecified.  A range error may occur if the magnitude of x is
>>      too large.
>>
>>      Returns
>>
>> 3    The lround and llround functions return the rounded integer value.
>> ...

The IEEE Std 1003.1-2001 Standard (informally known as POSIX) (and
likely, also the new 2004 one, which I do not yet have) defers to 1999
ISO C Standard for many functions, including ALL of those cited above
from the latter.

The ISO Fortran 95 Standard does not address the question of rounding
mode at all, so it provides little guidance to the integral.txt
proposal.  It offers only these:

    AINT  (A  [, KIND])		Truncation to whole number
    ANINT  (A  [, KIND])	Nearest whole number
    CEILING  (A	 [, KIND])	Least integer greater than or equal to number
    FLOOR (A [, KIND]) 		Greatest integer less than or equal to number
    INT	 (A  [, KIND])		Conversion to integer type
    NINT  (A  [, KIND])		Nearest integer

The 1998 and 2003 ISO C++ Standards mostly subsume the 1989 ISO C
Standard (ignoring the 1999 one), so they too offer little guidance.

Given the numerical deficiencies of Java (cf. the well-known article
``How Java's Floating-Point Hurts Everyone Everywhere'' by two members
of this Committee), we can find no help there either.  Java's
java.lang.math class offers only ceil(), floor(), rint(), and round()
in the subject area of integral.txt, and permits only one
(round-to-nearest/even) of the four IEEE 754 rounding modes.

The other programming languages standardized by ISO (Ada, APL, Basic,
Cobol, FIMS, Forth, M, Modula-2, MUMPS, Pascal, PL/1, Prolog, Scheme,
and SQL) might have some guidance, but I don't have copies of any of
the recent ones, and I doubt very much whether any is as comprehensive
as 1999 ISO Standard C.

The Revised(5) Report on the Algorithmic Language Scheme, available at

	http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs.html

describes (floor x), (ceiling x), (truncate x), (round x).  These are
analogous to functions already cited for C99.

It took nearly 20 years for language standards to even admit that IEEE
754 arithmetic exists (and today, is nearly universal), and
programmers are still blocked from portable access to many of its
features.

C99 is a BIG leap forward, but we are now 5 years and 5 months past
its formal publication, and most Unix systems still lack
fully-conforming C99 compilers.  On the 20+ flavors of Unix that I
routinely build and test code on, in over 100 different C and C++
environments, I know of only three that claim conformance: Intel icc
on IA-32, IA-64, EM64T, and AMD64, Sun Solaris 10 c99, and
Hewlett-Packard HP-UX 11 c99).  Recent GNU gcc is close, and even has
a c99 program, but is in fact not there yet.  {Free,Net,Open}BSD C
compilers do not even provide access to long double, almost 25 years
after the Intel 8087 hit the market with hardware support for it.
Argh...

-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                    FAX: +1 801 581 4148                  -
- Department of Mathematics, 110 LCB    Internet e-mail: beebe@xxxxxxxxxxxxx  -
- 155 S 1400 E RM 233                       beebe@xxxxxxx  beebe@xxxxxxxxxxxx -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe  -
-------------------------------------------------------------------------------


754 | revision | FAQ | references | list archive