/* evaluator.c generated by valac 0.56.19, the Vala compiler
 * generated from evaluator.vala, do not modify */

/* SPDX-License-Identifier: GPL-3.0-or-later*/

#include <glib-object.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "graphs.h"
#include <gobject/gvaluecollector.h>

#define GRAPHS_MATH_PARSER_EVALUATOR_DEGREES_TO_RADIANS 0.017453292519943295
#define GRAPHS_MATH_PARSER_EVALUATOR_RADIANS_TO_DEGREES 57.29577951308232
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define GRAPHS_MATH_PARSER_TYPE_EVALUATOR (graphs_math_parser_evaluator_get_type ())
#define GRAPHS_MATH_PARSER_EVALUATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRAPHS_MATH_PARSER_TYPE_EVALUATOR, GraphsMathParserEvaluator))
#define GRAPHS_MATH_PARSER_EVALUATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GRAPHS_MATH_PARSER_TYPE_EVALUATOR, GraphsMathParserEvaluatorClass))
#define GRAPHS_MATH_PARSER_IS_EVALUATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRAPHS_MATH_PARSER_TYPE_EVALUATOR))
#define GRAPHS_MATH_PARSER_IS_EVALUATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRAPHS_MATH_PARSER_TYPE_EVALUATOR))
#define GRAPHS_MATH_PARSER_EVALUATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GRAPHS_MATH_PARSER_TYPE_EVALUATOR, GraphsMathParserEvaluatorClass))

typedef struct _GraphsMathParserEvaluator GraphsMathParserEvaluator;
typedef struct _GraphsMathParserEvaluatorClass GraphsMathParserEvaluatorClass;
typedef struct _GraphsMathParserEvaluatorPrivate GraphsMathParserEvaluatorPrivate;

#define GRAPHS_MATH_PARSER_TYPE_LEXER (graphs_math_parser_lexer_get_type ())
#define GRAPHS_MATH_PARSER_LEXER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRAPHS_MATH_PARSER_TYPE_LEXER, GraphsMathParserLexer))
#define GRAPHS_MATH_PARSER_LEXER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GRAPHS_MATH_PARSER_TYPE_LEXER, GraphsMathParserLexerClass))
#define GRAPHS_MATH_PARSER_IS_LEXER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRAPHS_MATH_PARSER_TYPE_LEXER))
#define GRAPHS_MATH_PARSER_IS_LEXER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRAPHS_MATH_PARSER_TYPE_LEXER))
#define GRAPHS_MATH_PARSER_LEXER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GRAPHS_MATH_PARSER_TYPE_LEXER, GraphsMathParserLexerClass))

typedef struct _GraphsMathParserLexer GraphsMathParserLexer;
typedef struct _GraphsMathParserLexerClass GraphsMathParserLexerClass;
#define _graphs_math_parser_lexer_unref0(var) ((var == NULL) ? NULL : (var = (graphs_math_parser_lexer_unref (var), NULL)))
typedef enum  {
	GRAPHS_MATH_PARSER_TOKEN_TYPE_NUMBER,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_IDENT,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_PLUS,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_MINUS,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_STAR,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_SLASH,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_CARET,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_FACT,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_SUPERSCRIPT,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_LPAREN,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_RPAREN,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_END
} GraphsMathParserTokenType;

#define GRAPHS_MATH_PARSER_TYPE_TOKEN_TYPE (graphs_math_parser_token_type_get_type ())
typedef struct _GraphsMathParserLexerPrivate GraphsMathParserLexerPrivate;
typedef enum  {
	GRAPHS_MATH_PARSER_IDENT_PI,
	GRAPHS_MATH_PARSER_IDENT_E,
	GRAPHS_MATH_PARSER_IDENT_INF,
	GRAPHS_MATH_PARSER_IDENT_SIN,
	GRAPHS_MATH_PARSER_IDENT_COS,
	GRAPHS_MATH_PARSER_IDENT_TAN,
	GRAPHS_MATH_PARSER_IDENT_COT,
	GRAPHS_MATH_PARSER_IDENT_SEC,
	GRAPHS_MATH_PARSER_IDENT_CSC,
	GRAPHS_MATH_PARSER_IDENT_SIND,
	GRAPHS_MATH_PARSER_IDENT_COSD,
	GRAPHS_MATH_PARSER_IDENT_TAND,
	GRAPHS_MATH_PARSER_IDENT_COTD,
	GRAPHS_MATH_PARSER_IDENT_SECD,
	GRAPHS_MATH_PARSER_IDENT_CSCD,
	GRAPHS_MATH_PARSER_IDENT_ASIN,
	GRAPHS_MATH_PARSER_IDENT_ACOS,
	GRAPHS_MATH_PARSER_IDENT_ATAN,
	GRAPHS_MATH_PARSER_IDENT_ACOT,
	GRAPHS_MATH_PARSER_IDENT_ASEC,
	GRAPHS_MATH_PARSER_IDENT_ACSC,
	GRAPHS_MATH_PARSER_IDENT_ASIND,
	GRAPHS_MATH_PARSER_IDENT_ACOSD,
	GRAPHS_MATH_PARSER_IDENT_ATAND,
	GRAPHS_MATH_PARSER_IDENT_ACOTD,
	GRAPHS_MATH_PARSER_IDENT_ASECD,
	GRAPHS_MATH_PARSER_IDENT_ACSCD,
	GRAPHS_MATH_PARSER_IDENT_LOG,
	GRAPHS_MATH_PARSER_IDENT_LOG2,
	GRAPHS_MATH_PARSER_IDENT_LOG10,
	GRAPHS_MATH_PARSER_IDENT_SQRT,
	GRAPHS_MATH_PARSER_IDENT_EXP,
	GRAPHS_MATH_PARSER_IDENT_ABS,
	GRAPHS_MATH_PARSER_IDENT_CUSTOM
} GraphsMathParserIdent;

