@@ -16,6 +16,7 @@ package ast
16
16
17
17
import (
18
18
"github.com/hyperjumptech/grule-rule-engine/logger"
19
+ "math"
19
20
"reflect"
20
21
"strings"
21
22
"time"
@@ -170,3 +171,293 @@ func (gf *BuiltInFunctions) IsTimeAfter(time, after time.Time) bool {
170
171
func (gf * BuiltInFunctions ) TimeFormat (time time.Time , layout string ) string {
171
172
return time .Format (layout )
172
173
}
174
+
175
+ // Max will pick the biggest of value in the arguments
176
+ func (gf * BuiltInFunctions ) Max (vals ... float64 ) float64 {
177
+ val := float64 (0 )
178
+ for i , v := range vals {
179
+ if i == 0 {
180
+ val = v
181
+ } else {
182
+ if v > val {
183
+ val = v
184
+ }
185
+ }
186
+ }
187
+ return val
188
+ }
189
+
190
+ // Min will pick the smallest of value in the arguments
191
+ func (gf * BuiltInFunctions ) Min (vals ... float64 ) float64 {
192
+ val := float64 (0 )
193
+ for i , v := range vals {
194
+ if i == 0 {
195
+ val = v
196
+ } else {
197
+ if v < val {
198
+ val = v
199
+ }
200
+ }
201
+ }
202
+ return val
203
+ }
204
+
205
+ // Abs is a wrapper function for math.Abs function
206
+ func (gf * BuiltInFunctions ) Abs (x float64 ) float64 {
207
+ return math .Abs (x )
208
+ }
209
+
210
+ // Acos is a wrapper function for math.Acos function
211
+ func (gf * BuiltInFunctions ) Acos (x float64 ) float64 {
212
+ return math .Acos (x )
213
+ }
214
+
215
+ // Acosh is a wrapper function for math.Acosh function
216
+ func (gf * BuiltInFunctions ) Acosh (x float64 ) float64 {
217
+ return math .Acosh (x )
218
+ }
219
+
220
+ // Asin is a wrapper function for math.Asin function
221
+ func (gf * BuiltInFunctions ) Asin (x float64 ) float64 {
222
+ return math .Asin (x )
223
+ }
224
+
225
+ // Asinh is a wrapper function for math.Asinh function
226
+ func (gf * BuiltInFunctions ) Asinh (x float64 ) float64 {
227
+ return math .Asinh (x )
228
+ }
229
+
230
+ // Atan is a wrapper function for math.Atan function
231
+ func (gf * BuiltInFunctions ) Atan (x float64 ) float64 {
232
+ return math .Atan (x )
233
+ }
234
+
235
+ // Atan2 is a wrapper function for math.Atan2 function
236
+ func (gf * BuiltInFunctions ) Atan2 (y , x float64 ) float64 {
237
+ return math .Atan2 (y , x )
238
+ }
239
+
240
+ // Atanh is a wrapper function for math.Atanh function
241
+ func (gf * BuiltInFunctions ) Atanh (x float64 ) float64 {
242
+ return math .Atanh (x )
243
+ }
244
+
245
+ // Cbrt is a wrapper function for math.Cbrt function
246
+ func (gf * BuiltInFunctions ) Cbrt (x float64 ) float64 {
247
+ return math .Cbrt (x )
248
+ }
249
+
250
+ // Ceil is a wrapper function for math.Ceil function
251
+ func (gf * BuiltInFunctions ) Ceil (x float64 ) float64 {
252
+ return math .Ceil (x )
253
+ }
254
+
255
+ // Copysign is a wrapper function for math.Copysign function
256
+ func (gf * BuiltInFunctions ) Copysign (x , y float64 ) float64 {
257
+ return math .Copysign (x , y )
258
+ }
259
+
260
+ // Cos is a wrapper function for math.Cos function
261
+ func (gf * BuiltInFunctions ) Cos (x float64 ) float64 {
262
+ return math .Cos (x )
263
+ }
264
+
265
+ // Cosh is a wrapper function for math.Cosh function
266
+ func (gf * BuiltInFunctions ) Cosh (x float64 ) float64 {
267
+ return math .Cosh (x )
268
+ }
269
+
270
+ // Dim is a wrapper function for math.Dim function
271
+ func (gf * BuiltInFunctions ) Dim (x , y float64 ) float64 {
272
+ return math .Dim (x , y )
273
+ }
274
+
275
+ // Erf is a wrapper function for math.Erf function
276
+ func (gf * BuiltInFunctions ) Erf (x float64 ) float64 {
277
+ return math .Erf (x )
278
+ }
279
+
280
+ // Erfc is a wrapper function for math.Erfc function
281
+ func (gf * BuiltInFunctions ) Erfc (x float64 ) float64 {
282
+ return math .Erfc (x )
283
+ }
284
+
285
+ // Erfcinv is a wrapper function for math.Erfcinv function
286
+ func (gf * BuiltInFunctions ) Erfcinv (x float64 ) float64 {
287
+ return math .Erfcinv (x )
288
+ }
289
+
290
+ // Erfinv is a wrapper function for math.Erfinv function
291
+ func (gf * BuiltInFunctions ) Erfinv (x float64 ) float64 {
292
+ return math .Erfinv (x )
293
+ }
294
+
295
+ // Exp is a wrapper function for math.Exp function
296
+ func (gf * BuiltInFunctions ) Exp (x float64 ) float64 {
297
+ return math .Exp (x )
298
+ }
299
+
300
+ // Exp2 is a wrapper function for math.Exp2 function
301
+ func (gf * BuiltInFunctions ) Exp2 (x float64 ) float64 {
302
+ return math .Exp2 (x )
303
+ }
304
+
305
+ // Expm1 is a wrapper function for math.Expm1 function
306
+ func (gf * BuiltInFunctions ) Expm1 (x float64 ) float64 {
307
+ return math .Expm1 (x )
308
+ }
309
+
310
+ // Float64bits is a wrapper function for math.Float64bits function
311
+ func (gf * BuiltInFunctions ) Float64bits (f float64 ) uint64 {
312
+ return math .Float64bits (f )
313
+ }
314
+
315
+ // Float64frombits is a wrapper function for math.Float64frombits function
316
+ func (gf * BuiltInFunctions ) Float64frombits (b uint64 ) float64 {
317
+ return math .Float64frombits (b )
318
+ }
319
+
320
+ // Floor is a wrapper function for math.Floor function
321
+ func (gf * BuiltInFunctions ) Floor (x float64 ) float64 {
322
+ return math .Floor (x )
323
+ }
324
+
325
+ // Gamma is a wrapper function for math.Gamma function
326
+ func (gf * BuiltInFunctions ) Gamma (x float64 ) float64 {
327
+ return math .Gamma (x )
328
+ }
329
+
330
+ // Hypot is a wrapper function for math.Hypot function
331
+ func (gf * BuiltInFunctions ) Hypot (p , q float64 ) float64 {
332
+ return math .Hypot (p , q )
333
+ }
334
+
335
+ // Ilogb is a wrapper function for math.Ilogb function
336
+ func (gf * BuiltInFunctions ) Ilogb (x float64 ) int {
337
+ return math .Ilogb (x )
338
+ }
339
+
340
+ // IsInf is a wrapper function for math.IsInf function
341
+ func (gf * BuiltInFunctions ) IsInf (f float64 , sign int64 ) bool {
342
+ return math .IsInf (f , int (sign ))
343
+ }
344
+
345
+ // IsNaN is a wrapper function for math.IsNaN function
346
+ func (gf * BuiltInFunctions ) IsNaN (f float64 ) (is bool ) {
347
+ return math .IsNaN (f )
348
+ }
349
+
350
+ // J0 is a wrapper function for math.J0 function
351
+ func (gf * BuiltInFunctions ) J0 (x float64 ) float64 {
352
+ return math .J0 (x )
353
+ }
354
+
355
+ // J1 is a wrapper function for math.J1 function
356
+ func (gf * BuiltInFunctions ) J1 (x float64 ) float64 {
357
+ return math .J1 (x )
358
+ }
359
+
360
+ // Jn is a wrapper function for math.Jn function
361
+ func (gf * BuiltInFunctions ) Jn (n int64 , x float64 ) float64 {
362
+ return math .Jn (int (n ), x )
363
+ }
364
+
365
+ // Ldexp is a wrapper function for math.Ldexp function
366
+ func (gf * BuiltInFunctions ) Ldexp (frac float64 , exp int64 ) float64 {
367
+ return math .Ldexp (frac , int (exp ))
368
+ }
369
+
370
+ // MathLog is a wrapper function for math.MathLog function
371
+ func (gf * BuiltInFunctions ) MathLog (x float64 ) float64 {
372
+ return math .Log (x )
373
+ }
374
+
375
+ // Log10 is a wrapper function for math.Log10 function
376
+ func (gf * BuiltInFunctions ) Log10 (x float64 ) float64 {
377
+ return math .Log10 (x )
378
+ }
379
+
380
+ // Log1p is a wrapper function for math.Log1p function
381
+ func (gf * BuiltInFunctions ) Log1p (x float64 ) float64 {
382
+ return math .Log1p (x )
383
+ }
384
+
385
+ // Log2 is a wrapper function for math.Log2 function
386
+ func (gf * BuiltInFunctions ) Log2 (x float64 ) float64 {
387
+ return math .Log2 (x )
388
+ }
389
+
390
+ // Logb is a wrapper function for math.Logb function
391
+ func (gf * BuiltInFunctions ) Logb (x float64 ) float64 {
392
+ return math .Logb (x )
393
+ }
394
+
395
+ // Mod is a wrapper function for math.Mod function
396
+ func (gf * BuiltInFunctions ) Mod (x , y float64 ) float64 {
397
+ return math .Mod (x , y )
398
+ }
399
+
400
+ // NaN is a wrapper function for math.NaN function
401
+ func (gf * BuiltInFunctions ) NaN () float64 {
402
+ return math .NaN ()
403
+ }
404
+
405
+ // Pow is a wrapper function for math.Pow function
406
+ func (gf * BuiltInFunctions ) Pow (x , y float64 ) float64 {
407
+ return math .Pow (x , y )
408
+ }
409
+
410
+ // Pow10 is a wrapper function for math.Pow10 function
411
+ func (gf * BuiltInFunctions ) Pow10 (n int64 ) float64 {
412
+ return math .Pow10 (int (n ))
413
+ }
414
+
415
+ // Remainder is a wrapper function for math.Remainder function
416
+ func (gf * BuiltInFunctions ) Remainder (x , y float64 ) float64 {
417
+ return math .Remainder (x , y )
418
+ }
419
+
420
+ // Round is a wrapper function for math.Round function
421
+ func (gf * BuiltInFunctions ) Round (x float64 ) float64 {
422
+ return math .Round (x )
423
+ }
424
+
425
+ // RoundToEven is a wrapper function for math.RoundToEven function
426
+ func (gf * BuiltInFunctions ) RoundToEven (x float64 ) float64 {
427
+ return math .RoundToEven (x )
428
+ }
429
+
430
+ // Signbit is a wrapper function for math.Signbit function
431
+ func (gf * BuiltInFunctions ) Signbit (x float64 ) bool {
432
+ return math .Signbit (x )
433
+ }
434
+
435
+ // Sin is a wrapper function for math.Sin function
436
+ func (gf * BuiltInFunctions ) Sin (x float64 ) float64 {
437
+ return math .Sin (x )
438
+ }
439
+
440
+ // Sinh is a wrapper function for math.Sinh function
441
+ func (gf * BuiltInFunctions ) Sinh (x float64 ) float64 {
442
+ return math .Sinh (x )
443
+ }
444
+
445
+ // Sqrt is a wrapper function for math.Sqrt function
446
+ func (gf * BuiltInFunctions ) Sqrt (x float64 ) float64 {
447
+ return math .Sqrt (x )
448
+ }
449
+
450
+ // Tan is a wrapper function for math.Tan function
451
+ func (gf * BuiltInFunctions ) Tan (x float64 ) float64 {
452
+ return math .Tan (x )
453
+ }
454
+
455
+ // Tanh is a wrapper function for math.Tanh function
456
+ func (gf * BuiltInFunctions ) Tanh (x float64 ) float64 {
457
+ return math .Tanh (x )
458
+ }
459
+
460
+ // Trunc is a wrapper function for math.Trunc function
461
+ func (gf * BuiltInFunctions ) Trunc (x float64 ) float64 {
462
+ return math .Trunc (x )
463
+ }
0 commit comments