Fix error in kg conversion
[gcalctool.git] / src / mp-equation.h
blob60e6690d3be012c9fc66a14a244c46351b0d7534
1 /* Copyright (c) 2004-2008 Sami Pietila
2 * Copyright (c) 2008-2009 Robert Ancell
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
20 #ifndef MP_EQUATION_H
21 #define MP_EQUATION_H
23 #include "mp.h"
25 typedef enum
27 PARSER_ERR_NONE = 0,
28 PARSER_ERR_INVALID,
29 PARSER_ERR_OVERFLOW,
30 PARSER_ERR_UNKNOWN_VARIABLE,
31 PARSER_ERR_UNKNOWN_FUNCTION,
32 PARSER_ERR_UNKNOWN_CONVERSION,
33 PARSER_ERR_MP
34 } MPErrorCode;
36 /* Options for parser */
37 typedef struct {
38 /* Default number base */
39 int base;
41 /* The wordlength for binary operations in bits (e.g. 8, 16, 32) */
42 int wordlen;
44 /* Units for angles (e.g. radians, degrees) */
45 MPAngleUnit angle_units;
47 // FIXME:
48 // int enable_builtins;
50 /* Data to pass to callbacks */
51 void *callback_data;
53 /* Function to check if a variable is defined */
54 int (*variable_is_defined)(const char *name, void *data);
56 /* Function to get variable values */
57 int (*get_variable)(const char *name, MPNumber *z, void *data);
59 /* Function to set variable values */
60 void (*set_variable)(const char *name, const MPNumber *x, void *data);
62 /* Function to check if a function is defined */
63 int (*function_is_defined)(const char *name, void *data);
65 /* Function to solve functions */
66 int (*get_function)(const char *name, const MPNumber *x, MPNumber *z, void *data);
68 /* Function to convert units */
69 int (*convert)(const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z, void *data);
70 } MPEquationOptions;
72 MPErrorCode mp_equation_parse(const char *expression, MPEquationOptions *options, MPNumber *result, char **error_token);
73 const char *mp_error_code_to_string(MPErrorCode error_code);
75 int sub_atoi(const char *data);
76 int super_atoi(const char *data);
77 #endif