#define GRAPHS_MATH_PARSER_TYPE_IDENT (graphs_math_parser_ident_get_type ())
typedef struct _GraphsMathParserParamSpecEvaluator GraphsMathParserParamSpecEvaluator;

struct _GraphsMathParserEvaluator {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GraphsMathParserEvaluatorPrivate * priv;
};

struct _GraphsMathParserEvaluatorClass {
	GTypeClass parent_class;
	void (*finalize) (GraphsMathParserEvaluator *self);
};

struct _GraphsMathParserEvaluatorPrivate {
	GraphsMathParserLexer* lexer;
};

struct _GraphsMathParserLexer {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GraphsMathParserLexerPrivate * priv;
	GraphsMathParserTokenType current_type;
	GraphsMathParserIdent current_ident;
	gdouble current_val;
};

struct _GraphsMathParserLexerClass {
	GTypeClass parent_class;
	void (*finalize) (GraphsMathParserLexer *self);
};

struct _GraphsMathParserParamSpecEvaluator {
	GParamSpec parent_instance;
};

static gint GraphsMathParserEvaluator_private_offset;
static gpointer graphs_math_parser_evaluator_parent_class = NULL;
static GOnce graphs_math_parser_evaluator__instance;
static GOnce graphs_math_parser_evaluator__instance = G_ONCE_INIT;

VALA_EXTERN gpointer graphs_math_parser_evaluator_ref (gpointer instance);
VALA_EXTERN void graphs_math_parser_evaluator_unref (gpointer instance);
VALA_EXTERN GParamSpec* graphs_math_parser_param_spec_evaluator (const gchar* name,
                                                     const gchar* nick,
                                                     const gchar* blurb,
                                                     GType object_type,
                                                     GParamFlags flags);
VALA_EXTERN void graphs_math_parser_value_set_evaluator (GValue* value,
                                             gpointer v_object);
VALA_EXTERN void graphs_math_parser_value_take_evaluator (GValue* value,
                                              gpointer v_object);
VALA_EXTERN gpointer graphs_math_parser_value_get_evaluator (const GValue* value);
VALA_EXTERN GType graphs_math_parser_evaluator_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gpointer graphs_math_parser_lexer_ref (gpointer instance);
VALA_EXTERN void graphs_math_parser_lexer_unref (gpointer instance);
VALA_EXTERN GParamSpec* graphs_math_parser_param_spec_lexer (const gchar* name,
                                                 const gchar* nick,
                                                 const gchar* blurb,
                                                 GType object_type,
                                                 GParamFlags flags);
VALA_EXTERN void graphs_math_parser_value_set_lexer (GValue* value,
                                         gpointer v_object);
VALA_EXTERN void graphs_math_parser_value_take_lexer (GValue* value,
                                          gpointer v_object);
VALA_EXTERN gpointer graphs_math_parser_value_get_lexer (const GValue* value);
VALA_EXTERN GType graphs_math_parser_lexer_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GraphsMathParserLexer* graphs_math_parser_lexer_new (gboolean allow_custom_ident);
VALA_EXTERN GraphsMathParserLexer* graphs_math_parser_lexer_construct (GType object_type,
                                                           gboolean allow_custom_ident);
VALA_EXTERN GraphsMathParserEvaluator* graphs_math_parser_evaluator_instance (void);
static GraphsMathParserEvaluator* __lambda4_ (void);
VALA_EXTERN GraphsMathParserEvaluator* graphs_math_parser_evaluator_new (void);
VALA_EXTERN GraphsMathParserEvaluator* graphs_math_parser_evaluator_construct (GType object_type);
static gpointer ___lambda4__gthread_func (gpointer self);
VALA_EXTERN gdouble graphs_math_parser_evaluator_parse (GraphsMathParserEvaluator* self,
                                            const gchar* src,
                                            gunichar decimal_separator,
                                            GError** error);
