> Quite possibly. At a quick glance, dtoa.java has very little resemblance
> to dtoa.c as shown here: http://www.netlib.no/netlib/fp/dtoa.c . If I'm
> wrong about this, please say where the resemblances are (other than the
> fact that they do the same thing, which is no indication.)

Very little resemblance???? I didn't get further than the first few lines
of the dtoa routine in both sources before recognizing all the authors
of dtoa.java had simply filtered the code to compile under java
removing the original copyright notice which I find an incredible
insult to the author....

To compare please go to the start of the dtoa routine (line 2629 of
dtoa.c) and you will find the following:

=============================================
 char *
dtoa
#ifdef KR_headers
 (d, mode, ndigits, decpt, sign, rve)
 double d; int mode, ndigits, *decpt, *sign; char **rve;
#else
 (double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
#endif
{
 /* Arguments ndigits, decpt, sign are similar to those
 of ecvt and fcvt; trailing zeros are suppressed from
 the returned string.  If not null, *rve is set to point
 to the end of the return value.  If d is +-Infinity or NaN,
 then *decpt is set to 9999.

 mode:
  0 ==> shortest string that yields d when read in
   and rounded to nearest.
  1 ==> like 0, but with Steele & White stopping rule;
   e.g. with IEEE P754 arithmetic , mode 0 gives
   1e23 whereas mode 1 gives 9.999999999999999e22.
  2 ==> max(1,ndigits) significant digits.  This gives a
   return value similar to that of ecvt, except
   that trailing zeros are suppressed.
  3 ==> through ndigits past the decimal point.  This
   gives a return value similar to that from fcvt,
   except that trailing zeros are suppressed, and
   ndigits can be negative.
  4,5 ==> similar to 2 and 3, respectively, but (in
   round-nearest mode) with the tests of mode 0 to
   possibly return a shorter string that rounds to d.
   With IEEE arithmetic and compilation with
   -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same
   as modes 2 and 3 when FLT_ROUNDS != 1.
  6-9 ==> Debugging modes similar to mode - 4:  don't try
   fast floating-point estimate (if applicable).

  Values of mode other than 0-9 are treated as mode 0.

  Sufficient space is allocated to the return value
  to hold the suppressed trailing zeros.
 */

 int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1,
  j, j1, k, k0, k_check, leftright, m2, m5, s2, s5,
  spec_case, try_quick;
 Long L;
#ifndef Sudden_Underflow
 int denorm;
 ULong x;
#endif
 Bigint *b, *b1, *delta, *mlo, *mhi, *S;
 double d2, ds, eps;
 char *s, *s0;
#ifdef Honor_FLT_ROUNDS
 int rounding;
#endif
#ifdef SET_INEXACT
 int inexact, oldinexact;
#endif

#ifndef MULTIPLE_THREADS
 if (dtoa_result) {
  freedtoa(dtoa_result);
  dtoa_result = 0;
  }
#endif

 if (word0(d) & Sign_bit) {
  /* set sign for everything, including 0's and NaNs */
  *sign = 1;
  word0(d) &= ~Sign_bit; /* clear sign bit */
  }
 else
  *sign = 0;

=============================================

Now in a parallel window find the start of the dtoa method in
dtoa.java (line 422)

--------------------------------------------------------------------
 static int
 JS_dtoa(double d, int mode, boolean biasUp, int ndigits,
     boolean[] sign, StringBuffer buf)
 {
     /*  Arguments ndigits, decpt, sign are similar to those
         of ecvt and fcvt; trailing zeros are suppressed from
         the returned string.  If not null, *rve is set to point
         to the end of the return value.  If d is +-Infinity or NaN,
         then *decpt is set to 9999.

         mode:
         0 ==> shortest string that yields d when read in
         and rounded to nearest.
         1 ==> like 0, but with Steele & White stopping rule;
         e.g. with IEEE P754 arithmetic , mode 0 gives
         1e23 whereas mode 1 gives 9.999999999999999e22.
         2 ==> max(1,ndigits) significant digits.  This gives a
         return value similar to that of ecvt, except
         that trailing zeros are suppressed.
         3 ==> through ndigits past the decimal point.  This
         gives a return value similar to that from fcvt,
         except that trailing zeros are suppressed, and
         ndigits can be negative.
         4-9 should give the same return values as 2-3, i.e.,
         4 <= mode <= 9 ==> same return as mode
         2 + (mode & 1).  These modes are mainly for
         debugging; often they run slower but sometimes
         faster than modes 2-3.
         4,5,8,9 ==> left-to-right digit generation.
         6-9 ==> don't try fast floating-point estimate
         (if applicable).

         Values of mode other than 0-9 are treated as mode 0.

         Sufficient space is allocated to the return value
         to hold the suppressed trailing zeros.
     */

     int b2, b5, i, ieps, ilim, ilim0, ilim1,
         j, j1, k, k0, m2, m5, s2, s5;
  char dig;
     long L;
     long x;
     BigInteger b, b1, delta, mlo, mhi, S;
  int[] be = new int[1];
  int[] bbits = new int[1];
     double d2, ds, eps;
  boolean spec_case, denorm, k_check, try_quick, leftright;

     if ((word0(d) & Sign_bit) != 0) {
         /* set sign for everything, including 0's and NaNs */
         sign[0] = true;
         // word0(d) &= ~Sign_bit;  /* clear sign bit */
   d = setWord0(d, word0(d) & ~Sign_bit);
     }
     else
         sign[0] = false;

--------------------------------------------------------------------

Oh look, the same comments, the same variables names, the same
logic just modified to compile for Java yes?



Reply via email to