OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 // If the guess doesn't lie near a single-precision boundary we can simply | 521 // If the guess doesn't lie near a single-precision boundary we can simply |
522 // return its float-value. | 522 // return its float-value. |
523 if (f1 == f4) { | 523 if (f1 == f4) { |
524 return float_guess; | 524 return float_guess; |
525 } | 525 } |
526 | 526 |
527 ASSERT((f1 != f2 && f2 == f3 && f3 == f4) || | 527 ASSERT((f1 != f2 && f2 == f3 && f3 == f4) || |
528 (f1 == f2 && f2 != f3 && f3 == f4) || | 528 (f1 == f2 && f2 != f3 && f3 == f4) || |
529 (f1 == f2 && f2 == f3 && f3 != f4)); | 529 (f1 == f2 && f2 == f3 && f3 != f4)); |
530 | 530 |
531 // guess and next are the two possible canditates (in the same way that | 531 // guess and next are the two possible candidates (in the same way that |
532 // double_guess was the lower candidate for a double-precision guess). | 532 // double_guess was the lower candidate for a double-precision guess). |
533 float guess = f1; | 533 float guess = f1; |
534 float next = f4; | 534 float next = f4; |
535 DiyFp upper_boundary; | 535 DiyFp upper_boundary; |
536 if (guess == 0.0f) { | 536 if (guess == 0.0f) { |
537 float min_float = 1e-45f; | 537 float min_float = 1e-45f; |
538 upper_boundary = Double(static_cast<double>(min_float) / 2).AsDiyFp(); | 538 upper_boundary = Double(static_cast<double>(min_float) / 2).AsDiyFp(); |
539 } else { | 539 } else { |
540 upper_boundary = Single(guess).UpperBoundary(); | 540 upper_boundary = Single(guess).UpperBoundary(); |
541 } | 541 } |
542 int comparison = CompareBufferWithDiyFp(trimmed, exponent, upper_boundary); | 542 int comparison = CompareBufferWithDiyFp(trimmed, exponent, upper_boundary); |
543 if (comparison < 0) { | 543 if (comparison < 0) { |
544 return guess; | 544 return guess; |
545 } else if (comparison > 0) { | 545 } else if (comparison > 0) { |
546 return next; | 546 return next; |
547 } else if ((Single(guess).Significand() & 1) == 0) { | 547 } else if ((Single(guess).Significand() & 1) == 0) { |
548 // Round towards even. | 548 // Round towards even. |
549 return guess; | 549 return guess; |
550 } else { | 550 } else { |
551 return next; | 551 return next; |
552 } | 552 } |
553 } | 553 } |
554 | 554 |
555 } // namespace double_conversion | 555 } // namespace double_conversion |
OLD | NEW |