VALA_EXTERN void graphs_math_parser_lexer_start_lexing (GraphsMathParserLexer* self,
                                            const gchar* src,
                                            gunichar decimal_separator,
                                            GError** error);
static gdouble graphs_math_parser_evaluator_expr (GraphsMathParserEvaluator* self,
                                           GError** error);
VALA_EXTERN void graphs_math_parser_lexer_expect_end (GraphsMathParserLexer* self,
                                          GError** error);
static gdouble graphs_math_parser_evaluator_term (GraphsMathParserEvaluator* self,
                                           GError** error);
VALA_EXTERN GType graphs_math_parser_token_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType graphs_math_parser_ident_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void graphs_math_parser_lexer_next (GraphsMathParserLexer* self,
                                    GError** error);
static gdouble graphs_math_parser_evaluator_power (GraphsMathParserEvaluator* self,
                                            GError** error);
static gdouble graphs_math_parser_evaluator_unary (GraphsMathParserEvaluator* self,
                                            GError** error);
static gdouble graphs_math_parser_evaluator_postfix (GraphsMathParserEvaluator* self,
                                              GError** error);
static gdouble graphs_math_parser_evaluator_primary (GraphsMathParserEvaluator* self,
                                              GError** error);
VALA_EXTERN glong graphs_math_parser_factorial (gint n);
VALA_EXTERN gdouble graphs_math_parser_ipow (gdouble bas,
                                 gint exp);
VALA_EXTERN void graphs_math_parser_lexer_expect (GraphsMathParserLexer* self,
                                      GraphsMathParserTokenType t,
                                      GError** error);
static gdouble graphs_math_parser_evaluator_call_function (GraphsMathParserIdent id,
                                                    gdouble x);
static void graphs_math_parser_evaluator_finalize (GraphsMathParserEvaluator * obj);
static GType graphs_math_parser_evaluator_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
graphs_math_parser_evaluator_get_instance_private (GraphsMathParserEvaluator* self)
{
	return G_STRUCT_MEMBER_P (self, GraphsMathParserEvaluator_private_offset);
}

static GraphsMathParserEvaluator*
__lambda4_ (void)
{
	GraphsMathParserEvaluator* _tmp0_;
	GraphsMathParserEvaluator* result;
	_tmp0_ = graphs_math_parser_evaluator_new ();
	result = _tmp0_;
	return result;
}

static gpointer
___lambda4__gthread_func (gpointer self)
{
	gpointer result;
	result = __lambda4_ ();
	return result;
}

GraphsMathParserEvaluator*
graphs_math_parser_evaluator_instance (void)
{
	gconstpointer _tmp0_;
	GraphsMathParserEvaluator* result;
	_tmp0_ = g_once (&graphs_math_parser_evaluator__instance, ___lambda4__gthread_func, NULL);
	result = (GraphsMathParserEvaluator*) _tmp0_;
	return result;
}

gdouble
graphs_math_parser_evaluator_parse (GraphsMathParserEvaluator* self,
                                    const gchar* src,
                                    gunichar decimal_separator,
                                    GError** error)
{
	GraphsMathParserLexer* _tmp0_;
	gdouble _result_ = 0.0;
	GraphsMathParserLexer* _tmp5_;
	GError* _inner_error0_ = NULL;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	g_return_val_if_fail (src != NULL, -1.0);
	_tmp0_ = self->priv->lexer;
	graphs_math_parser_lexer_start_lexing (_tmp0_, src, decimal_separator, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			gdouble _tmp1_ = -1.0;
			g_propagate_error (error, _inner_error0_);
			return _tmp1_;
		} else {
			gdouble _tmp2_ = -1.0;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp2_;
		}
	}
	_result_ = graphs_math_parser_evaluator_expr (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			gdouble _tmp3_ = -1.0;
			g_propagate_error (error, _inner_error0_);
			return _tmp3_;
		} else {
			gdouble _tmp4_ = -1.0;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp4_;
		}
	}
	_tmp5_ = self->priv->lexer;
	graphs_math_parser_lexer_expect_end (_tmp5_, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			gdouble _tmp6_ = -1.0;
			g_propagate_error (error, _inner_error0_);
			return _tmp6_;
		} else {
			gdouble _tmp7_ = -1.0;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp7_;
		}
	}
	result = _result_;
	return result;
}

