Releasing 6.6.2
[gcalctool.git] / src / mp-equation.h
blobd6c0f24890bd43bad810ae80ad289eb2654c6ce2
1 /*
2 * Copyright (C) 2004-2008 Sami Pietila
3 * Copyright (C) 2008-2011 Robert Ancell.
4 *
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, either version 2 of the License, or (at your option) any later
8 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9 * license.
12 #ifndef MP_EQUATION_H
13 #define MP_EQUATION_H
15 #include "mp.h"
17 typedef enum
19 PARSER_ERR_NONE = 0,
20 PARSER_ERR_INVALID,
21 PARSER_ERR_OVERFLOW,
22 PARSER_ERR_UNKNOWN_VARIABLE,
23 PARSER_ERR_UNKNOWN_FUNCTION,
24 PARSER_ERR_UNKNOWN_CONVERSION,
25 PARSER_ERR_MP
26 } MPErrorCode;
28 /* Options for parser */
29 typedef struct {
30 /* Default number base */
31 int base;
33 /* The wordlength for binary operations in bits (e.g. 8, 16, 32) */
34 int wordlen;
36 /* Units for angles (e.g. radians, degrees) */
37 MPAngleUnit angle_units;
39 // FIXME:
40 // int enable_builtins;
42 /* Data to pass to callbacks */
43 void *callback_data;
45 /* Function to check if a variable is defined */
46 int (*variable_is_defined)(const char *name, void *data);
48 /* Function to get variable values */
49 int (*get_variable)(const char *name, MPNumber *z, void *data);
51 /* Function to set variable values */
52 void (*set_variable)(const char *name, const MPNumber *x, void *data);
54 /* Function to check if a function is defined */
55 int (*function_is_defined)(const char *name, void *data);
57 /* Function to solve functions */
58 int (*get_function)(const char *name, const MPNumber *x, MPNumber *z, void *data);
60 /* Function to convert units */
61 int (*convert)(const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z, void *data);
62 } MPEquationOptions;
64 MPErrorCode mp_equation_parse(const char *expression, MPEquationOptions *options, MPNumber *result, char **error_token);
65 const char *mp_error_code_to_string(MPErrorCode error_code);
67 int sub_atoi(const char *data);
68 int super_atoi(const char *data);
69 #endif