#include <string>
#include <sstream>
#include <cmath>
#include <vector>
Include dependency graph for tools.hpp:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Functions | |
| std::string | format (double x, int prec=16) |
| Simple function to format a double with a given precision. Useful if we don't want to mess with, e.g., cout's settings and produce predictable double-output. | |
| void | print_copyright (std::ostream &os) |
| Print copyright notice. | |
| std::string | move_to (int N) |
| Move to position (using ANSI escape seq.). | |
| double | lnfact (int n) |
| Compute ln(n!). | |
| double | fact (int n) |
| Compute n!. | |
| double | lnbinom (int n, int m) |
| Compute log of factorial, ln(n!/m!/(n-m)!). | |
| double | binom (int n, int m) |
| Compute "n ober m" = n!/(m!(n-m)!). | |
| template<typename T> | |
| std::string | yesno (const T &x) |
| Return string "yes" if true, "no" if false. | |
| template<typename T> | |
| int | m1pow (const T &i) |
| Compute pow(-1,i). Used a lot! | |
| template<typename T> | |
| T | sqr (const T &x) |
| Compute square of number; used a lot! | |
| template<class T> | |
| size_t | count_bits (const T &x) |
| Count bits in a word. See http://graphics.stanford.edu/~seander/bithacks.html. | |
| template<typename T> | |
| std::string | to_binary (const T &a, const size_t &n=0) |
| Compute a binary string version of number. | |
| template<class Vector> | |
| bool | general_inc (Vector &alpha, int min, int max, size_t digit=0) |
| Simple recursive function to step through multi-indices. | |
| bool | more_general_inc (std::vector< int > &alpha, const std::vector< int > &min, const std::vector< int > &max, int digit=0) |
| Simple recursive function to step through multi-indices. More general version of general_inc(). Here, the max and min values are different for each index in the multi-index. | |
| double binom | ( | int | n, | |
| int | m | |||
| ) | [inline] |
Compute "n ober m" = n!/(m!(n-m)!).
| n | a number | |
| m | a number |
Here is the call graph for this function:
| double fact | ( | int | n | ) | [inline] |
Compute n!.
| n | number to take factorial of |
Here is the call graph for this function:
| std::string format | ( | double | x, | |
| int | prec = 16 | |||
| ) | [inline] |
Simple function to format a double with a given precision. Useful if we don't want to mess with, e.g., cout's settings and produce predictable double-output.
| x | number to write | |
| prec | precision |
| bool general_inc | ( | Vector & | alpha, | |
| int | min, | |||
| int | max, | |||
| size_t | digit = 0 | |||
| ) | [inline] |
Simple recursive function to step through multi-indices.
The template parameter Vector must implement Vector::size() and Vector::operator[]().
| alpha | Multi-index | |
| min | Minimum value of each index | |
| max | Maximum value + 1 of each index | |
| digit | Which digit to increase. User should not use this; used for recursion. |
| double lnbinom | ( | int | n, | |
| int | m | |||
| ) | [inline] |
Compute log of factorial, ln(n!/m!/(n-m)!).
| n | a number | |
| m | a number |
Here is the call graph for this function:
| double lnfact | ( | int | n | ) | [inline] |
Compute ln(n!).
| n | number to take factorial of |
| bool more_general_inc | ( | std::vector< int > & | alpha, | |
| const std::vector< int > & | min, | |||
| const std::vector< int > & | max, | |||
| int | digit = 0 | |||
| ) | [inline] |
Simple recursive function to step through multi-indices. More general version of general_inc(). Here, the max and min values are different for each index in the multi-index.
The template parameter Vector must implement Vector::size() and Vector::operator[]().
| alpha | Multi-index | |
| min | Minimum value of each index | |
| max | Maximum value + 1 of each index | |
| digit | Which digit to increase. User should not use this; used for recursion. |
| std::string move_to | ( | int | N | ) | [inline] |
Move to position (using ANSI escape seq.).
| N | position on line, should be >=0. |
| std::string to_binary | ( | const T & | a, | |
| const size_t & | n = 0 | |||
| ) |
Compute a binary string version of number.
| a | Number to convert | |
| n | Number of bits to use; n = 0 (default) means all bits. |
1.4.7