| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_BIGINT_OPERATIONS_H_ | 5 #ifndef VM_BIGINT_OPERATIONS_H_ |
| 6 #define VM_BIGINT_OPERATIONS_H_ | 6 #define VM_BIGINT_OPERATIONS_H_ |
| 7 | 7 |
| 8 #include "vm/heap.h" | 8 #include "vm/heap.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/token.h" | 10 #include "vm/token.h" |
| 11 | 11 |
| 12 // This should be folded into OpenSSL | 12 // This should be folded into OpenSSL |
| 13 #undef BN_abs_is_word | 13 #undef BN_abs_is_word |
| 14 #define BN_abs_is_word(a, w) (((a)->top == 1) \ | 14 #define BN_abs_is_word(a, w) (((a)->top == 1) \ |
| 15 && ((a)->d[0] == static_cast<BN_ULONG>(w))) | 15 && ((a)->d[0] == static_cast<BN_ULONG>(w))) |
| 16 | 16 |
| 17 namespace dart { | 17 namespace dart { |
| 18 | 18 |
| 19 class BigintOperations : public AllStatic { | 19 class BigintOperations : public AllStatic { |
| 20 public: | 20 public: |
| 21 static RawBigint* NewFromSmi(const Smi& smi, Heap::Space space = Heap::kNew); | 21 static RawBigint* NewFromSmi(const Smi& smi, Heap::Space space = Heap::kNew); |
| 22 static RawBigint* NewFromInt64(int64_t value, Heap::Space space = Heap::kNew); | 22 static RawBigint* NewFromInt64(int64_t value, Heap::Space space = Heap::kNew); |
| 23 static RawBigint* NewFromUInt64(uint64_t value, | 23 static RawBigint* NewFromUint64(uint64_t value, |
| 24 Heap::Space space = Heap::kNew); | 24 Heap::Space space = Heap::kNew); |
| 25 // The given string must be a valid integer representation. It may be | 25 // The given string must be a valid integer representation. It may be |
| 26 // prefixed by a minus and/or "0x". | 26 // prefixed by a minus and/or "0x". |
| 27 // Returns Bigint::null() if the string cannot be parsed. | 27 // Returns Bigint::null() if the string cannot be parsed. |
| 28 static RawBigint* NewFromCString(const char* str, | 28 static RawBigint* NewFromCString(const char* str, |
| 29 Heap::Space space = Heap::kNew); | 29 Heap::Space space = Heap::kNew); |
| 30 static RawBigint* NewFromDouble(double d, Heap::Space space = Heap::kNew); | 30 static RawBigint* NewFromDouble(double d, Heap::Space space = Heap::kNew); |
| 31 | 31 |
| 32 // The given string must be a nul-terminated string of hex-digits. It must | 32 // The given string must be a nul-terminated string of hex-digits. It must |
| 33 // only contain hex-digits. No sign or leading "0x" is allowed. | 33 // only contain hex-digits. No sign or leading "0x" is allowed. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 uword (*allocator)(intptr_t size)); | 50 uword (*allocator)(intptr_t size)); |
| 51 static const char* ToDecCString(const Bigint& bigint, | 51 static const char* ToDecCString(const Bigint& bigint, |
| 52 uword (*allocator)(intptr_t size)); | 52 uword (*allocator)(intptr_t size)); |
| 53 | 53 |
| 54 static bool FitsIntoSmi(const Bigint& bigint); | 54 static bool FitsIntoSmi(const Bigint& bigint); |
| 55 static RawSmi* ToSmi(const Bigint& bigint); | 55 static RawSmi* ToSmi(const Bigint& bigint); |
| 56 | 56 |
| 57 static bool FitsIntoInt64(const Bigint& bigint); | 57 static bool FitsIntoInt64(const Bigint& bigint); |
| 58 static int64_t ToInt64(const Bigint& bigint); | 58 static int64_t ToInt64(const Bigint& bigint); |
| 59 | 59 |
| 60 static bool FitsIntoUInt64(const Bigint& bigint); | 60 static bool FitsIntoUint64(const Bigint& bigint); |
| 61 static uint64_t ToUInt64(const Bigint& bigint); | 61 static uint64_t ToUint64(const Bigint& bigint); |
| 62 static uint64_t AbsToUInt64(const Bigint& bigint); | 62 static uint64_t AbsToUint64(const Bigint& bigint); |
| 63 | 63 |
| 64 static RawDouble* ToDouble(const Bigint& bigint); | 64 static RawDouble* ToDouble(const Bigint& bigint); |
| 65 | 65 |
| 66 static RawBigint* Add(const Bigint& a, const Bigint& b); | 66 static RawBigint* Add(const Bigint& a, const Bigint& b); |
| 67 static RawBigint* Subtract(const Bigint& a, const Bigint& b); | 67 static RawBigint* Subtract(const Bigint& a, const Bigint& b); |
| 68 static RawBigint* Multiply(const Bigint& a, const Bigint& b); | 68 static RawBigint* Multiply(const Bigint& a, const Bigint& b); |
| 69 // TODO(floitsch): what to do for divisions by zero. | 69 // TODO(floitsch): what to do for divisions by zero. |
| 70 static RawBigint* Divide(const Bigint& a, const Bigint& b); | 70 static RawBigint* Divide(const Bigint& a, const Bigint& b); |
| 71 static RawBigint* Modulo(const Bigint& a, const Bigint& b); | 71 static RawBigint* Modulo(const Bigint& a, const Bigint& b); |
| 72 static RawBigint* Remainder(const Bigint& a, const Bigint& b); | 72 static RawBigint* Remainder(const Bigint& a, const Bigint& b); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 97 static RawSmi* BitOpWithSmi(Token::Kind kind, | 97 static RawSmi* BitOpWithSmi(Token::Kind kind, |
| 98 const Bigint& bigint, | 98 const Bigint& bigint, |
| 99 const Smi& smi); | 99 const Smi& smi); |
| 100 | 100 |
| 101 DISALLOW_IMPLICIT_CONSTRUCTORS(BigintOperations); | 101 DISALLOW_IMPLICIT_CONSTRUCTORS(BigintOperations); |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 } // namespace dart | 104 } // namespace dart |
| 105 | 105 |
| 106 #endif // VM_BIGINT_OPERATIONS_H_ | 106 #endif // VM_BIGINT_OPERATIONS_H_ |
| OLD | NEW |