51#include <glib-object.h>
126#define GNC_NUMERIC_RND_MASK 0x0000000f
127#define GNC_NUMERIC_DENOM_MASK 0x000000f0
128#define GNC_NUMERIC_SIGFIGS_MASK 0x0000ff00
217#define GNC_HOW_DENOM_SIGFIGS( n ) ( ((( n ) & 0xff) << 8) | GNC_HOW_DENOM_SIGFIG)
218#define GNC_HOW_GET_SIGFIGS( a ) ( (( a ) & 0xff00 ) >> 8)
245#define GNC_DENOM_AUTO 0
255gnc_numeric gnc_numeric_create(gint64 num, gint64 denom)
265gnc_numeric gnc_numeric_zero(
void)
267 return gnc_numeric_create(0, 1);
315gint64 gnc_numeric_num(gnc_numeric a)
321gint64 gnc_numeric_denom(gnc_numeric a)
383 gint64 denom, gint how);
391 gint64 denom, gint how);
395 gint64 denom, gint how);
403 gint64 denom, gint how);
413 gint64 denom, gint how);
429gnc_numeric gnc_numeric_add_fixed(gnc_numeric a, gnc_numeric b)
440gnc_numeric gnc_numeric_sub_fixed(gnc_numeric a, gnc_numeric b)
475 guint8 * max_decimal_places);
488GType gnc_numeric_get_type(
void );
489#define GNC_TYPE_NUMERIC (gnc_numeric_get_type ())
GNCNumericErrorCode
Error codes.
const char * gnc_numeric_errorCode_to_string(GNCNumericErrorCode error_code)
Returns a string representation of the given GNCNumericErrorCode.
gboolean gnc_numeric_to_decimal(gnc_numeric *a, guint8 *max_decimal_places)
Attempt to convert the denominator to an exact power of ten without rounding.
gdouble gnc_numeric_to_double(gnc_numeric n)
Convert numeric to floating-point value.
gboolean gnc_numeric_eq(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b are exactly the same (have the same numerator and ...
gnc_numeric gnc_numeric_sub(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a-b.
gint gnc_numeric_same(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Equivalence predicate: Convert both a and b to denom using the specified DENOM and method HOW,...
gchar * gnc_numeric_to_string(gnc_numeric n)
Convert to string.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
gnc_numeric double_to_gnc_numeric(double in, gint64 denom, gint how)
Convert a floating-point number to a gnc_numeric.
gnc_numeric gnc_numeric_div(gnc_numeric x, gnc_numeric y, gint64 denom, gint how)
Division.
gnc_numeric gnc_numeric_error(GNCNumericErrorCode error_code)
Create a gnc_numeric object that signals the error condition noted by error_code, rather than a numbe...
gnc_numeric gnc_numeric_from_string(const gchar *str)
Read a gnc_numeric from str, skipping any leading whitespace.
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.
gnc_numeric gnc_numeric_abs(gnc_numeric a)
Returns a newly created gnc_numeric that is the absolute value of the given gnc_numeric value.
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Multiply a times b, returning the product.
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
gint gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b
gnc_numeric gnc_numeric_convert(gnc_numeric n, gint64 denom, gint how)
Change the denominator of a gnc_numeric value to the specified denominator under standard arguments '...
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value.
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.
gnc_numeric gnc_numeric_invert(gnc_numeric num)
Invert a gnc_numeric.
gnc_numeric gnc_numeric_reduce(gnc_numeric n)
Return input after reducing it by Greater Common Factor (GCF) elimination.
gchar * gnc_num_dbg_to_string(gnc_numeric n)
Convert to string.
gboolean gnc_numeric_positive_p(gnc_numeric a)
Returns 1 if a > 0, otherwise returns 0.
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
@ GNC_ERROR_REMAINDER
GNC_HOW_RND_NEVER was specified, but the result could not be converted to the desired denominator wit...
@ GNC_ERROR_OVERFLOW
Intermediate result overflow.
@ GNC_ERROR_DENOM_DIFF
GNC_HOW_DENOM_FIXED was specified, but argument denominators differed.
@ GNC_ERROR_ARG
Argument is not a valid number.
@ GNC_HOW_RND_ROUND_HALF_UP
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
@ GNC_HOW_RND_ROUND_HALF_DOWN
Round to the nearest integer, rounding toward zero when there are two equidistant nearest integers.
@ GNC_HOW_RND_FLOOR
Round toward -infinity.
@ GNC_HOW_RND_PROMOTE
Promote fractions (round away from zero)
@ GNC_HOW_RND_NEVER
Never round at all, and signal an error if there is a fractional result in a computation.
@ GNC_HOW_RND_CEIL
Round toward +infinity.
@ GNC_HOW_RND_TRUNC
Truncate fractions (round toward zero)
@ GNC_HOW_RND_ROUND
Use unbiased ("banker's") rounding.
@ GNC_HOW_DENOM_REDUCE
Reduce the result value by common factor elimination, using the smallest possible value for the denom...
@ GNC_HOW_DENOM_FIXED
All arguments are required to have the same denominator, that denominator is to be used in the output...
@ GNC_HOW_DENOM_LCD
Find the least common multiple of the arguments' denominators and use that as the denominator of the ...
@ GNC_HOW_DENOM_SIGFIG
Round to the number of significant figures given in the rounding instructions by the GNC_HOW_DENOM_SI...
@ GNC_HOW_DENOM_EXACT
Use any denominator which gives an exactly correct ratio of numerator to denominator.