1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "big_integer.h" 17 18 namespace OHOS::NativeRdb { BigInteger(int64_t value)19BigInteger::BigInteger(int64_t value) 20 { 21 if (value < 0) { 22 sign_ = 1; 23 value *= -1; 24 } 25 value_.push_back(value); 26 } 27 BigInteger(int32_t sign,std::vector<uint64_t> && trueForm)28BigInteger::BigInteger(int32_t sign, std::vector<uint64_t>&& trueForm) 29 : sign_(sign), value_(std::move(trueForm)) 30 { 31 } 32 BigInteger(const BigInteger & other)33BigInteger::BigInteger(const BigInteger& other) 34 { 35 operator=(other); 36 } 37 BigInteger(BigInteger && other)38BigInteger::BigInteger(BigInteger&& other) 39 { 40 operator=(std::move(other)); 41 } 42 operator =(const BigInteger & other)43BigInteger& BigInteger::operator=(const BigInteger& other) 44 { 45 if (this == &other) { 46 return *this; 47 } 48 sign_ = other.sign_; 49 value_ = other.value_; 50 return *this; 51 } 52 operator =(BigInteger && other)53BigInteger& BigInteger::operator=(BigInteger&& other) 54 { 55 if (this == &other) { 56 return *this; 57 } 58 sign_ = other.sign_; 59 value_ = std::move(other.value_); 60 other.sign_ = 0; 61 return *this; 62 } 63 operator ==(const BigInteger & other)64bool BigInteger::operator==(const BigInteger& other) 65 { 66 if (sign_ != other.sign_) { 67 return false; 68 } 69 return value_ == other.value_; 70 } 71 operator <(const BigInteger & rhs)72bool BigInteger::operator<(const BigInteger &rhs) 73 { 74 return sign_ != rhs.sign_ ? (sign_ > rhs.sign_) : (sign_ == 0 ? (value_ < rhs.value_) : (rhs.value_ < value_)); 75 } 76 Sign() const77int32_t BigInteger::Sign() const 78 { 79 return sign_; 80 } 81 Size() const82size_t BigInteger::Size() const 83 { 84 return value_.size(); 85 } 86 TrueForm() const87const uint64_t* BigInteger::TrueForm() const 88 { 89 return value_.data(); 90 } 91 Value() const92std::vector<uint64_t> BigInteger::Value() const 93 { 94 return value_; 95 } 96 } 97