GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-numeric.h
Go to the documentation of this file.
1 /********************************************************************
2  * gnc-numeric.h - A rational number library *
3  * This program is free software; you can redistribute it and/or *
4  * modify it under the terms of the GNU General Public License as *
5  * published by the Free Software Foundation; either version 2 of *
6  * the License, or (at your option) any later version. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License*
14  * along with this program; if not, contact: *
15  * *
16  * Free Software Foundation Voice: +1-617-542-5942 *
17  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
18  * Boston, MA 02110-1301, USA [email protected] *
19  * *
20  *******************************************************************/
21 
50 #ifndef GNC_NUMERIC_H
51 #define GNC_NUMERIC_H
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #endif
56 
57 #include <glib-object.h>
58 
60 {
61  gint64 num;
62  gint64 denom;
63 };
64 
68 typedef struct _gnc_numeric gnc_numeric;
69 
127 #define GNC_NUMERIC_RND_MASK 0x0000000f
128 #define GNC_NUMERIC_DENOM_MASK 0x000000f0
129 #define GNC_NUMERIC_SIGFIGS_MASK 0x0000ff00
130 
144 enum
145 {
148 
151 
154 
157 
162 
167 
174 
179 };
180 
182 enum
183 {
190 
197 
202 
208 
213 };
214 
218 #define GNC_HOW_DENOM_SIGFIGS( n ) ( ((( n ) & 0xff) << 8) | GNC_HOW_DENOM_SIGFIG)
219 #define GNC_HOW_GET_SIGFIGS( a ) ( (( a ) & 0xff00 ) >> 8)
220 
222 typedef enum
223 {
230 
235 
236 
246 #define GNC_DENOM_AUTO 0
247 
249 #define GNC_DENOM_RECIPROCAL( a ) (- ( a ))
250 
258 static inline
259 gnc_numeric gnc_numeric_create(gint64 num, gint64 denom)
260 {
261  gnc_numeric out;
262  out.num = num;
263  out.denom = denom;
264  return out;
265 }
266 
268 static inline
269 gnc_numeric gnc_numeric_zero(void)
270 {
271  return gnc_numeric_create(0, 1);
272 }
273 
298 gnc_numeric double_to_gnc_numeric(double n, gint64 denom,
299  gint how);
300 
304 gboolean string_to_gnc_numeric(const gchar* str, gnc_numeric *n);
305 
310 
320 static inline
321 gint64 gnc_numeric_num(gnc_numeric a)
322 {
323  return a.num;
324 }
326 static inline
327 gint64 gnc_numeric_denom(gnc_numeric a)
328 {
329  return a.denom;
330 }
331 
334 
338 
352 
355 
357 gboolean gnc_numeric_zero_p(gnc_numeric a);
358 
361 
364 
368 gboolean gnc_numeric_eq(gnc_numeric a, gnc_numeric b);
369 
375 
389  gint64 denom, gint how);
397  gint64 denom, gint how);
398 
401  gint64 denom, gint how);
402 
409  gint64 denom, gint how);
410 
419  gint64 denom, gint how);
424 
429 
434 static inline
435 gnc_numeric gnc_numeric_add_fixed(gnc_numeric a, gnc_numeric b)
436 {
437  return gnc_numeric_add(a, b, GNC_DENOM_AUTO,
439 }
440 
445 static inline
446 gnc_numeric gnc_numeric_sub_fixed(gnc_numeric a, gnc_numeric b)
447 {
448  return gnc_numeric_sub(a, b, GNC_DENOM_AUTO,
450 }
459  gint64 denom, gint how,
460  gnc_numeric * error);
461 
465  gint64 denom, gint how,
466  gnc_numeric * error);
467 
472  gint64 denom, gint how,
473  gnc_numeric * error);
474 
479  gint64 denom, gint how,
480  gnc_numeric * error);
491  gint how);
492 
496 
510  guint8 * max_decimal_places);
516 GType gnc_numeric_get_type( void );
517 #define GNC_TYPE_NUMERIC (gnc_numeric_get_type ())
518 
519 #ifdef __cplusplus
520 }
521 #endif
522 
523 #endif
gnc_numeric gnc_numeric_mul_with_error(gnc_numeric a, gnc_numeric b, gint64 denom, gint how, gnc_numeric *error)
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
gchar * gnc_num_dbg_to_string(gnc_numeric n)
gnc_numeric double_to_gnc_numeric(double n, gint64 denom, gint how)
gnc_numeric gnc_numeric_add_with_error(gnc_numeric a, gnc_numeric b, gint64 denom, gint how, gnc_numeric *error)
gnc_numeric gnc_numeric_neg(gnc_numeric a)
GNCNumericErrorCode
Definition: gnc-numeric.h:222
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
gboolean gnc_numeric_to_decimal(gnc_numeric *a, guint8 *max_decimal_places)
gboolean gnc_numeric_zero_p(gnc_numeric a)
gint gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
gchar * gnc_numeric_to_string(gnc_numeric n)
gnc_numeric gnc_numeric_sub_with_error(gnc_numeric a, gnc_numeric b, gint64 denom, gint how, gnc_numeric *error)
gboolean string_to_gnc_numeric(const gchar *str, gnc_numeric *n)
gboolean gnc_numeric_negative_p(gnc_numeric a)
gnc_numeric gnc_numeric_reduce(gnc_numeric n)
gdouble gnc_numeric_to_double(gnc_numeric n)
gnc_numeric gnc_numeric_convert(gnc_numeric n, gint64 denom, gint how)
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
const char * gnc_numeric_errorCode_to_string(GNCNumericErrorCode error_code)
gnc_numeric gnc_numeric_error(GNCNumericErrorCode error_code)
gnc_numeric gnc_numeric_abs(gnc_numeric a)
gnc_numeric gnc_numeric_div(gnc_numeric x, gnc_numeric y, gint64 denom, gint how)
gboolean gnc_numeric_eq(gnc_numeric a, gnc_numeric b)
gboolean gnc_numeric_positive_p(gnc_numeric a)
gnc_numeric gnc_numeric_sub(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
GNCNumericErrorCode gnc_numeric_check(gnc_numeric a)
gint gnc_numeric_same(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
#define GNC_DENOM_AUTO
Definition: gnc-numeric.h:246
gnc_numeric gnc_numeric_div_with_error(gnc_numeric a, gnc_numeric b, gint64 denom, gint how, gnc_numeric *error)