static gdouble
graphs_math_parser_evaluator_expr (GraphsMathParserEvaluator* self,
                                   GError** error)
{
	gdouble v = 0.0;
	GraphsMathParserTokenType t = 0;
	GError* _inner_error0_ = NULL;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	v = graphs_math_parser_evaluator_term (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			gdouble _tmp0_ = -1.0;
			g_propagate_error (error, _inner_error0_);
			return _tmp0_;
		} else {
			gdouble _tmp1_ = -1.0;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp1_;
		}
	}
	while (TRUE) {
		GraphsMathParserLexer* _tmp2_;
		gboolean _tmp3_ = FALSE;
		GraphsMathParserLexer* _tmp4_;
		gdouble r = 0.0;
		gdouble _tmp9_ = 0.0;
		_tmp2_ = self->priv->lexer;
		t = _tmp2_->current_type;
		if (t == GRAPHS_MATH_PARSER_TOKEN_TYPE_PLUS) {
			_tmp3_ = TRUE;
		} else {
			_tmp3_ = t == GRAPHS_MATH_PARSER_TOKEN_TYPE_MINUS;
		}
		if (!_tmp3_) {
			break;
		}
		_tmp4_ = self->priv->lexer;
		graphs_math_parser_lexer_next (_tmp4_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				gdouble _tmp5_ = -1.0;
				g_propagate_error (error, _inner_error0_);
				return _tmp5_;
			} else {
				gdouble _tmp6_ = -1.0;
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return _tmp6_;
			}
		}
		r = graphs_math_parser_evaluator_term (self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				gdouble _tmp7_ = -1.0;
				g_propagate_error (error, _inner_error0_);
				return _tmp7_;
			} else {
				gdouble _tmp8_ = -1.0;
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return _tmp8_;
			}
		}
		if (t == GRAPHS_MATH_PARSER_TOKEN_TYPE_PLUS) {
			_tmp9_ = v + r;
		} else {
			_tmp9_ = v - r;
		}
		v = _tmp9_;
	}
	result = v;
	return result;
}

static gdouble
graphs_math_parser_evaluator_term (GraphsMathParserEvaluator* self,
                                   GError** error)
{
	gdouble v = 0.0;
	GError* _inner_error0_ = NULL;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	v = graphs_math_parser_evaluator_power (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			gdouble _tmp0_ = -1.0;
			g_propagate_error (error, _inner_error0_);
			return _tmp0_;
		} else {
			gdouble _tmp1_ = -1.0;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp1_;
		}
	}
	while (TRUE) {
		GraphsMathParserTokenType t = 0;
		GraphsMathParserLexer* _tmp2_;
		gboolean _tmp3_ = FALSE;
		gboolean _tmp14_ = FALSE;
		gboolean _tmp15_ = FALSE;
		_tmp2_ = self->priv->lexer;
		t = _tmp2_->current_type;
		if (t == GRAPHS_MATH_PARSER_TOKEN_TYPE_STAR) {
			_tmp3_ = TRUE;
		} else {
			_tmp3_ = t == GRAPHS_MATH_PARSER_TOKEN_TYPE_SLASH;
		}
		if (_tmp3_) {
			GraphsMathParserLexer* _tmp4_;
			gdouble r = 0.0;
			gboolean _tmp9_ = FALSE;
			gdouble _tmp13_ = 0.0;
			_tmp4_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp4_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp5_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp5_;
				} else {
					gdouble _tmp6_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp6_;
				}
			}
			r = graphs_math_parser_evaluator_power (self, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp7_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp7_;
				} else {
					gdouble _tmp8_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp8_;
				}
			}
			if (t == GRAPHS_MATH_PARSER_TOKEN_TYPE_SLASH) {
				_tmp9_ = r == ((gdouble) 0);
			} else {
				_tmp9_ = FALSE;
			}
			if (_tmp9_) {
				GError* _tmp10_;
				_tmp10_ = g_error_new_literal (GRAPHS_MATH_ERROR, GRAPHS_MATH_ERROR_DIV_ZERO, "division by zero");
				_inner_error0_ = _tmp10_;
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp11_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp11_;
				} else {
					gdouble _tmp12_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp12_;
				}
			}
			if (t == GRAPHS_MATH_PARSER_TOKEN_TYPE_STAR) {
				_tmp13_ = v * r;
			} else {
				_tmp13_ = v / r;
			}
			v = _tmp13_;
			continue;
		}
		if (t == GRAPHS_MATH_PARSER_TOKEN_TYPE_NUMBER) {
			_tmp15_ = TRUE;
		} else {
			_tmp15_ = t == GRAPHS_MATH_PARSER_TOKEN_TYPE_IDENT;
		}
		if (_tmp15_) {
			_tmp14_ = TRUE;
		} else {
			_tmp14_ = t == GRAPHS_MATH_PARSER_TOKEN_TYPE_LPAREN;
		}
		if (_tmp14_) {
			gdouble _tmp16_ = 0.0;
			_tmp16_ = graphs_math_parser_evaluator_power (self, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp17_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp17_;
				} else {
					gdouble _tmp18_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp18_;
				}
			}
			v *= _tmp16_;
			continue;
		}
		break;
	}
	result = v;
	return result;
}

static gdouble
graphs_math_parser_evaluator_power (GraphsMathParserEvaluator* self,
                                    GError** error)
{
	gdouble v = 0.0;
	GraphsMathParserLexer* _tmp2_;
	GError* _inner_error0_ = NULL;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	v = graphs_math_parser_evaluator_unary (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			gdouble _tmp0_ = -1.0;
			g_propagate_error (error, _inner_error0_);
			return _tmp0_;
		} else {
			gdouble _tmp1_ = -1.0;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp1_;
		}
	}
	_tmp2_ = self->priv->lexer;
	if (_tmp2_->current_type == GRAPHS_MATH_PARSER_TOKEN_TYPE_CARET) {
		GraphsMathParserLexer* _tmp3_;
		gdouble _tmp6_ = 0.0;
		_tmp3_ = self->priv->lexer;
		graphs_math_parser_lexer_next (_tmp3_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				gdouble _tmp4_ = -1.0;
				g_propagate_error (error, _inner_error0_);
				return _tmp4_;
			} else {
				gdouble _tmp5_ = -1.0;
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return _tmp5_;
			}
		}
		_tmp6_ = graphs_math_parser_evaluator_power (self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				gdouble _tmp7_ = -1.0;
				g_propagate_error (error, _inner_error0_);
				return _tmp7_;
			} else {
				gdouble _tmp8_ = -1.0;
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return _tmp8_;
			}
		}
		v = pow (v, _tmp6_);
	}
	result = v;
	return result;
}

static gdouble
graphs_math_parser_evaluator_unary (GraphsMathParserEvaluator* self,
                                    GError** error)
{
	GraphsMathParserLexer* _tmp0_;
	gdouble _tmp11_ = 0.0;
	GError* _inner_error0_ = NULL;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = self->priv->lexer;
	if (_tmp0_->current_type == GRAPHS_MATH_PARSER_TOKEN_TYPE_MINUS) {
		GraphsMathParserLexer* _tmp1_;
		gdouble _tmp4_ = 0.0;
		_tmp1_ = self->priv->lexer;
		graphs_math_parser_lexer_next (_tmp1_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				gdouble _tmp2_ = -1.0;
				g_propagate_error (error, _inner_error0_);
				return _tmp2_;
			} else {
				gdouble _tmp3_ = -1.0;
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return _tmp3_;
			}
		}
		_tmp4_ = graphs_math_parser_evaluator_postfix (self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				gdouble _tmp5_ = -1.0;
				g_propagate_error (error, _inner_error0_);
				return _tmp5_;
			} else {
				gdouble _tmp6_ = -1.0;
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return _tmp6_;
			}
		}
		result = -_tmp4_;
		return result;
	} else {
		GraphsMathParserLexer* _tmp7_;
		_tmp7_ = self->priv->lexer;
		if (_tmp7_->current_type == GRAPHS_MATH_PARSER_TOKEN_TYPE_PLUS) {
			GraphsMathParserLexer* _tmp8_;
			_tmp8_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp8_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp9_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp9_;
				} else {
					gdouble _tmp10_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp10_;
				}
			}
		}
	}
	_tmp11_ = graphs_math_parser_evaluator_postfix (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			gdouble _tmp12_ = -1.0;
			g_propagate_error (error, _inner_error0_);
			return _tmp12_;
		} else {
			gdouble _tmp13_ = -1.0;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp13_;
		}
	}
	result = _tmp11_;
	return result;
}

