< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/doubleconv/BignumDtoa.java

Print this page




 263                 return;
 264             } else if (in_delta_room_minus) {
 265                 // Round down (== do nothing).
 266                 return;
 267             } else {  // in_delta_room_plus
 268                 // Round up.
 269                 // Note again that the last digit could not be '9' since this would have
 270                 // stopped the loop earlier.
 271                 // We still have an ASSERT here, in case the preconditions were not
 272                 // satisfied.
 273                 assert (buffer.chars[buffer.length -1] != '9');
 274                 buffer.chars[buffer.length - 1]++;
 275                 return;
 276             }
 277         }
 278     }
 279 
 280 
 281     // Let v = numerator / denominator < 10.
 282     // Then we generate 'count' digits of d = x.xxxxx... (without the decimal point)
 283     // from left to right. Once 'count' digits have been produced we decide wether
 284     // to round up or down. Remainders of exactly .5 round upwards. Numbers such
 285     // as 9.999999 propagate a carry all the way, and change the
 286     // exponent (decimal_point), when rounding upwards.
 287     static void generateCountedDigits(final int count,
 288                                       final Bignum numerator, final Bignum denominator,
 289                                       final DtoaBuffer buffer) {
 290         assert (count >= 0);
 291         for (int i = 0; i < count - 1; ++i) {
 292             final char digit;
 293             digit = numerator.divideModuloIntBignum(denominator);
 294             assert (digit <= 9);  // digit is a uint16_t and therefore always positive.
 295             // digit = numerator / denominator (integer division).
 296             // numerator = numerator % denominator.
 297             buffer.chars[i] = (char)(digit + '0');
 298             // Prepare for next iteration.
 299             numerator.times10();
 300         }
 301         // Generate the last digit.
 302         char digit;
 303         digit = numerator.divideModuloIntBignum(denominator);




 263                 return;
 264             } else if (in_delta_room_minus) {
 265                 // Round down (== do nothing).
 266                 return;
 267             } else {  // in_delta_room_plus
 268                 // Round up.
 269                 // Note again that the last digit could not be '9' since this would have
 270                 // stopped the loop earlier.
 271                 // We still have an ASSERT here, in case the preconditions were not
 272                 // satisfied.
 273                 assert (buffer.chars[buffer.length -1] != '9');
 274                 buffer.chars[buffer.length - 1]++;
 275                 return;
 276             }
 277         }
 278     }
 279 
 280 
 281     // Let v = numerator / denominator < 10.
 282     // Then we generate 'count' digits of d = x.xxxxx... (without the decimal point)
 283     // from left to right. Once 'count' digits have been produced we decide whether
 284     // to round up or down. Remainders of exactly .5 round upwards. Numbers such
 285     // as 9.999999 propagate a carry all the way, and change the
 286     // exponent (decimal_point), when rounding upwards.
 287     static void generateCountedDigits(final int count,
 288                                       final Bignum numerator, final Bignum denominator,
 289                                       final DtoaBuffer buffer) {
 290         assert (count >= 0);
 291         for (int i = 0; i < count - 1; ++i) {
 292             final char digit;
 293             digit = numerator.divideModuloIntBignum(denominator);
 294             assert (digit <= 9);  // digit is a uint16_t and therefore always positive.
 295             // digit = numerator / denominator (integer division).
 296             // numerator = numerator % denominator.
 297             buffer.chars[i] = (char)(digit + '0');
 298             // Prepare for next iteration.
 299             numerator.times10();
 300         }
 301         // Generate the last digit.
 302         char digit;
 303         digit = numerator.divideModuloIntBignum(denominator);


< prev index next >