Skip to content

Commit

Permalink
max and min functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lunfardo314 committed Aug 9, 2024
1 parent 745acac commit 2e2fc7c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 0 additions & 8 deletions embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,6 @@ func evalUint64Bytes(par *CallParams) []byte {
return ret
}

func evalEqualUint(par *CallParams) []byte {
a0, a1 := mustArithmeticArgs(par, "equalUint")
if a0 == a1 {
return []byte{0xff}
}
return nil
}

// lexicographical comparison of two slices of equal length
func evalLessThan(par *CallParams) []byte {
a0 := par.Arg(0)
Expand Down
15 changes: 15 additions & 0 deletions extend.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var extendWithUtilityFunctions = []*ExtendedFunctionData{
{"evalArgumentBytecode", "eval(parseArgumentBytecode($0,$1,$2))"},
{"lessThanUint", "lessThan(uint64Bytes($0), uint64Bytes($1))"},
{"equalUint", "equal(uint64Bytes($0), uint64Bytes($1))"},
{"max", "if(lessThan($0,$1),$1,$0)"},
{"min", "if(lessThan($0,$1),$0,$1)"},
}

func (lib *Library) extendBase() {
Expand All @@ -29,4 +31,17 @@ func (lib *Library) extendBase() {
lib.MustTrue("not(lessThanUint(u16/100,u64/100))")
lib.MustTrue("lessThanUint(0,u64/1)")
lib.MustError("lessThanUint(nil, 5)", "wrong size of parameter")

lib.MustEqual("max(1,100)", "100")
lib.MustEqual("max(100,1)", "100")

lib.MustEqual("min(1,100)", "1")
lib.MustEqual("min(100,1)", "1")

lib.MustEqual("max(u32/1,u32/100)", "u32/100")
lib.MustEqual("max(u32/100,u32/1)", "u32/100")

lib.MustEqual("min(u32/1,u32/100)", "u32/1")
lib.MustEqual("min(u32/100,u32/1)", "u32/1")

}

0 comments on commit 2e2fc7c

Please sign in to comment.