yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
BigIntegerUtils.hh File Reference
#include "BigInteger.hh"
#include <string>
#include <iostream>
+ Include dependency graph for BigIntegerUtils.hh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::string bigUnsignedToString (const BigUnsigned &x)
 
std::string bigIntegerToString (const BigInteger &x)
 
BigUnsigned stringToBigUnsigned (const std::string &s)
 
BigInteger stringToBigInteger (const std::string &s)
 
template<class T >
BigInteger dataToBigInteger (const T *data, BigInteger::Index length, BigInteger::Sign sign)
 
std::ostream & operator<< (std::ostream &os, const BigUnsigned &x)
 
std::ostream & operator<< (std::ostream &os, const BigInteger &x)
 

Function Documentation

std::string bigIntegerToString ( const BigInteger x)

Definition at line 8 of file BigIntegerUtils.cc.

8  {
9  return (x.getSign() == BigInteger::negative)
10  ? (std::string("-") + bigUnsignedToString(x.getMagnitude()))
12 }
std::string bigUnsignedToString(const BigUnsigned &x)
const BigUnsigned & getMagnitude() const
Definition: BigInteger.hh:83
Sign getSign() const
Definition: BigInteger.hh:80

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string bigUnsignedToString ( const BigUnsigned x)

Definition at line 4 of file BigIntegerUtils.cc.

4  {
5  return std::string(BigUnsignedInABase(x, 10));
6 }

+ Here is the caller graph for this function:

template<class T >
BigInteger dataToBigInteger ( const T *  data,
BigInteger::Index  length,
BigInteger::Sign  sign 
)

Definition at line 45 of file BigIntegerUtils.hh.

45  {
46  // really ceiling(numBytes / sizeof(BigInteger::Blk))
47  unsigned int pieceSizeInBits = 8 * sizeof(T);
48  unsigned int piecesPerBlock = sizeof(BigInteger::Blk) / sizeof(T);
49  unsigned int numBlocks = (length + piecesPerBlock - 1) / piecesPerBlock;
50 
51  // Allocate our block array
52  BigInteger::Blk *blocks = new BigInteger::Blk[numBlocks];
53 
54  BigInteger::Index blockNum, pieceNum, pieceNumHere;
55 
56  // Convert
57  for (blockNum = 0, pieceNum = 0; blockNum < numBlocks; blockNum++) {
58  BigInteger::Blk curBlock = 0;
59  for (pieceNumHere = 0; pieceNumHere < piecesPerBlock && pieceNum < length;
60  pieceNumHere++, pieceNum++)
61  curBlock |= (BigInteger::Blk(data[pieceNum]) << (pieceSizeInBits * pieceNumHere));
62  blocks[blockNum] = curBlock;
63  }
64 
65  // Create the BigInteger.
66  BigInteger x(blocks, numBlocks, sign);
67 
68  delete [] blocks;
69  return x;
70 }
bool sign(Lit p)
Definition: SolverTypes.h:66
BigUnsigned::Index Index
Definition: BigInteger.hh:17
BigUnsigned::Blk Blk
Definition: BigInteger.hh:16
std::ostream& operator<< ( std::ostream &  os,
const BigUnsigned x 
)

Definition at line 25 of file BigIntegerUtils.cc.

25  {
27  long osFlags = os.flags();
28  if (osFlags & os.dec)
29  base = 10;
30  else if (osFlags & os.hex) {
31  base = 16;
32  if (osFlags & os.showbase)
33  os << "0x";
34  } else if (osFlags & os.oct) {
35  base = 8;
36  if (osFlags & os.showbase)
37  os << '0';
38  } else
39  throw "std::ostream << BigUnsigned: Could not determine the desired base from output-stream flags";
40  std::string s = std::string(BigUnsignedInABase(x, base));
41  os << s;
42  return os;
43 }
std::ostream& operator<< ( std::ostream &  os,
const BigInteger x 
)

Definition at line 45 of file BigIntegerUtils.cc.

45  {
46  if (x.getSign() == BigInteger::negative)
47  os << '-';
48  os << x.getMagnitude();
49  return os;
50 }
const BigUnsigned & getMagnitude() const
Definition: BigInteger.hh:83
Sign getSign() const
Definition: BigInteger.hh:80

+ Here is the call graph for this function:

BigInteger stringToBigInteger ( const std::string &  s)

Definition at line 18 of file BigIntegerUtils.cc.

18  {
19  // Recognize a sign followed by a BigUnsigned.
20  return (s[0] == '-') ? BigInteger(stringToBigUnsigned(s.substr(1, s.length() - 1)), BigInteger::negative)
21  : (s[0] == '+') ? BigInteger(stringToBigUnsigned(s.substr(1, s.length() - 1)))
23 }
BigUnsigned stringToBigUnsigned(const std::string &s)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

BigUnsigned stringToBigUnsigned ( const std::string &  s)

Definition at line 14 of file BigIntegerUtils.cc.

+ Here is the caller graph for this function: