summaryrefslogtreecommitdiff
path: root/src/tibtype.h
blob: 68549b77a58fbee30472298b19b93f95bd133705 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 *  libtib - Read, write, and evaluate TI BASIC programs
 *  Copyright (C) 2015-2016 Delwink, LLC
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, version 3 only.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef DELWINK_TIB_TIBTYPE_H
#define DELWINK_TIB_TIBTYPE_H

#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <gsl/gsl_matrix_complex_double.h>
#include <gsl/gsl_complex.h>

#include "tibexpr.h"

enum tib_type
  {
    TIB_TYPE_NONE=0,
    TIB_TYPE_COMPLEX,
    TIB_TYPE_STRING,
    TIB_TYPE_LIST,
    TIB_TYPE_MATRIX
  };

union variant
{
  gsl_complex number;
  char *string;
  gsl_vector_complex *list;
  gsl_matrix_complex *matrix;
};

typedef struct
{
  enum tib_type type;
  union variant value;
  size_t refs;
} TIB;

TIB *
tib_empty (void);

TIB *
tib_copy (const TIB *t);

void
tib_incref (TIB *t);

void
tib_decref (TIB *t);

TIB *
tib_new_complex (double real, double imaginary);

TIB *
tib_new_str (const char *value);

TIB *
tib_new_list (const gsl_complex *value, size_t len);

TIB *
tib_new_matrix (const gsl_complex **value, size_t w, size_t h);

enum tib_type
tib_type (const TIB *t);

gsl_complex
tib_complex_value (const TIB *t);

const char *
tib_str_value (const TIB *t);

const gsl_vector_complex *
tib_list_value (const TIB *t);

const gsl_matrix_complex *
tib_matrix_value (const TIB *t);

int
tib_toexpr (struct tib_expr *dest, const TIB *src);

TIB *
tib_add (const TIB *t1, const TIB *t2);

TIB *
tib_sub (const TIB *t1, const TIB *t2);

TIB *
tib_mul (const TIB *t1, const TIB *t2);

TIB *
tib_div (const TIB *t1, const TIB *t2);

TIB *
tib_pow (const TIB *t, const TIB *power);

TIB *
tib_root (const TIB *t, gsl_complex root);

TIB *
tib_factorial (const TIB *t);

TIB *
tib_log (const TIB *t);

TIB *
tib_toradians (const TIB *t);

#endif