-
Notifications
You must be signed in to change notification settings - Fork 0
/
number_floatspan.go
283 lines (253 loc) · 7.7 KB
/
number_floatspan.go
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package gomeos
/*
#include "meos.h"
#include <stdio.h>
#include <stdlib.h>
#include "cast.h"
*/
import "C"
import (
"fmt"
"unsafe"
)
type FloatSpan struct {
_inner *C.Span
}
func NewFloatSpan(g_fs_in string) *FloatSpan {
c_fs_in := C.CString(g_fs_in)
defer C.free(unsafe.Pointer(c_fs_in))
c_fs := C.floatspan_in(c_fs_in)
g_fs := &FloatSpan{_inner: c_fs}
return g_fs
}
func (g_fs *FloatSpan) Inner() *C.Span {
return g_fs._inner
}
func (g_fs *FloatSpan) Init(c_span *C.Span) {
g_fs._inner = c_span
}
func (g_fs *FloatSpan) IsNumSpan() bool { return true }
func (g_fs FloatSpan) FloatSpanOut(max_decimal int) string {
c_fs_out := C.floatspan_out(g_fs._inner, C.int(max_decimal))
defer C.free(unsafe.Pointer(c_fs_out))
g_fs_out := C.GoString(c_fs_out)
return g_fs_out
}
func (g_fs FloatSpan) ToSpanSet() FloatSpanSet {
return FloatSpanSet{_inner: C.span_to_spanset(g_fs._inner)}
}
func (g_fs FloatSpan) ToIntSpan() IntSpan {
return IntSpan{_inner: C.floatspan_to_intspan(g_fs._inner)}
}
func (g_fs FloatSpan) Lower() float64 {
return float64(C.floatspan_lower(g_fs._inner))
}
func (g_fs FloatSpan) Upper() float64 {
return float64(C.floatspan_upper(g_fs._inner))
}
func (g_fs FloatSpan) Width() float32 {
return float32(C.floatspan_width(g_fs._inner))
}
func (g_fs FloatSpan) ShiftScale(d float64, w float64) FloatSpan {
modified := C.floatspan_shift_scale(g_fs._inner, C.double(d), C.double(w), C._Bool(d != 0), C._Bool(w != 0))
return FloatSpan{_inner: modified}
}
func (g_fs FloatSpan) Shift(delta float64) FloatSpan {
return g_fs.ShiftScale(delta, 0.0)
}
func (g_fs FloatSpan) Scale(width float64) FloatSpan {
return g_fs.ShiftScale(0.0, width)
}
func (g_fs *FloatSpan) IsAdjacent(other interface{}) (bool, error) {
switch o := other.(type) {
case float64:
return bool(C.adjacent_span_float(g_fs._inner, C.double(o))), nil
case *FloatSpan:
return bool(C.adjacent_span_span(g_fs._inner, o._inner)), nil
case *FloatSpanSet:
return bool(C.adjacent_spanset_span(o._inner, g_fs._inner)), nil
default:
return false, fmt.Errorf("operation not supported with type %T", other)
}
}
func (g_fs *FloatSpan) Contains(other interface{}) (bool, error) {
switch o := other.(type) {
case float64:
return bool(C.contains_span_float(g_fs._inner, C.double(o))), nil
case *FloatSpan:
return bool(C.contains_span_span(g_fs._inner, o._inner)), nil
case *FloatSpanSet:
return bool(C.contains_span_spanset(g_fs._inner, o._inner)), nil
default:
return false, fmt.Errorf("operation not supported with type %T", other)
}
}
func (g_fs *FloatSpan) IsSame(other interface{}) (bool, error) {
switch o := other.(type) {
case float64:
return bool(C.span_eq(g_fs._inner, C.float_to_span(C.double(o)))), nil
case *FloatSpan:
return bool(C.span_eq(g_fs._inner, o._inner)), nil
case *FloatSpanSet:
return bool(C.span_eq(g_fs._inner, o.ToSpan()._inner)), nil
default:
return false, fmt.Errorf("operation not supported with type %T", other)
}
}
func (g_fs *FloatSpan) IsLeft(other interface{}) (bool, error) {
switch o := other.(type) {
case float64:
return bool(C.left_span_float(g_fs._inner, C.double(o))), nil
case *FloatSpan:
return bool(C.left_span_span(g_fs._inner, o._inner)), nil
case *FloatSpanSet:
return bool(C.left_span_spanset(g_fs._inner, o._inner)), nil
default:
return false, fmt.Errorf("operation not supported with type %T", other)
}
}
func (g_fs *FloatSpan) IsOverOrLeft(other interface{}) (bool, error) {
switch o := other.(type) {
case float64:
return bool(C.overleft_span_float(g_fs._inner, C.double(o))), nil
case *FloatSpan:
return bool(C.overleft_span_span(g_fs._inner, o._inner)), nil
case *FloatSpanSet:
return bool(C.overleft_span_spanset(g_fs._inner, o._inner)), nil
default:
return false, fmt.Errorf("operation not supported with type %T", other)
}
}
func (g_fs *FloatSpan) IsRight(other interface{}) (bool, error) {
switch o := other.(type) {
case float64:
return bool(C.right_span_float(g_fs._inner, C.double(o))), nil
case *FloatSpan:
return bool(C.right_span_span(g_fs._inner, o._inner)), nil
case *FloatSpanSet:
return bool(C.right_span_spanset(g_fs._inner, o._inner)), nil
default:
return false, fmt.Errorf("operation not supported with type %T", other)
}
}
func (g_fs *FloatSpan) IsOverOrRight(other interface{}) (bool, error) {
switch o := other.(type) {
case float64:
return bool(C.overright_span_float(g_fs._inner, C.double(o))), nil
case *FloatSpan:
return bool(C.overright_span_span(g_fs._inner, o._inner)), nil
case *FloatSpanSet:
return bool(C.overright_span_spanset(g_fs._inner, o._inner)), nil
default:
return false, fmt.Errorf("operation not supported with type %T", other)
}
}
func (g_fs *FloatSpan) Distance(other interface{}) (float64, error) {
switch o := other.(type) {
case int:
return float64(C.distance_span_float(g_fs._inner, C.double(o))), nil
case float64:
return float64(C.distance_span_float(g_fs._inner, C.double(o))), nil
case float32:
return float64(C.distance_span_float(g_fs._inner, C.double(o))), nil
case *FloatSpan:
return float64(C.distance_floatspan_floatspan(g_fs._inner, o._inner)), nil
case *FloatSpanSet:
return float64(C.distance_floatspanset_floatspan(o._inner, g_fs._inner)), nil
default:
return 0.0, fmt.Errorf("operation not supported with type %T", other)
}
}
func (g_fs *FloatSpan) Intersection(other interface{}) (*FloatSpan, error) {
switch o := other.(type) {
case float64:
res := C.intersection_span_float(g_fs._inner, C.double(o))
if res == nil {
return nil, nil
} else {
return &FloatSpan{_inner: res}, nil
}
case *FloatSpan:
res := C.intersection_span_span(g_fs._inner, o._inner)
if res == nil {
return nil, nil
} else {
return &FloatSpan{_inner: res}, nil
}
case *FloatSpanSet:
res := C.intersection_spanset_span(o._inner, g_fs._inner)
if res == nil {
return nil, nil
} else {
// In Pymeos, it is FloatSpanSet, but in Go, it's FloatSpan because I need to declare the type of output
fss := FloatSpanSet{_inner: res}
fs := fss.ToSpan()
return &fs, nil
}
default:
return nil, fmt.Errorf("operation not supported with type %T", other)
}
}
func (g_fs *FloatSpan) Mul(other interface{}) (*FloatSpan, error) {
return g_fs.Intersection(other)
}
func (g_fs *FloatSpan) Minus(other interface{}) (*FloatSpanSet, error) {
switch o := other.(type) {
case float64:
res := C.minus_span_float(g_fs._inner, C.double(o))
if res == nil {
return nil, nil
} else {
return &FloatSpanSet{_inner: res}, nil
}
case *FloatSpan:
res := C.minus_span_span(g_fs._inner, o._inner)
if res == nil {
return nil, nil
} else {
return &FloatSpanSet{_inner: res}, nil
}
case *FloatSpanSet:
res := C.minus_spanset_span(o._inner, g_fs._inner)
if res == nil {
return nil, nil
} else {
return &FloatSpanSet{_inner: res}, nil
}
default:
return nil, fmt.Errorf("operation not supported with type %T", other)
}
}
func (g_fs *FloatSpan) Sub(other interface{}) (*FloatSpanSet, error) {
return g_fs.Minus(other)
}
func (g_fs *FloatSpan) Union(other interface{}) (*FloatSpanSet, error) {
switch o := other.(type) {
case float64:
res := C.gunion_span_float(g_fs._inner, C.double(o))
if res == nil {
return nil, nil
} else {
return &FloatSpanSet{_inner: res}, nil
}
case *FloatSpan:
res := C.gunion_span_span(g_fs._inner, o._inner)
if res == nil {
return nil, nil
} else {
return &FloatSpanSet{_inner: res}, nil
}
case *FloatSpanSet:
res := C.gunion_spanset_span(o._inner, g_fs._inner)
if res == nil {
return nil, nil
} else {
return &FloatSpanSet{_inner: res}, nil
}
default:
return nil, fmt.Errorf("operation not supported with type %T", other)
}
}
func (g_fs *FloatSpan) Add(other interface{}) (*FloatSpanSet, error) {
return g_fs.Union(other)
}