Definition in file qofnumeric.h.
Go to the source code of this file.
Data Structures | |
struct | _QofNumeric |
Standard Arguments to most functions | |
Most of the QofNumeric arithmetic functions take two arguments in addition to their numeric args: 'denom', which is the denominator to use in the output QofNumeric object, and 'how'. which describes how the arithmetic result is to be converted to that denominator. This combination of output denominator and rounding policy allows the results of financial and other rational computations to be properly rounded to the appropriate units. Valid values for denom are: QOF_DENOM_AUTO -- compute denominator exactly integer n -- Force the denominator of the result to be this integer QOF_DENOM_RECIPROCAL -- Use 1/n as the denominator (???huh???) Valid values for 'how' are bitwise combinations of zero or one "rounding instructions" with zero or one "denominator types". Valid rounding instructions are: QOF_HOW_RND_FLOOR QOF_HOW_RND_CEIL QOF_HOW_RND_TRUNC QOF_HOW_RND_PROMOTE QOF_HOW_RND_ROUND_HALF_DOWN QOF_HOW_RND_ROUND_HALF_UP QOF_HOW_RND_ROUND QOF_HOW_RND_NEVER The denominator type specifies how to compute a denominator if QOF_DENOM_AUTO is specified as the 'denom'. Valid denominator types are: QOF_HOW_DENOM_EXACT QOF_HOW_DENOM_REDUCE QOF_HOW_DENOM_LCD QOF_HOW_DENOM_FIXED QOF_HOW_DENOM_SIGFIGS(N) To use traditional rational-number operational semantics (all results are exact and are reduced to relatively-prime fractions) pass the argument QOF_DENOM_AUTO as 'denom' and QOF_HOW_DENOM_REDUCE| QOF_HOW_RND_NEVER as 'how'.
To enforce strict financial semantics (such that all operands must have the same denominator as each other and as the result), use QOF_DENOM_AUTO as 'denom' and QOF_HOW_DENOM_FIXED | QOF_HOW_RND_NEVER as 'how'. | |
#define | QOF_NUMERIC_RND_MASK 0x0000000f |
bitmasks for HOW flags. | |
#define | QOF_NUMERIC_DENOM_MASK 0x000000f0 |
#define | QOF_NUMERIC_SIGFIGS_MASK 0x0000ff00 |
#define | QOF_HOW_DENOM_SIGFIGS(n) ( ((( n ) & 0xff) << 8) | QOF_HOW_DENOM_SIGFIG) |
#define | QOF_HOW_GET_SIGFIGS(a) ( (( a ) & 0xff00 ) >> 8) |
#define | QOF_DENOM_AUTO 0 |
#define | QOF_DENOM_RECIPROCAL(a) (- ( a )) |
enum | { QOF_HOW_RND_FLOOR = 0x01, QOF_HOW_RND_CEIL = 0x02, QOF_HOW_RND_TRUNC = 0x03, QOF_HOW_RND_PROMOTE = 0x04, QOF_HOW_RND_ROUND_HALF_DOWN = 0x05, QOF_HOW_RND_ROUND_HALF_UP = 0x06, QOF_HOW_RND_ROUND = 0x07, QOF_HOW_RND_NEVER = 0x08 } |
Rounding/Truncation modes for operations. More... | |
enum | { QOF_HOW_DENOM_EXACT = 0x10, QOF_HOW_DENOM_REDUCE = 0x20, QOF_HOW_DENOM_LCD = 0x30, QOF_HOW_DENOM_FIXED = 0x40, QOF_HOW_DENOM_SIGFIG = 0x50 } |
enum | QofNumericErrorCode { QOF_ERROR_OK = 0, QOF_ERROR_ARG = -1, QOF_ERROR_OVERFLOW = -2, QOF_ERROR_DENOM_DIFF = -3, QOF_ERROR_REMAINDER = -4 } |
Defines | |
Deprecated, backwards-compatible definitions | |
#define | QOF_RND_FLOOR QOF_HOW_RND_FLOOR |
#define | QOF_RND_CEIL QOF_HOW_RND_CEIL |
#define | QOF_RND_TRUNC QOF_HOW_RND_TRUNC |
#define | QOF_RND_PROMOTE QOF_HOW_RND_PROMOTE |
#define | QOF_RND_ROUND_HALF_DOWN QOF_HOW_RND_ROUND_HALF_DOWN |
#define | QOF_RND_ROUND_HALF_UP QOF_HOW_RND_ROUND_HALF_UP |
#define | QOF_RND_ROUND QOF_HOW_RND_ROUND |
#define | QOF_RND_NEVER QOF_HOW_RND_NEVER |
#define | QOF_DENOM_EXACT QOF_HOW_DENOM_EXACT |
#define | QOF_DENOM_REDUCE QOF_HOW_DENOM_REDUCE |
#define | QOF_DENOM_LCD QOF_HOW_DENOM_LCD |
#define | QOF_DENOM_FIXED QOF_HOW_DENOM_FIXED |
#define | QOF_DENOM_SIGFIG QOF_HOW_DENOM_SIGFIG |
#define | QOF_DENOM_SIGFIGS(X) QOF_HOW_DENOM_SIGFIGS(X) |
#define | QOF_NUMERIC_GET_SIGFIGS(X) QOF_HOW_GET_SIGFIGS(X) |
Typedefs | |
typedef struct _QofNumeric | QofNumeric |
A rational-number type. | |
Functions | |
Constructors | |
static QofNumeric | qof_numeric_create (gint64 num, gint64 denom) |
static QofNumeric | qof_numeric_zero (void) |
QofNumeric | qof_numeric_from_double (gdouble in, gint64 denom, gint how) |
gboolean | qof_numeric_from_string (const gchar *str, QofNumeric *n) |
QofNumeric | qof_numeric_error (QofNumericErrorCode error_code) |
Value Accessors | |
static gint64 | qof_numeric_num (QofNumeric a) |
static gint64 | qof_numeric_denom (QofNumeric a) |
gdouble | qof_numeric_to_double (QofNumeric in) |
gchar * | qof_numeric_to_string (QofNumeric n) |
gchar * | qof_numeric_dbg_to_string (QofNumeric n) |
Comparisons and Predicates | |
QofNumericErrorCode | qof_numeric_check (QofNumeric a) |
gint | qof_numeric_compare (QofNumeric a, QofNumeric b) |
gboolean | qof_numeric_zero_p (QofNumeric a) |
gboolean | qof_numeric_negative_p (QofNumeric a) |
gboolean | qof_numeric_positive_p (QofNumeric a) |
gboolean | qof_numeric_eq (QofNumeric a, QofNumeric b) |
gboolean | qof_numeric_equal (QofNumeric a, QofNumeric b) |
gint | qof_numeric_same (QofNumeric a, QofNumeric b, gint64 denom, gint how) |
Arithmetic Operations | |
QofNumeric | qof_numeric_add (QofNumeric a, QofNumeric b, gint64 denom, gint how) |
QofNumeric | qof_numeric_sub (QofNumeric a, QofNumeric b, gint64 denom, gint how) |
QofNumeric | qof_numeric_mul (QofNumeric a, QofNumeric b, gint64 denom, gint how) |
QofNumeric | qof_numeric_div (QofNumeric x, QofNumeric y, gint64 denom, gint how) |
QofNumeric | qof_numeric_neg (QofNumeric a) |
QofNumeric | qof_numeric_abs (QofNumeric a) |
static QofNumeric | qof_numeric_add_fixed (QofNumeric a, QofNumeric b) |
static QofNumeric | qof_numeric_sub_fixed (QofNumeric a, QofNumeric b) |
Arithmetic Functions with Exact Error Returns | |
QofNumeric | qof_numeric_add_with_error (QofNumeric a, QofNumeric b, gint64 denom, gint how, QofNumeric *error) |
QofNumeric | qof_numeric_sub_with_error (QofNumeric a, QofNumeric b, gint64 denom, gint how, QofNumeric *error) |
QofNumeric | qof_numeric_mul_with_error (QofNumeric a, QofNumeric b, gint64 denom, gint how, QofNumeric *error) |
QofNumeric | qof_numeric_div_with_error (QofNumeric a, QofNumeric b, gint64 denom, gint how, QofNumeric *error) |
Change Denominator | |
QofNumeric | qof_numeric_convert (QofNumeric in, gint64 denom, gint how) |
QofNumeric | qof_numeric_convert_with_error (QofNumeric in, gint64 denom, gint how, QofNumeric *error) |
QofNumeric | qof_numeric_reduce (QofNumeric in) |