Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/double.h

Issue 4681001: Fix Double.NextDouble function. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/cctest/test-double.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 e -= DiyFp::kSignificandSize - kSignificandSize; 76 e -= DiyFp::kSignificandSize - kSignificandSize;
77 return DiyFp(f, e); 77 return DiyFp(f, e);
78 } 78 }
79 79
80 // Returns the double's bit as uint64. 80 // Returns the double's bit as uint64.
81 uint64_t AsUint64() const { 81 uint64_t AsUint64() const {
82 return d64_; 82 return d64_;
83 } 83 }
84 84
85 double NextDouble() const { 85 double NextDouble() const {
86 if (d64_ == kInfinity) return kInfinity; 86 if (d64_ == kInfinity) return Double(kInfinity).value();
87 return Double(d64_ + 1).value(); 87 if (Sign() < 0 && Significand() == 0) {
88 // -0.0
89 return 0.0;
90 }
91 if (Sign() < 0) {
92 return Double(d64_ - 1).value();
93 } else {
94 return Double(d64_ + 1).value();
95 }
88 } 96 }
89 97
90 int Exponent() const { 98 int Exponent() const {
91 if (IsDenormal()) return kDenormalExponent; 99 if (IsDenormal()) return kDenormalExponent;
92 100
93 uint64_t d64 = AsUint64(); 101 uint64_t d64 = AsUint64();
94 int biased_e = 102 int biased_e =
95 static_cast<int>((d64 & kExponentMask) >> kPhysicalSignificandSize); 103 static_cast<int>((d64 & kExponentMask) >> kPhysicalSignificandSize);
96 return biased_e - kExponentBias; 104 return biased_e - kExponentBias;
97 } 105 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 biased_exponent = static_cast<uint64_t>(exponent + kExponentBias); 221 biased_exponent = static_cast<uint64_t>(exponent + kExponentBias);
214 } 222 }
215 return (significand & kSignificandMask) | 223 return (significand & kSignificandMask) |
216 (biased_exponent << kPhysicalSignificandSize); 224 (biased_exponent << kPhysicalSignificandSize);
217 } 225 }
218 }; 226 };
219 227
220 } } // namespace v8::internal 228 } } // namespace v8::internal
221 229
222 #endif // V8_DOUBLE_H_ 230 #endif // V8_DOUBLE_H_
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-double.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698