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

Side by Side Diff: vm/bigint_operations.h

Issue 9835074: Fix for issue 2233 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 9 months 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 | vm/bigint_operations.cc » ('j') | vm/bigint_operations.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 Google Inc. All Rights Reserved. 1 // Copyright 2012 Google Inc. All Rights Reserved.
2 2
3 #ifndef VM_BIGINT_OPERATIONS_H_ 3 #ifndef VM_BIGINT_OPERATIONS_H_
4 #define VM_BIGINT_OPERATIONS_H_ 4 #define VM_BIGINT_OPERATIONS_H_
5 5
6 #include "platform/utils.h" 6 #include "platform/utils.h"
7 7
8 #include "vm/object.h" 8 #include "vm/object.h"
9 9
10 namespace dart { 10 namespace dart {
11 11
12 class BigintOperations : public AllStatic { 12 class BigintOperations : public AllStatic {
13 public: 13 public:
14 static RawBigint* NewFromSmi(const Smi& smi, Heap::Space space = Heap::kNew); 14 static RawBigint* NewFromSmi(const Smi& smi, Heap::Space space = Heap::kNew);
15 static RawBigint* NewFromInt64(int64_t value, Heap::Space space = Heap::kNew); 15 static RawBigint* NewFromInt64(int64_t value, Heap::Space space = Heap::kNew);
16 static RawBigint* NewFromUint64(uint64_t value, 16 static RawBigint* NewFromUint64(uint64_t value,
17 Heap::Space space = Heap::kNew); 17 Heap::Space space = Heap::kNew);
18 // The given string must be a valid integer representation. It may be 18 // The given string must be a valid integer representation. It may be
19 // prefixed by a minus and/or "0x". 19 // prefixed by a minus and/or "0x".
20 // Returns Bigint::null() if the string cannot be parsed. 20 // Returns Bigint::null() if the string cannot be parsed.
21 static RawBigint* NewFromCString(const char* str, 21 static RawBigint* NewFromCString(const char* str,
22 Heap::Space space = Heap::kNew); 22 Heap::Space space = Heap::kNew);
23 static RawBigint* NewFromDouble(double d, Heap::Space space = Heap::kNew); 23 static RawBigint* NewFromDouble(double d, Heap::Space space = Heap::kNew);
24 24
25 // The given string must be a nul-terminated string of hex-digits. It must 25 // Compute length of bigint instance created for the specified hex string.
cshapiro 2012/03/24 01:48:07 What is the unit for this length?
siva 2012/03/24 02:25:03 Changed comment. On 2012/03/24 01:48:07, cshapiro
26 // only contain hex-digits. No sign or leading "0x" is allowed. 26 // The specified hex string must be a null-terminated string of hex-digits.
27 static RawBigint* FromHexCString(const char* str, 27 // It must only contain hex-digits. Leading "0x" is not allowed.
28 static intptr_t ComputeLength(const char* hex_string);
29
30 // Create a bigint instance from the specified hex string. The given string
31 // must be a null-terminated string of hex-digits. It must only contain
32 // hex-digits. Leading "0x" is not allowed.
33 static RawBigint* FromHexCString(const char* hex_string,
28 Heap::Space space = Heap::kNew); 34 Heap::Space space = Heap::kNew);
29 35
30 // The given string must be a nul-terminated string of decimal digits. It 36 // Helper method to initialize a bigint instance object with the bigint value
37 // in the specified string. The given string must be a null-terminated string
38 // of hex-digits. It must only contain hex-digits, leading "0x" is not
39 // allowed.
40 static void FromHexCString(const char* hex_string, const Bigint& value);
41
42 // The given string must be a null-terminated string of decimal digits. It
cshapiro 2012/03/24 01:48:07 just an fyi, nul (one 'l') is the name of the asci
siva 2012/03/24 02:25:03 Reverted to nul-terminated. On 2012/03/24 01:48:0
31 // must only contain decimal digits (0-9). No sign is allowed. Leading 43 // must only contain decimal digits (0-9). No sign is allowed. Leading
32 // zeroes are ignored. 44 // zeroes are ignored.
33 static RawBigint* FromDecimalCString(const char* str, 45 static RawBigint* FromDecimalCString(const char* str,
34 Heap::Space space = Heap::kNew); 46 Heap::Space space = Heap::kNew);
35 47
36 // Converts the bigint to a HEX string. The returned string is prepended by 48 // Converts the bigint to a HEX string. The returned string is prepended by
37 // a "0x" (after the optional minus-sign). 49 // a "0x" (after the optional minus-sign).
38 static const char* ToHexCString(intptr_t length, 50 static const char* ToHexCString(intptr_t length,
39 bool is_negative, 51 bool is_negative,
40 void* data, 52 void* data,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 100
89 private: 101 private:
90 typedef Bigint::Chunk Chunk; 102 typedef Bigint::Chunk Chunk;
91 typedef Bigint::DoubleChunk DoubleChunk; 103 typedef Bigint::DoubleChunk DoubleChunk;
92 104
93 static const int kDigitBitSize = 28; 105 static const int kDigitBitSize = 28;
94 static const Chunk kDigitMask = (static_cast<Chunk>(1) << kDigitBitSize) - 1; 106 static const Chunk kDigitMask = (static_cast<Chunk>(1) << kDigitBitSize) - 1;
95 static const Chunk kDigitMaxValue = kDigitMask; 107 static const Chunk kDigitMaxValue = kDigitMask;
96 static const int kChunkSize = sizeof(Chunk); 108 static const int kChunkSize = sizeof(Chunk);
97 static const int kChunkBitSize = kChunkSize * kBitsPerByte; 109 static const int kChunkBitSize = kChunkSize * kBitsPerByte;
110 static const int kHexCharsPerDigit = kDigitBitSize / 4;
98 111
99 static RawBigint* Zero() { return Bigint::Allocate(0); } 112 static RawBigint* Zero() { return Bigint::Allocate(0); }
100 static RawBigint* One() { 113 static RawBigint* One() {
101 Bigint& result = Bigint::Handle(Bigint::Allocate(1)); 114 Bigint& result = Bigint::Handle(Bigint::Allocate(1));
102 result.SetChunkAt(0, 1); 115 result.SetChunkAt(0, 1);
103 return result.raw(); 116 return result.raw();
104 } 117 }
105 static RawBigint* MinusOne() { 118 static RawBigint* MinusOne() {
106 Bigint& result = Bigint::Handle(One()); 119 Bigint& result = Bigint::Handle(One());
107 result.ToggleSign(); 120 result.ToggleSign();
(...skipping 23 matching lines...) Expand all
131 static RawBigint* Copy(const Bigint& bigint); 144 static RawBigint* Copy(const Bigint& bigint);
132 145
133 static int CountBits(Chunk digit); 146 static int CountBits(Chunk digit);
134 147
135 DISALLOW_IMPLICIT_CONSTRUCTORS(BigintOperations); 148 DISALLOW_IMPLICIT_CONSTRUCTORS(BigintOperations);
136 }; 149 };
137 150
138 } // namespace dart 151 } // namespace dart
139 152
140 #endif // VM_BIGINT_OPERATIONS_H_ 153 #endif // VM_BIGINT_OPERATIONS_H_
OLDNEW
« no previous file with comments | « no previous file | vm/bigint_operations.cc » ('j') | vm/bigint_operations.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698