-
Notifications
You must be signed in to change notification settings - Fork 59
BInt
BInt is an arbitrary precision integer value type. It stores a number in base 2^64 notation as an array. Each element of the array is called a limb, which is of type UInt64, the whole array is called limbs and has the type [UInt64]. A boolean sign variable determines if the number is positive or negative. If sign == true, then the number is smaller than 0, otherwise it is greater or equal to 0. It stores the 64 bit digits in little endian, that is, the least significant digit is stored in the array index 0:
public struct BInt:
SignedNumeric, // Implies Numeric, Equatable, ExpressibleByIntegerLiteral
BinaryInteger, // Implies Hashable, CustomStringConvertible, Strideable, Comparable
ExpressibleByFloatLiteral
limbs == [] := undefined, should throw an error
limbs == [0], sign == false := 0, defined as positive
limbs == [0], sign == true := undefined, should throw an error
limbs == [n] := n if sign == false, otherwise -n, given 0 <= n < 2^64
limbs == [l0, l1, l2, ..., ln] :=
(l0 * 2^(0*64)) +
(11 * 2^(1*64)) +
(12 * 2^(2*64)) +
... +
(ln * 2^(n*64))
// Implies Hashable, CustomStringConvertible, Strideable, Comparable ExpressibleByFloatLiteral
, // Implies Numeric, Equatable, ExpressibleByIntegerLiteral BinaryInteger
, SignedNumeric
public typealias Magnitude = UInt64
public typealias Words = [UInt]
Initialise a BInt from a hexadecimal string
public init(hex: String)
- hex: the hexadecimal string to convert to a big integer
Initialise from an unsigned, 64 bit integer
public init(_ n: UInt64)
- n: the 64 bit unsigned integer to convert to a BInt
Initialise from big-endian data
public init(data: Data)
- data: the data to convert to a Bignum
Create an instance initialized to a string value.
public init(_ str: String)
public init(floatLiteral value: Double)
public init(integerLiteral value: Int)
public init?<T>(exactly source: T) where T : BinaryInteger
Creates an integer from the given floating-point value, rounding toward zero.
public init<T>(_ source: T) where T : BinaryFloatingPoint
Creates a new instance from the given integer.
public init<T>(_ source: T) where T : BinaryInteger
Creates a new instance with the representable value that’s closest to the given integer.
public init<T>(clamping source: T) where T : BinaryInteger
Creates an integer from the given floating-point value, if it can be represented exactly.
public init?<T>(exactly source: T) where T : BinaryFloatingPoint
Creates a new instance from the bit pattern of the given instance by sign-extending or truncating to fit this type.
public init<T>(truncatingIfNeeded source: T) where T : BinaryInteger
public init(number: String, withBase base: Int)
Decimal string representation
public var dec: String
Hexadecimal string representation
public var hex: String
public var magnitude: UInt64
A collection containing the words of this value’s binary representation, in order from the least significant to most significant.
public var words: BInt.Words
public var description: String
A Boolean value indicating whether this type is a signed integer type.
public static var isSigned: Bool
The number of bits in the current binary representation of this value.
public var bitWidth: Int
The number of trailing zeros in this value’s binary representation.
public var trailingZeroBitCount: Int
public func asString(withBase base: Int) -> String
public func hash(into hasher: inout Hasher)
Returns -1 if this value is negative and 1 if it’s positive; otherwise, 0.
public func signum() -> BInt
public mutating func negate()
Returns the quotient and remainder of this value divided by the given value.
public func quotientAndRemainder(dividingBy rhs: BInt) -> (quotient: BInt, remainder: BInt)
public static func <<<T: BinaryInteger>(lhs: BInt, rhs: T) -> BInt
public static func <<=<T: BinaryInteger>(lhs: inout BInt, rhs: T)
public static func >><T: BinaryInteger>(lhs: BInt, rhs: T) -> BInt
public static func >>=<T: BinaryInteger>(lhs: inout BInt, rhs: T)
Returns the result of performing a bitwise AND operation on the two given values.
public static func &(lhs: BInt, rhs: BInt) -> BInt
Stores the result of performing a bitwise AND operation on the two given values in the left-hand-side variable.
public static func &=(lhs: inout BInt, rhs: BInt)
public static func |(lhs: BInt, rhs: BInt) -> BInt
public static func |=(lhs: inout BInt, rhs: BInt)
public static func ^(lhs: BInt, rhs: BInt) -> BInt
public static func ^=(lhs: inout BInt, rhs: BInt)
public prefix static func ~(x: BInt) -> BInt
public static func +=(lhs: inout BInt, rhs: BInt)
public static func +(lhs: BInt, rhs: BInt) -> BInt
public static prefix func -(n: BInt) -> BInt
public static func -(lhs: BInt, rhs: BInt) -> BInt
public static func -=(lhs: inout BInt, rhs: BInt)
public static func *(lhs: BInt, rhs: BInt) -> BInt
public static func *=(lhs: inout BInt, rhs: BInt)
public static func **(lhs: BInt, rhs: Int) -> BInt
public static func /(lhs: BInt, rhs:BInt) -> BInt
public static func /=(lhs: inout BInt, rhs: BInt)
public static func %(lhs: BInt, rhs: BInt) -> BInt
public static func %=(lhs: inout BInt, rhs: BInt)
public static func ==(lhs: BInt, rhs: BInt) -> Bool
public static func <(lhs: BInt, rhs: BInt) -> Bool
public static func >(lhs: BInt, rhs: BInt) -> Bool
public static func <=(lhs: BInt, rhs: BInt) -> Bool
public static func >=(lhs: BInt, rhs: BInt) -> Bool
Generated at 2022-05-17T08:44:22+0000 using swift-doc 1.0.0-rc.1.
Types
- APIClientError
- APIEndPoint
- Account.Meta
- Account.Meta.CodingKeys
- AccountInfo
- AccountInstructions
- AnyDecodable
- AnyEncodable
- AnyResponse
- AssociatedTokenProgram
- BDouble
- BInt
- BIntMath
- Base58
- BinaryReader
- BlockCommitment
- BorshDecodingError
- BufferInfo
- BufferInfoParsed
- BufferLayoutError
- ClusterNodes
- ConfirmedBlock
- ConfirmedTransaction
- ConfirmedTransaction.Message
- Context
- DataSlice
- DefaultFeeCalculator
- DerivablePath
- DerivablePath.DerivableType
- Ed25519HDKey
- Ed25519HDKey.Error
- Ed25519HDKey.Keys
- EmptyInfo
- EncodableWrapper
- EpochInfo
- EpochSchedule
- ErrorDetail
- Fee
- FeeAmount
- FeeAmount.OtherFee
- FeeCalculatorResponse
- FeeRateGovernor
- Identity
- InflationGovernor
- InflationRate
- InnerInstruction
- Int2X
- Int2XConfig
- JSONRPCAPIClientRequest
- JSONRPCRequestEncoder
- JSONRPCResponse
- JSONRPCResponseDecoder
- Keychain
- Keychain.KeyDerivationError
- LargestAccount
- Mint
- Mnemonic
- Mnemonic.Error
- Network
- OwnerInfoParams
- OwnerValidationProgram
- ParsedInstruction
- PerformanceSample
- Pool
- PreparedTransaction
- ProgramAccount
- ProgramAccounts
- PublicKey
- RIPEMD
- RIPEMD.Block
- RIPEMD.Block.K
- RIPEMD.Block.r
- RIPEMD.Block.s
- RequestAPI
- RequestConfiguration
- Response
- ResponseError
- ResponseErrorData
- Reward
- Rpc
- SignatureInfo
- SignatureStatus
- SimulationResult
- SocketAction
- SocketEntity
- SocketError
- SocketLogsNotificationData
- SocketMethod
- SocketParams
- SocketSignatureNotificationData
- SocketTokenAccountNotificationData
- SocketTokenAccountNotificationDataInfo
- SocketTokenAccountNotificationDataParsed
- SolanaError
- StakeActivation
- Supply
- SwapResponse
- SystemProgram
- SystemProgram.Index
- Throwable
- Token
- TokenAccount
- TokenAccountBalance
- TokenAmount
- TokenBalance
- TokenExtensions
- TokenProgram
- TokenProgram.Index
- TokenSwapInfo
- TokenSwapProgram
- TokenTag
- TokensListParserError
- Transaction
- Transaction.Message
- Transaction.Message.CompiledInstruction
- Transaction.Message.Header
- Transaction.Signature
- TransactionInfo
- TransactionInstruction
- TransactionMeta
- TransactionStatus
- Transfer
- UInt2X
- Version
- VoteAccount
- VoteAccounts
- Wallet
- Wordlists
- WrappingToken
Protocols
Global Typealiases
- Bignum
- BorshCodable
- Commitment
- Decimals
- Int1024
- Int128
- Int1X
- Int256
- Int512
- Lamports
- RequestEncoder
- ResponseDecoder
- SPLTokenDestinationAddress
- SocketLogsNotification
- SocketNativeAccountNotification
- SocketProgramAccountNotification
- SocketSignatureNotification
- SocketSubscriptionResponse
- SocketTokenAccountNotification
- SocketUnsubscriptionResponse
- TransactionError
- TransactionID
- UInt1024
- UInt128
- UInt1X
- UInt256
- UInt512
Global Functions
- abs(_:)
- checkAccountValidation(account:)
- checkIfAssociatedTokenAccountExists(owner:mint:)
- connect()
- disconnect()
- findSPLTokenDestinationAddress(mintAddress:destinationAddress:)
- getAccountInfo(account:)
- getBalance(account:commitment:)
- getBlockCommitment(block:)
- getBlockHeight()
- getBlockTime(block:)
- getClusterNodes()
- getConfirmedBlock(slot:encoding:)
- getConfirmedBlocksWithLimit(startSlot:limit:)
- getConfirmedSignaturesForAddress(account:startSlot:endSlot:)
- getEpochInfo(commitment:)
- getFees(commitment:)
- getMinimumBalanceForRentExemption(dataLength:commitment:)
- getMinimumBalanceForRentExemption(span:)
- getMultipleAccounts(pubkeys:)
- getMultipleMintDatas(mintAddresses:programId:)
- getRecentBlockhash()
- getRecentBlockhash(commitment:)
- getSignatureStatus(signature:configs:)
- getSignatureStatuses(signatures:configs:)
- getTokenAccountBalance(pubkey:commitment:)
- getTokenAccountsByDelegate(pubkey:mint:programId:configs:)
- getTokenAccountsByOwner(pubkey:params:configs:)
- getTokenLargestAccounts(pubkey:commitment:)
- getTokenSupply(pubkey:commitment:)
- getTokenWallets(account:tokensRepository:)
- getTokensList(useCache:)
- getTransaction(transactionSignature:)
- getVersion()
- getVoteAccounts(commitment:)
- minimumLedgerSlot()
- observeSignatureStatus(signature:)
- observeSignatureStatus(signature:timeout:delay:)
- parse(network:)
- prepareCreatingWSOLAccountAndCloseWhenDone(from:amount:payer:minRentExemption:)
- prepareForCreatingAssociatedTokenAccount(owner:mint:feePayer:closeAfterward:)
- prepareSendingNativeSOL(from:to:amount:feePayer:)
- prepareSendingSPLTokens(account:mintAddress:decimals:from:to:amount:feePayer:transferChecked:lamportsPerSignature:minRentExemption:)
- prepareTransaction(instructions:signers:feePayer:feeCalculator:)
- request(with:)
- requestAirdrop(account:lamports:commitment:)
- requestData(request:)
- sendTransaction(preparedTransaction:)
- sendTransaction(transaction:configs:)
- setLogFilter(filter:)
- sha256(data:)
- simulateTransaction(preparedTransaction:)
- simulateTransaction(transaction:configs:)
- subscribe(type:params:commitment:)
- unsubscribe(type:socketId:)
- validatorExit()
Extensions
- Account
- Array
- Bool
- Data
- Dictionary
- Double
- Error
- FixedWidthInteger
- Float32
- Float64
- Int
- NSRegularExpression
- RawRepresentable
- Set
- Socket
- SocketLogsNotification
- SocketNativeAccountNotification
- SocketProgramAccountNotification
- SocketSignatureNotification
- SocketTokenAccountNotification
- String
- StringProtocol
- UInt32
- UInt64
- UInt8
- URLRequest
- URLSession