Repository navigation
Expand file tree
/
Copy pathmain.c
More file actions
73 lines (58 loc) · 1.65 KB
/
Copy pathmain.c
File metadata and controls
73 lines (58 loc) · 1.65 KB
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
#include <glib-object.h>
#include "tdouble.h"
static void
notify_cb (GObject *gobject, GParamSpec *pspec, gpointer user_data) {
const char *name;
double v;
name = g_param_spec_get_name (pspec);
if (T_IS_DOUBLE (gobject) && strcmp (name, "value") == 0) {
g_object_get (T_DOUBLE (gobject), "value", &v, NULL);
g_print ("Property \"%s\" is set to %lf.\n", name, v);
}
}
static double
get_value (TDouble *d) {
double v;
g_object_get (d, "value", &v, NULL);
return v;
}
static void
t_print (char *op, TDouble *d1, TDouble *d2, TDouble *d3) {
g_print ("%lf %s %lf = %lf\n", get_value(d1), op, get_value(d2), get_value(d3));
}
int
main (int argc, char **argv) {
TDouble *d1, *d2, *d3;
d1 = t_double_new_with_value (10.0);
d2 = t_double_new_with_value (20.0);
g_signal_connect (G_OBJECT (d1), "notify::value", G_CALLBACK (notify_cb), NULL);
if ((d3 = t_double_add (d1, d2)) != NULL) {
t_print ("+", d1, d2, d3);
g_object_unref (d3);
}
if ((d3 = t_double_sub (d1, d2)) != NULL) {
t_print ("-", d1, d2, d3);
g_object_unref (d3);
}
if ((d3 = t_double_mul (d1, d2)) != NULL) {
t_print ("*", d1, d2, d3);
g_object_unref (d3);
}
if ((d3 = t_double_div (d1, d2)) != NULL) {
t_print ("/", d1, d2, d3);
g_object_unref (d3);
}
g_object_set (d2, "value", 0.0, NULL);
if ((d3 = t_double_div (d1, d2)) != NULL) {
t_print ("/", d1, d2, d3);
g_object_unref (d3);
}
if ((d3 = t_double_uminus (d1)) != NULL) {
g_print ("-(%lf) = %lf\n", get_value(d1), get_value(d3));
g_object_unref (d3);
}
g_object_set (d1, "value", 100.0, NULL);
g_object_unref (d1);
g_object_unref (d2);
return 0;
}