static gdouble
graphs_math_parser_evaluator_postfix (GraphsMathParserEvaluator* self,
                                      GError** error)
{
	gdouble v = 0.0;
	GError* _inner_error0_ = NULL;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	v = graphs_math_parser_evaluator_primary (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			gdouble _tmp0_ = -1.0;
			g_propagate_error (error, _inner_error0_);
			return _tmp0_;
		} else {
			gdouble _tmp1_ = -1.0;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp1_;
		}
	}
	while (TRUE) {
		GraphsMathParserLexer* _tmp2_;
		GraphsMathParserLexer* _tmp10_;
		_tmp2_ = self->priv->lexer;
		if (_tmp2_->current_type == GRAPHS_MATH_PARSER_TOKEN_TYPE_FACT) {
			gboolean _tmp3_ = FALSE;
			GraphsMathParserLexer* _tmp7_;
			if (v < ((gdouble) 0)) {
				_tmp3_ = TRUE;
			} else {
				_tmp3_ = v != floor (v);
			}
			if (_tmp3_) {
				GError* _tmp4_;
				_tmp4_ = g_error_new_literal (GRAPHS_MATH_ERROR, GRAPHS_MATH_ERROR_DOMAIN, "invalid factorial");
				_inner_error0_ = _tmp4_;
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp5_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp5_;
				} else {
					gdouble _tmp6_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp6_;
				}
			}
			v = (gdouble) graphs_math_parser_factorial ((gint) v);
			_tmp7_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp7_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp8_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp8_;
				} else {
					gdouble _tmp9_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp9_;
				}
			}
			continue;
		}
		_tmp10_ = self->priv->lexer;
		if (_tmp10_->current_type == GRAPHS_MATH_PARSER_TOKEN_TYPE_SUPERSCRIPT) {
			gint exp = 0;
			GraphsMathParserLexer* _tmp11_;
			GraphsMathParserLexer* _tmp12_;
			_tmp11_ = self->priv->lexer;
			exp = (gint) _tmp11_->current_val;
			_tmp12_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp12_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp13_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp13_;
				} else {
					gdouble _tmp14_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp14_;
				}
			}
			v = graphs_math_parser_ipow (v, exp);
			continue;
		}
		break;
	}
	result = v;
	return result;
}

static gdouble
graphs_math_parser_evaluator_primary (GraphsMathParserEvaluator* self,
                                      GError** error)
{
	GraphsMathParserLexer* _tmp0_;
	GError* _inner_error0_ = NULL;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = self->priv->lexer;
	switch (_tmp0_->current_type) {
		case GRAPHS_MATH_PARSER_TOKEN_TYPE_NUMBER:
		{
			gdouble v = 0.0;
			GraphsMathParserLexer* _tmp1_;
			GraphsMathParserLexer* _tmp2_;
			_tmp1_ = self->priv->lexer;
			v = _tmp1_->current_val;
			_tmp2_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp2_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp3_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp3_;
				} else {
					gdouble _tmp4_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp4_;
				}
			}
			result = v;
			return result;
		}
		case GRAPHS_MATH_PARSER_TOKEN_TYPE_IDENT:
		{
			GraphsMathParserIdent id = 0;
			GraphsMathParserLexer* _tmp5_;
			GraphsMathParserLexer* _tmp6_;
			GraphsMathParserLexer* _tmp9_;
			gdouble arg = 0.0;
			GraphsMathParserLexer* _tmp14_;
			_tmp5_ = self->priv->lexer;
			id = _tmp5_->current_ident;
			_tmp6_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp6_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp7_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp7_;
				} else {
					gdouble _tmp8_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp8_;
				}
			}
			switch (id) {
				case GRAPHS_MATH_PARSER_IDENT_PI:
				{
					result = G_PI;
					return result;
				}
				case GRAPHS_MATH_PARSER_IDENT_E:
				{
					result = G_E;
					return result;
				}
				case GRAPHS_MATH_PARSER_IDENT_INF:
				{
					result = ((double) INFINITY);
					return result;
				}
				default:
				{
					break;
				}
			}
			_tmp9_ = self->priv->lexer;
			graphs_math_parser_lexer_expect (_tmp9_, GRAPHS_MATH_PARSER_TOKEN_TYPE_LPAREN, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp10_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp10_;
				} else {
					gdouble _tmp11_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp11_;
				}
			}
			arg = graphs_math_parser_evaluator_expr (self, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp12_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp12_;
				} else {
					gdouble _tmp13_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp13_;
				}
			}
			_tmp14_ = self->priv->lexer;
			graphs_math_parser_lexer_expect (_tmp14_, GRAPHS_MATH_PARSER_TOKEN_TYPE_RPAREN, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp15_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp15_;
				} else {
					gdouble _tmp16_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp16_;
				}
			}
			result = graphs_math_parser_evaluator_call_function (id, arg);
			return result;
		}
		case GRAPHS_MATH_PARSER_TOKEN_TYPE_LPAREN:
		{
			GraphsMathParserLexer* _tmp17_;
			gdouble v = 0.0;
			GraphsMathParserLexer* _tmp22_;
			_tmp17_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp17_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp18_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp18_;
				} else {
					gdouble _tmp19_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp19_;
				}
			}
			v = graphs_math_parser_evaluator_expr (self, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp20_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp20_;
				} else {
					gdouble _tmp21_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp21_;
				}
			}
			_tmp22_ = self->priv->lexer;
			graphs_math_parser_lexer_expect (_tmp22_, GRAPHS_MATH_PARSER_TOKEN_TYPE_RPAREN, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					gdouble _tmp23_ = -1.0;
					g_propagate_error (error, _inner_error0_);
					return _tmp23_;
				} else {
					gdouble _tmp24_ = -1.0;
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp24_;
				}
			}
			result = v;
			return result;
		}
		default:
		{
			GError* _tmp25_;
			_tmp25_ = g_error_new_literal (GRAPHS_MATH_ERROR, GRAPHS_MATH_ERROR_SYNTAX, "unexpected token");
			_inner_error0_ = _tmp25_;
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				gdouble _tmp26_ = -1.0;
				g_propagate_error (error, _inner_error0_);
				return _tmp26_;
			} else {
				gdouble _tmp27_ = -1.0;
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return _tmp27_;
			}
		}
	}
}

