@@ -1099,6 +1099,16 @@ func liftNumeric(f func(float64) float64) func(*interpreter, value) (value, erro
10991099 }
11001100}
11011101
1102+ func liftNumericToBoolean (f func (float64 ) bool ) func (* interpreter , value ) (value , error ) {
1103+ return func (i * interpreter , x value ) (value , error ) {
1104+ n , err := i .getNumber (x )
1105+ if err != nil {
1106+ return nil , err
1107+ }
1108+ return makeValueBoolean (f (n .value )), nil
1109+ }
1110+ }
1111+
11021112var builtinSqrt = liftNumeric (math .Sqrt )
11031113var builtinCeil = liftNumeric (math .Ceil )
11041114var builtinFloor = liftNumeric (math .Floor )
@@ -1125,6 +1135,22 @@ var builtinExponent = liftNumeric(func(f float64) float64 {
11251135 return float64 (exponent )
11261136})
11271137var builtinRound = liftNumeric (math .Round )
1138+ var builtinIsEven = liftNumericToBoolean (func (f float64 ) bool {
1139+ i , _ := math .Modf (f ) // Get the integral part of the float
1140+ return math .Mod (i , 2 ) == 0
1141+ })
1142+ var builtinIsOdd = liftNumericToBoolean (func (f float64 ) bool {
1143+ i , _ := math .Modf (f ) // Get the integral part of the float
1144+ return math .Mod (i , 2 ) != 0
1145+ })
1146+ var builtinIsInteger = liftNumericToBoolean (func (f float64 ) bool {
1147+ _ , frac := math .Modf (f ) // Get the fraction part of the float
1148+ return frac == 0
1149+ })
1150+ var builtinIsDecimal = liftNumericToBoolean (func (f float64 ) bool {
1151+ _ , frac := math .Modf (f ) // Get the fraction part of the float
1152+ return frac != 0
1153+ })
11281154
11291155func liftBitwise (f func (int64 , int64 ) int64 , positiveRightArg bool ) func (* interpreter , value , value ) (value , error ) {
11301156 return func (i * interpreter , xv , yv value ) (value , error ) {
@@ -2467,6 +2493,10 @@ var funcBuiltins = buildBuiltinMap([]builtin{
24672493 & unaryBuiltin {name : "mantissa" , function : builtinMantissa , params : ast.Identifiers {"x" }},
24682494 & unaryBuiltin {name : "exponent" , function : builtinExponent , params : ast.Identifiers {"x" }},
24692495 & unaryBuiltin {name : "round" , function : builtinRound , params : ast.Identifiers {"x" }},
2496+ & unaryBuiltin {name : "isEven" , function : builtinIsEven , params : ast.Identifiers {"x" }},
2497+ & unaryBuiltin {name : "isOdd" , function : builtinIsOdd , params : ast.Identifiers {"x" }},
2498+ & unaryBuiltin {name : "isInteger" , function : builtinIsInteger , params : ast.Identifiers {"x" }},
2499+ & unaryBuiltin {name : "isDecimal" , function : builtinIsDecimal , params : ast.Identifiers {"x" }},
24702500 & binaryBuiltin {name : "pow" , function : builtinPow , params : ast.Identifiers {"x" , "n" }},
24712501 & binaryBuiltin {name : "modulo" , function : builtinModulo , params : ast.Identifiers {"x" , "y" }},
24722502 & unaryBuiltin {name : "md5" , function : builtinMd5 , params : ast.Identifiers {"s" }},
0 commit comments