static gdouble
graphs_math_parser_evaluator_call_function (GraphsMathParserIdent id,
                                            gdouble x)
{
	gdouble result;
	switch (id) {
		case GRAPHS_MATH_PARSER_IDENT_SIN:
		{
			result = sin (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_COS:
		{
			result = cos (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_TAN:
		{
			result = tan (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_COT:
		{
			result = 1. / tan (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_SEC:
		{
			result = 1. / cos (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_CSC:
		{
			result = 1. / sin (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_SIND:
		{
			result = sin (x * GRAPHS_MATH_PARSER_EVALUATOR_DEGREES_TO_RADIANS);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_COSD:
		{
			result = cos (x * GRAPHS_MATH_PARSER_EVALUATOR_DEGREES_TO_RADIANS);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_TAND:
		{
			result = tan (x * GRAPHS_MATH_PARSER_EVALUATOR_DEGREES_TO_RADIANS);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_COTD:
		{
			result = 1. / tan (x * GRAPHS_MATH_PARSER_EVALUATOR_DEGREES_TO_RADIANS);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_SECD:
		{
			result = 1. / cos (x * GRAPHS_MATH_PARSER_EVALUATOR_DEGREES_TO_RADIANS);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_CSCD:
		{
			result = 1. / sin (x * GRAPHS_MATH_PARSER_EVALUATOR_DEGREES_TO_RADIANS);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ASIN:
		{
			result = asin (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACOS:
		{
			result = acos (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ATAN:
		{
			result = atan (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACOT:
		{
			result = asin (1. / sqrt (1 + (x * x)));
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ASEC:
		{
			result = acos (1. / x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACSC:
		{
			result = asin (1. / x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ASIND:
		{
			result = asin (x) * GRAPHS_MATH_PARSER_EVALUATOR_RADIANS_TO_DEGREES;
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACOSD:
		{
			result = acos (x) * GRAPHS_MATH_PARSER_EVALUATOR_RADIANS_TO_DEGREES;
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ATAND:
		{
			result = atan (x) * GRAPHS_MATH_PARSER_EVALUATOR_RADIANS_TO_DEGREES;
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACOTD:
		{
			result = asin (1. / sqrt (1 + (x * x))) * GRAPHS_MATH_PARSER_EVALUATOR_RADIANS_TO_DEGREES;
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ASECD:
		{
			result = acos (1. / x) * GRAPHS_MATH_PARSER_EVALUATOR_RADIANS_TO_DEGREES;
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACSCD:
		{
			result = asin (1. / x) * GRAPHS_MATH_PARSER_EVALUATOR_RADIANS_TO_DEGREES;
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_LOG:
		{
			result = log (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_LOG2:
		{
			result = log2 (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_LOG10:
		{
			result = log10 (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_SQRT:
		{
			result = sqrt (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_EXP:
		{
			result = exp (x);
			return result;
		}
		case GRAPHS_MATH_PARSER_IDENT_ABS:
		{
			result = fabs (x);
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

GraphsMathParserEvaluator*
graphs_math_parser_evaluator_construct (GType object_type)
{
	GraphsMathParserEvaluator* self = NULL;
	self = (GraphsMathParserEvaluator*) g_type_create_instance (object_type);
	return self;
}

GraphsMathParserEvaluator*
graphs_math_parser_evaluator_new (void)
{
	return graphs_math_parser_evaluator_construct (GRAPHS_MATH_PARSER_TYPE_EVALUATOR);
}

static void
graphs_math_parser_value_evaluator_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
graphs_math_parser_value_evaluator_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		graphs_math_parser_evaluator_unref (value->data[0].v_pointer);
	}
}

static void
graphs_math_parser_value_evaluator_copy_value (const GValue* src_value,
                                               GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = graphs_math_parser_evaluator_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
graphs_math_parser_value_evaluator_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
graphs_math_parser_value_evaluator_collect_value (GValue* value,
                                                  guint n_collect_values,
                                                  GTypeCValue* collect_values,
                                                  guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		GraphsMathParserEvaluator * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = graphs_math_parser_evaluator_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
graphs_math_parser_value_evaluator_lcopy_value (const GValue* value,
                                                guint n_collect_values,
                                                GTypeCValue* collect_values,
                                                guint collect_flags)
{
	GraphsMathParserEvaluator ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = graphs_math_parser_evaluator_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
graphs_math_parser_param_spec_evaluator (const gchar* name,
                                         const gchar* nick,
                                         const gchar* blurb,
                                         GType object_type,
                                         GParamFlags flags)
{
	GraphsMathParserParamSpecEvaluator* spec;
	g_return_val_if_fail (g_type_is_a (object_type, GRAPHS_MATH_PARSER_TYPE_EVALUATOR), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
graphs_math_parser_value_get_evaluator (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GRAPHS_MATH_PARSER_TYPE_EVALUATOR), NULL);
	return value->data[0].v_pointer;
}

void
graphs_math_parser_value_set_evaluator (GValue* value,
                                        gpointer v_object)
{
	GraphsMathParserEvaluator * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GRAPHS_MATH_PARSER_TYPE_EVALUATOR));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GRAPHS_MATH_PARSER_TYPE_EVALUATOR));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		graphs_math_parser_evaluator_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		graphs_math_parser_evaluator_unref (old);
	}
}

void
graphs_math_parser_value_take_evaluator (GValue* value,
                                         gpointer v_object)
{
	GraphsMathParserEvaluator * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GRAPHS_MATH_PARSER_TYPE_EVALUATOR));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GRAPHS_MATH_PARSER_TYPE_EVALUATOR));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		graphs_math_parser_evaluator_unref (old);
	}
}

static void
graphs_math_parser_evaluator_class_init (GraphsMathParserEvaluatorClass * klass,
                                         gpointer klass_data)
{
	graphs_math_parser_evaluator_parent_class = g_type_class_peek_parent (klass);
	((GraphsMathParserEvaluatorClass *) klass)->finalize = graphs_math_parser_evaluator_finalize;
	g_type_class_adjust_private_offset (klass, &GraphsMathParserEvaluator_private_offset);
}

static void
graphs_math_parser_evaluator_instance_init (GraphsMathParserEvaluator * self,
                                            gpointer klass)
{
	GraphsMathParserLexer* _tmp0_;
	self->priv = graphs_math_parser_evaluator_get_instance_private (self);
	_tmp0_ = graphs_math_parser_lexer_new (FALSE);
	self->priv->lexer = _tmp0_;
	self->ref_count = 1;
}

static void
graphs_math_parser_evaluator_finalize (GraphsMathParserEvaluator * obj)
{
	GraphsMathParserEvaluator * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_MATH_PARSER_TYPE_EVALUATOR, GraphsMathParserEvaluator);
	g_signal_handlers_destroy (self);
	_graphs_math_parser_lexer_unref0 (self->priv->lexer);
}

static GType
graphs_math_parser_evaluator_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { graphs_math_parser_value_evaluator_init, graphs_math_parser_value_evaluator_free_value, graphs_math_parser_value_evaluator_copy_value, graphs_math_parser_value_evaluator_peek_pointer, "p", graphs_math_parser_value_evaluator_collect_value, "p", graphs_math_parser_value_evaluator_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (GraphsMathParserEvaluatorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) graphs_math_parser_evaluator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraphsMathParserEvaluator), 0, (GInstanceInitFunc) graphs_math_parser_evaluator_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType graphs_math_parser_evaluator_type_id;
	graphs_math_parser_evaluator_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GraphsMathParserEvaluator", &g_define_type_info, &g_define_type_fundamental_info, 0);
	GraphsMathParserEvaluator_private_offset = g_type_add_instance_private (graphs_math_parser_evaluator_type_id, sizeof (GraphsMathParserEvaluatorPrivate));
	return graphs_math_parser_evaluator_type_id;
}

GType
graphs_math_parser_evaluator_get_type (void)
{
	static volatile gsize graphs_math_parser_evaluator_type_id__once = 0;
	if (g_once_init_enter (&graphs_math_parser_evaluator_type_id__once)) {
		GType graphs_math_parser_evaluator_type_id;
		graphs_math_parser_evaluator_type_id = graphs_math_parser_evaluator_get_type_once ();
		g_once_init_leave (&graphs_math_parser_evaluator_type_id__once, graphs_math_parser_evaluator_type_id);
	}
	return graphs_math_parser_evaluator_type_id__once;
}

gpointer
graphs_math_parser_evaluator_ref (gpointer instance)
{
	GraphsMathParserEvaluator * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
graphs_math_parser_evaluator_unref (gpointer instance)
{
	GraphsMathParserEvaluator * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GRAPHS_MATH_PARSER_EVALUATOR_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

